🔐Command Injection
Also known as OS Command Injection, Shell Injection
Slipping a command into a form so the web app runs it.
Think of it like
Think of it like a note that asks for a book. A line at the end also says to empty the safe.
Example
A web tool pings any address you type. An attacker types example.com; cat /etc/passwd, and the page shows the server's user list.
Why it matters
It hands the attacker the server itself. From there they can read secrets, change files or reach other machines.
Definition
Example code
python
# Unsafe: the text goes into a shell
os.system("ping -c 1 " + host)
# Safe: the text is one argument, no shell
subprocess.run(["ping", "-c", "1", host])Common mistake
Key takeaways
- 1The shell builds it. User text joins the command line.
- 2Signs chain commands. A ; or && starts another one.
- 3Skip the shell. Pass the text as one argument.