Skip to content
Payload Playground
HomeGuidesCommand Injection Testing Guide

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.

Intermediate
6 steps10 payload examples~60 min
Authorized testing only. Only use these techniques on systems you have explicit permission to test.
1

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.

Example payloads
ip=127.0.0.1
filename=test.pdf
host=example.com
2

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.

Example payloads
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)
3

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.

4

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.

5

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.

6

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.

Level up your security testing

Send feedback

Report an issue or suggest an improvement.

0/2000

Your report includes this page (/guides/how-to-test-for-command-injection) and your browser. If you’re signed in, we include your account ID and plan so support can prioritize Pro requests. Please leave out secrets and client data.