Command Injection and SSRF
Make a web server run your commands, or make it send requests for you.
When an application passes user input to a shell or uses it to fetch a URL, an attacker may be able to take control of the server or reach systems behind the firewall.
1
Command injection
A "network check" page runs:
phpsystem("ping -c 1 " . $_GET["host"]);Entering
8.8.8.8; whoamiruns two commands, because;separates commands in the shell. Other separators:&&,||,|, and command substitution$(...)or backticks.Attackers prove injection with harmless commands such as
whoamiorid, or withsleep 5when they can't see output (blind injection).Fix: don't call a shell with user input. Use library functions, pass arguments as an array, and validate input against an allowlist.
2
Server-side request forgery
A feature fetches a URL you supply, e.g. "import profile picture from URL". In SSRF (Server-Side Request Forgery), you give it an internal address instead:
http://localhost:8080/admin http://169.254.169.254/latest/meta-data/The second address is the cloud metadata service on AWS and other clouds. From inside the server it can return temporary cloud credentials.
Fix: allowlist the hosts the server may fetch, block private and link-local ranges, and don't return raw responses to the user.
โ Report a problem with this room
Log in to report a problem.