EncryptCodecencryptcodec
Simulations/Command Injection

Command Injection

Intermediate

A web app runs ping <hostname> on the server using unsanitized user input. Inject shell commands to read files, run programs, and even open a reverse shell — then learn how to prevent it.

Progress:
1
Chain a Command
2
Use Input Validation
3
Reverse Shell Attempt
⚡ Ping Utility
// server-side handler
app.post('/api/ping', (req, res) => {
exec(`ping -c 3 ${req.body.host}`, cb)
})
Try: google.com; cat /etc/passwd or google.com && whoami
🛡 Defenses
Terminal output — server console
Enter a hostname and click Run Ping…

Challenges

1
Chain a Command
Inject a second command after the hostname using ;, &&, or || to read sensitive data or run arbitrary commands.
hints
2
Use Input Validation
Enable the Input Sanitization toggle and show that the injection from Challenge 1 is blocked.
hints
3
Reverse Shell Attempt
Attempt a reverse shell payload to demonstrate the full severity of command injection.
hints
How to prevent command injection
execFile, allowlist validation, and avoiding shell=true

Frequently Asked Questions