Picture an internal "network diagnostics" page. One text field, one Ping button, a block of output underneath. Somewhere on the server a line of code takes what you typed and appends it to ping -c 4, then hands the entire string to a shell.

That is OS command injection, and the demonstration takes five seconds.

The test

Enter 127.0.0.1. You get normal ping replies. Now enter:

127.0.0.1; id 

The shell sees a semicolon and reads two commands: the ping, then id. If the response ends with something like uid=33(www-data), the application ran a command you chose. Nothing was broken to get there. id only prints the account name.

Separators to try

Filters tend to catch one and miss the others, so test all of them:

  • ; runs the next command regardless of the first
  • && runs it only if the first succeeds
  • | pipes the first command's output into the second
  • a newline character, which many filters never consider

If the page filters the characters you try, that is a hint the input is reaching a shell, not proof it is safe.

Fix the structure, skip the filter

Blocklists age badly. The reliable change is structural: do not use a shell. In most languages you can execute a program and pass arguments as an array, so the address is one argument and a semicolon is just a character in it. Add a check that the input parses as an IP address, and reject the request before any command is built.

What the output tells you

Read the whole response, not only the last line. If the ping output appears and then a username, the injected command ran after the original. If only the username appears, the application may have discarded the ping result. If the page shows a generic error, try a command that produces a visible difference, such as 127.0.0.1; sleep 5, and watch whether the response takes five seconds longer. That timing test works even when the app never prints command output.

What to report

Name the field, the exact payload, and the command that ran. Say that you used id or sleep and nothing else. A finding like "the host parameter reaches a shell; ; id returned the web server account" is complete. You do not need to read files off the server to make the case, and on a real target you should not.

Practise it

Codelivly has a free OS command injection lab built around a ping tool exactly like this one. You abuse it with shell separators, run your own commands, and read the flag from the environment.

After that, if you want the rest of the beginner web workflow in one place, the Web Application Hacking book for beginners is 200 pages.