T05 · Unauthorized Access and Privilege Escalation
Error
- Location
- scripts/bridge_server.py:96
- Finding
- Unrestricted Remote Shell Command Execution<![CDATA[ ## Vulnerability Details **File Location**: `scripts/bridge_server.py:96-112` **Vulnerability Type**: Arbitrary command execution through an authenticated network endpoint **Risk Level**: Critical ### Vulnerable Code ```python def handle_execute(self, data): """执行命令""" command = data.get('command', '') timeout = data.get('timeout', 30) capture = data.get('capture_output', True) if not command: self.send_json_response(400, {"error": "Missing 'command' field"}) return logger.info(f"执行命令: {command}") try: result = subprocess.run( command, shell=True, capture_output=capture, text=True, timeout=timeout ) ``` ### Technical Analysis The `/execute` endpoint passes a remotely supplied string directly to `subprocess.run` with `shell=True`. Authentication consists only of possession of a single bearer token. There is no command allowlist, argument validation, user confirmation, sandbox, privilege separation, or operating-system policy limiting what the process can execute. Although remote command execution is part of the declared functionality, unrestricted shell access exceeds the minimum privilege needed for safe task delegation. The bearer token effectively becomes a reusable remote-administration credential. ### Attack Path 1. An attacker obtains the bearer token through network interception, logs, local configuration, pairing-state exposure, or accidental disclosure. 2. The attacker sends an authenticated POST request to `/execute`. 3. The JSON `command` field contains an arbitrary shell command. 4. `subprocess.run(..., shell=True)` invokes the system shell. 5. The command runs with all privileges available to the Bridge server process. 6. The attacker receives standard output and standard error in the HTTP response or through the callback feature. ### Impact Assessment A successful attacker can execute arbitrary programs, read ...[truncated 234 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Remove the generic shell endpoint and expose narrowly scoped, explicitly defined operations. - Use fixed executable paths and argument arrays with `shell=False`. - Validate every argument against an operation-specific allowlist. - Run the service under a dedicated unprivileged account with a minimal filesystem and network policy. - Isolate permitted operations in a container or sandbox with resource limits. - Require explicit user approval for security-sensitive actions. - Use short-lived, operation-scoped credentials instead of one reusable administrator token. - Record tamper-resistant audit events without logging commands that contain secrets. ]]>
