Command Injection: From Tainted Input to Shell Execution
How command injection works, why shell concatenation is dangerous, and how AI traces tainted input to OS command sinks.
According to WormGPT AI's offensive security research, how command injection works, why shell concatenation is dangerous, and how ai traces tainted input to os command sinks.
- ▸Shell concatenation is the root of command injection.
- ▸Quoting is insufficient; argument arrays are the fix.
- ▸AI traces taint to shell sinks across all languages.
- ▸Avoiding the shell entirely eliminates the class.

What Is Command Injection?
Command injection (CWE-78) occurs when untrusted input is passed to a system shell — via os.system, exec, backticks, or shell=True calls — letting an attacker append arbitrary commands. It is one of the most direct paths to remote code execution.
The Concatenation Pattern
The classic flaw: building a command string with user input. An input of "file.txt; rm -rf /" becomes two commands. Even "safe" quoting fails when the input contains quotes or shell metacharacters. The only reliable fix is to avoid the shell entirely and use argument arrays.
AI Detection of Command Sinks
WormGPT AI traces taint from user input to shell execution sinks. It recognizes the many ways shells get invoked across languages — os.system, subprocess with shell=True, Runtime.exec, child_process exec, eval — and flags any where untrusted data reaches the command without being passed as a discrete argument.
Remediation: Argument Arrays
The fix is to call commands with argument arrays (subprocess.run(["ls", filename]) without shell=True) so the input is a parameter, not part of the command string. WormGPT AI generates this refactor and references CWE-78.
Key Takeaways
- Shell concatenation is the root of command injection.
- Quoting is insufficient; argument arrays are the fix.
- AI traces taint to shell sinks across all languages.
- Avoiding the shell entirely eliminates the class.
FAQ
Is shell=True always dangerous? Not always, but it is dangerous the moment any part of the command is influenced by untrusted input. Default to shell=False and argument arrays.
What is blind command injection? The attacker cannot see output but can infer success via timing or out-of-band interaction (a DNS lookup, a callback). It is still full RCE.
How does CVSS score command injection? Typically 9.8 (Critical) — it grants arbitrary command execution on the host, often leading to full system compromise.
Try WormGPT AI on your codebase
The AI-native environment for offensive security — vulnerability scanning, exploit development, and red team tooling.
Open the platform

