Command Injection Testing Guide
Review where application input reaches an OS command, assess the evidence for execution, and verify a fix with a harmless regression test.
Identify OS interaction points
Find application features that likely invoke system commands: ping/traceroute utilities, file operations, PDF/image processing, DNS lookups, and any functionality that wraps CLI tools.
ip=127.0.0.1
filename=test.pdf
host=example.com
Test command separators
Inject command separators to append your own commands. Different operating systems use different separators. Test each to determine the OS and which characters are allowed.
127.0.0.1; whoami
127.0.0.1 | id
127.0.0.1 || id
127.0.0.1 & whoami
127.0.0.1 && id
`whoami`
$(id)
Check what the evidence establishes
A slow response has several possible causes. In an application you maintain, trace the request to the process call in source code and correlate it with existing process or application logs. Record which facts you observed and which effects are still unknown.
Remove the shell from the data path
Use a library function for the operation when possible. If a subprocess is required, fix the executable and allowed options in code, validate input against the field's expected format, and pass each value as a separate argument. An argument starting with a dash may still select an option in the child program.
Verify the fix with a process stub
In a unit test, replace the process launcher with a recording stub. For a valid filename such as quarterly report.pdf, assert that the stub received the entire name as one argument and that shell parsing is disabled. For a value outside the field's allowlist, assert that the launcher was never called.
Document the observed impact
Record the affected field, the service account's privileges, the evidence of execution, and the regression test result. State which resources the process could access and which effects were observed. Use the Pentest Workspace below to track the fix and its retest.
Related Resources
Level up your security testing
Install the CLI
npx payload-playgroundExplore All Tools
Encoding, hashing, JWT & more
Browse Cheat Sheets
Quick-reference payload guides