Command Injection
Cheat sheet · https://pcornel.dk/topic.php?topic=4757
Answer
Command injection happens when user input reaches an operating system shell, letting attackers run commands. Avoid shell calls, use APIs with argument lists and strictly validate input.
Remember
- Avoid calling a shell with user input.
- Pass arguments as lists to process APIs.
- Validate input strictly.
First checks
- Code review: shell=True/exec/system calls — dangerous sinks
- Use argument arrays (subprocess.run([...])) — no shell
- Input allowlists — validation
Verify in this order
input → command builder → (no shell) → process
Where it usually breaks
First mismatch in asset/subject identity → trust/authentication → authorization/policy → enforcement/control → telemetry/detection → protected outcome/response; preserve identity/policy/pre-state before mutation.
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=4757