T09 · Insecure Skill Coding Practices
- Location
scripts/infoseek_helper.py:614- Finding
PowerShell Command Injection Through a User-Controlled Deletion Path
- Content
View full analysis
bool: """Windows: move to recycle bin""" import subprocess safe_path = filepath.replace('"', '""') ps_command = f''' Add-Type -AssemblyName Microsoft.VisualBasic [Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile("{safe_path}", "OnlyErrorDialogs", "SendToRecycleBin") ''' result = subprocess.run( ['powershell', '-Command', ps_command], capture_output=True, text=True, timeout=30 ) return result.returncode == 0 ``` ### Technical Analysis The `filepath` command-line argument is controlled by the caller and is interpolated directly into dynamically generated PowerShell source code. Replacing double quotes with two double quotes is not a reliable way to encode an untrusted value for use inside a PowerShell expandable string. In particular, PowerShell evaluates constructs such as `$()` inside double-quoted strings. A specially crafted file path containing a PowerShell subexpression can therefore cause arbitrary PowerShell expressions to be evaluated when the generated script is parsed. Other PowerShell metacharacters may also allow an attacker to alter the intended command structure. Using `subprocess.run()` with an argument list prevents command-line parsing by a conventional shell, but it does not mitigate this issue because the application deliberately invokes `powershell -Command` and supplies attacker-influenced PowerShell source code. ### Attack Path 1. An attacker causes the Skill or its user to process a Windows file path containing PowerShell syntax, such as an expandable `$()` expression. 2. The caller invokes the `delete` subcommand with the crafted value through `--filepath`. 3. The deletion workflow displays the path and requests confirmat ...[truncated 1243 chars]- Remediation
View remediation
