labs / cmdi

Command Injection Sandbox

Break out of a ping command and read a file you were never meant to see.

Injection Intermediate Server lab
leaderboard →
    Objective Run a command of your choosing through this ping tool and read the flag file in /home/appsec.

    This admin tool pings a host you supply. Under the hood it runs ping -c 1 <your input> as a shell command. Shells treat ;, && and | as command separators… (Everything here is simulated — no real shell is involved.)

    How the fix works

    Never build shell strings from user input. Call the program directly with an argument array (so input can't become a new command), or avoid the shell entirely with a library. Validate that a hostname is actually a hostname. Then ; cat … is just a weird-looking host, not a breakout.

    $ patch ./cmdi

    You broke it — now fix it. Which change prevents command injection?

    exec("ping -c 1 " + host);