Skip to content

fix: update shell prompt after cd command in AI shell mode - #13

Open
Priyanka-cmd23 wants to merge 1 commit into
Dev9269:masterfrom
Priyanka-cmd23:fix/shell-prompt-cd
Open

fix: update shell prompt after cd command in AI shell mode#13
Priyanka-cmd23 wants to merge 1 commit into
Dev9269:masterfrom
Priyanka-cmd23:fix/shell-prompt-cd

Conversation

@Priyanka-cmd23

Copy link
Copy Markdown

Summary

When using AI shell mode in the SSH honeypot, the shell prompt (e.g.,
oot@debian-12:/root$) did not update after running cd commands. This fix intercepts cd commands at the shell handler level, updates session.cwd immediately, and renders the correct path in the next prompt — without sending an unnecessary AI query.

Changes

  • honeypot/ai_shell.py: Added cd command handling in _interact() that:
    • Parses the target directory (absolute, relative, .., ~, -, bare cd)
    • Resolves the path via _resolve_path() (handles .., ., double slashes)
    • Validates against allowed directories via _validate_path()
    • Updates session.cwd and immediately sends the updated prompt
    • Skips the AI query for cd commands (which produced useless responses)
  • honeypot/ai_shell.py: Added two static helper methods:
    • _resolve_path(path) — normalizes paths, resolves .. and .
    • _validate_path(path) — prevents escape to disallowed directories

Example behavior

Before:
oot@debian-12:/root$ cd /tmp → AI responds with something →
oot@debian-12:/root$ (wrong)
After:
oot@debian-12:/root$ cd /tmp →
oot@debian-12:/tmp$ (correct)

Closes #6

When using AI shell mode, the prompt path now correctly reflects
directory changes after cd command. Also handles cd .., cd -, cd ~,
cd (no args), and path validation.

Changes:
- Intercept cd commands before sending to AI engine
- Update session.cwd with proper path resolution (_resolve_path)
- Validate target paths (_validate_path) against allowed directories
- Handle cd -, cd .., cd ~, and bare cd (goes to /root)
- Log cd activity separately for audit trail

Closes Dev9269#6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix: shell prompt not updating after cd

2 participants