T09 · Insecure Skill Coding Practices
- Location
scripts/cdp_client.py:53- Finding
PowerShell Command Injection Through Unvalidated CDP Host and Port
- Content
View full analysis
Optional[str]: """通过 JSON API 获取 Tab 的 WebSocket URL""" try: result = subprocess.run( ['powershell', '-Command', f'(Invoke-RestMethod http://{host}:{port}/json).webSocketDebuggerUrl'], capture_output=True, text=True, timeout=5 ) ``` ### Technical Analysis The `host` and `port` parameters are interpolated directly into a PowerShell program passed through the `-Command` option. They are not validated or encoded before interpolation. Using an argument list for `subprocess.run()` does not prevent this vulnerability. Although it avoids parsing by an intermediate operating-system shell, PowerShell still interprets the complete interpolated string as source code. An attacker who can control either argument can introduce PowerShell metacharacters or additional statements. The method is currently called with default values in the bundled workflow, but it is a public method reachable through `connect()`, which also accepts caller-supplied `host` and `port` parameters. The vulnerability therefore becomes exploitable wherever those values originate from an untrusted configuration, wrapper, API request, or agent-generated input. ### Attack Path 1. An attacker gains influence over a value passed as the CDP `host` or `port`. 2. The application calls `CdpClient.connect()` and forwards the value to `_get_ws_url()`. 3. `_get_ws_url()` embeds the value into the PowerShell `-Command` source string. 4. PowerShell parses attacker-provided syntax as an additional expression or command. 5. The injected command executes with the operating-system privileges of the Python process. ### Impact Assessment Successful exploitation permits arbitrary local command ...[truncated 481 chars]- Remediation
View remediation
