T09 · Insecure Skill Coding Practices
- Location
rpa.py:248- Finding
Command Injection in Application Launching
- Content
View full analysis
Vulnerability Details
File Location:
rpa.py:248-266
Vulnerability Type: OS command injection through unsafe shell invocation
Risk Level: HighVulnerable Code
python def cmd_launch(args): """启动应用""" app_paths = { "notepad": "notepad.exe", "word": "winword.exe", "excel": "excel.exe", "chrome": "chrome.exe", "firefox": "firefox.exe", "edge": "msedge.exe", "explorer": "explorer.exe", "cmd": "cmd.exe", "powershell": "powershell.exe", "paint": "mspaint.exe", "calc": "calc.exe", } app_path = app_paths.get(args.app.lower(), args.app) try: if args.args: subprocess.Popen(f'start "" "{app_path}" {args.args}', shell=True) else: subprocess.Popen(f'start "" "{app_path}"', shell=True)Technical Analysis
Both
args.appandargs.argsare incorporated into a command string passed tosubprocess.Popenwithshell=True. On Windows, this causes the string to be interpreted by the command processor rather than executing a program directly.The
args.argsvalue is not quoted or escaped at all. Shell metacharacters such as&,|, redirection operators, and command-grouping syntax can therefore append or replace commands. The fallback behavior forargs.appalso permits an arbitrary caller-supplied value to enter the quoted command string. Embedded quotation marks can terminate that boundary and introduce additional shell syntax.Attack Path
- An attacker, untrusted prompt, or compromised caller controls the
apporargsparameter ofdesktop_launch_app. - The value is substituted into the
startcommand without shell-safe encoding. - A value containing command separators, such as an argument beginning with
&, changes the command interpreted bycmd.exe. subprocess.Popen(..., shell=True)exe ...[truncated 575 chars]
- An attacker, untrusted prompt, or compromised caller controls the
- Remediation
View remediation
Remediation Suggestions
- Remove
shell=Trueand invoke the executable with a structured argument list. - Resolve supported application aliases to fixed executable paths.
- If custom applications must be supported, require an absolute path and validate it against an explicit allowlist of permitted directories or executables.
- Parse application arguments into a list with a Windows-aware parser rather than concatenating them into a command.
- Reject shell metacharacters when the requested operation does not legitimately require shell syntax.
- Require explicit user approval before launching arbitrary executable paths.
- Run application-launch operations in a restricted, non-administrative security context.
- Remove
