-
-
Notifications
You must be signed in to change notification settings - Fork 5
Add remote shell payload for remote REPL. #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…nding commands
WalkthroughNew remote Python REPL implementation comprising server-side and client-side modules. The server processes special commands, executes Python code within a context, captures stdout/stderr, and frames responses with markers. The client provides interactive TCP communication for remote command execution and result retrieval. Changes
Sequence DiagramsequenceDiagram
participant Client as Client
participant Server as Remote Shell
Client->>Server: Connect to host:port
Server->>Client: Send greeting
loop Command Loop
Server->>Client: Send prompt "ps> "
Client->>Client: Read user input
Client->>Server: Send command
alt Is Special Command
Server->>Server: handle_special_commands()<br/>(parse .exit, .vars, etc.)
else Regular Python Code
Server->>Server: handle_command()<br/>(compile with eval/exec)<br/>(capture stdout/stderr)
end
Server->>Client: Send output
Server->>Client: Send END_MARKER
Client->>Client: Display output
end
Client->>Client: User sends exit command
Client->>Server: Close connection
Server->>Server: Send "Bye." and cleanup
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20–25 minutes Areas requiring extra attention:
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
payloads/remote_shell.py(1 hunks)remote_client.py(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
payloads/remote_shell.py (2)
src/utils/rp.py (1)
log(45-52)payloads/updater_for_up_to_2.x.x.py (1)
sc(16-34)
🪛 Ruff (0.14.4)
payloads/remote_shell.py
113-113: Use of possibly insecure function; consider using ast.literal_eval
(S307)
118-118: Use of exec detected
(S102)
121-121: Do not catch blind exception: Exception
(BLE001)
179-179: Comment contains ambiguous – (EN DASH). Did you mean - (HYPHEN-MINUS)?
(RUF003)
193-193: Do not catch blind exception: Exception
(BLE001)
| if mode == "eval": | ||
| result = eval(code_obj, ctx, ctx) | ||
| # Para ver contenido de expresiones tipo "renpy" | ||
| if result is not None: | ||
| print(repr(result)) | ||
| else: | ||
| exec(code_obj, ctx, ctx) | ||
| except SystemExit: |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix exec usage for Python 2 REPL commands.
This payload runs under Python 2.7, so exec is still a statement. The current exec(code_obj, ctx, ctx) builds a tuple and triggers TypeError: exec() arg 1 must be a string or code object, meaning any statement command (x = 1, import os, etc.) fails. Switch back to the Python 2 form so statements execute correctly.
- exec(code_obj, ctx, ctx)
+ exec code_obj in ctx, ctx📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if mode == "eval": | |
| result = eval(code_obj, ctx, ctx) | |
| # Para ver contenido de expresiones tipo "renpy" | |
| if result is not None: | |
| print(repr(result)) | |
| else: | |
| exec(code_obj, ctx, ctx) | |
| except SystemExit: | |
| if mode == "eval": | |
| result = eval(code_obj, ctx, ctx) | |
| # Para ver contenido de expresiones tipo "renpy" | |
| if result is not None: | |
| print(repr(result)) | |
| else: | |
| exec code_obj in ctx, ctx | |
| except SystemExit: |
🧰 Tools
🪛 Ruff (0.14.4)
113-113: Use of possibly insecure function; consider using ast.literal_eval
(S307)
118-118: Use of exec detected
(S102)
🤖 Prompt for AI Agents
In payloads/remote_shell.py around lines 112 to 119, the code uses
exec(code_obj, ctx, ctx) which is the Python 3 function form but this runs under
Python 2.7 where exec is a statement; the current call builds a tuple and raises
TypeError for statement inputs. Replace the function-call form with the Python 2
exec statement invocation so the compiled code object is executed in the
provided ctx namespace (e.g., use the exec statement form that takes the code
object and namespace), ensuring statements like assignments and imports run
correctly under Python 2.
Summary by CodeRabbit