T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/app_launcher.py:28
- Finding
- PowerShell Command Injection in Application Launch Parameters<![CDATA[ ## Vulnerability Details **File Location**: `scripts/app_launcher.py`, lines 28-46 **Vulnerability Type**: PowerShell command injection **Risk Level**: High ### Vulnerable Code ```python # Build the PowerShell command ps_cmd = f"Start-Process -FilePath '{app_path}'" if arguments: ps_cmd += f" -ArgumentList '{arguments}'" if working_dir: ps_cmd += f" -WorkingDirectory '{working_dir}'" if wait: ps_cmd += f" -Wait -Timeout {timeout}" # Execute the PowerShell command result = subprocess.run( ["powershell", "-Command", ps_cmd], capture_output=True, text=True, timeout=timeout + 10 ) ``` ### Technical Analysis The `app_path`, `arguments`, and `working_dir` values are interpolated directly into PowerShell source code enclosed by single quotes. No escaping, validation, or parameter separation is applied. An attacker-controlled value containing a single quote can terminate the intended PowerShell string. PowerShell statement delimiters can then introduce additional commands. Supplying the generated script as an element of a Python argument array does not prevent this vulnerability because `powershell -Command` deliberately parses that element as executable PowerShell source. The `url` command is also affected because `open_url()` passes the URL to the vulnerable `start_app()` function: ```python def open_url(url): return start_app(url, arguments="") ``` ### Attack Path 1. An attacker supplies a crafted application path or URL through an automation request. 2. The Agent invokes `app_launcher.py start <value>` or `app_launcher.py url <value>`. 3. The script inserts the value into `Start-Process -FilePath '<value>'`. 4. A quote in the value closes the intended string, after which injected PowerShell statements are parsed. 5. PowerShell executes the appended commands with the privileges of the Python/Agent process. ### Impact Assessment Successful exploitation provides arbitrary command execution under the current Age ...[truncated 319 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Do not generate PowerShell source code by interpolating untrusted values. - Launch executables directly with `subprocess.Popen()` or `subprocess.run()` using a structured argument list. - Use `webbrowser.open()` or an equivalent native API for URLs after validating the allowed URL schemes. - Pass application arguments as separate list elements rather than as one command string. - Canonicalize and validate application and working-directory paths. - Consider an allowlist of approved executables and URL schemes. - If PowerShell is unavoidable, pass values through separately bound parameters and treat them strictly as data rather than script fragments. ]]>
