The idea
Solveig has an authorised engagement against Nordvik Telecom, whose on-call engineers use an ops portal to check whether a host is reachable. You type a host, it pings it, it tells you if the host answered. Useful and ordinary.
Under the hood, the portal does the obvious thing: it builds the line ping -c 1 <your host> and runs it through a shell. A shell does not see "a hostname" — it sees a command line, where ;, | and $(…) separate and chain commands. So if your "host" is 8.8.8.8; id, the shell runs ping and then id. Your input was never data; it went straight into the command position. That is OS command injection, and it hands an attacker the ability to run commands as the server.
This target keeps that power inert: the only commands it will run are a handful of harmless built-ins, standing in for the free rein a real portal would give. The lesson is that your input became a command at all.
Steps
-
The portal checks reachability
You are on Solveig's box,
kali, with the portal at10.0.1.20. Open it in the Viewer to see the console, then use it as intended: ask it to check a well-known host. Notice that the response echoes the exact command the portal built — that is your window into how your input is used.kali:~# curl -s -G --data-urlencode "host=8.8.8.8" http://10.0.1.20/api/diagnose
-
Your input becomes the command
Test the boundary. In a shell,
;ends one command and starts the next. If the portal really pastes your host into the line and runs it through a shell, then a host of8.8.8.8; idwill runpingandid. Try it and read the output.kali:~# curl -s -G --data-urlencode "host=8.8.8.8; id" http://10.0.1.20/api/diagnose
-
Read the ops secret
Turn the foothold on something real. The portal runs as the
opsuser, which can read the portal's own operations config — a file no endpoint serves. Inject acatof it and read the ops token straight off the server.kali:~# curl -s -G --data-urlencode "host=8.8.8.8; cat /opt/app/ops-secret.conf" http://10.0.1.20/api/diagnose
-
Swap seats: no shell, validate input
Now you run Nordvik. Escaping shell metacharacters by hand is a trap — the quoting rules differ per shell and trip you up in ways that are hard to spot. The real fix is to not build a shell command line at all: validate the input, then pass it as a single argument to one fixed program, with no shell to interpret it. The safe endpoint,
/api/diagnose-safe, does this. Send it the injection that worked a moment ago.kali:~# curl -s -o /dev/null -w "%{http_code}" -G --data-urlencode "host=8.8.8.8; id" http://10.0.1.20/api/diagnose-safe kali:~# curl -s -G --data-urlencode "host=8.8.8.8" http://10.0.1.20/api/diagnose-safe
Run these steps on real machines