Explore the dangers, mechanisms, and defenses against Command Injection attacks.
Command Injection is a security vulnerability that allows an attacker to execute arbitrary system commands on the host operating system via a vulnerable application.
Experience a simulated Command Injection attack
Common code patterns that can lead to Command Injection vulnerabilities (for educational purposes only)
If userInput is '8.8.8.8 && cat /etc/passwd', it will execute both commands.
ping userInputIf filename is 'secret.txt; rm -rf /', it will display the file content and then attempt to delete all files.
<?php system('cat ' . $_GET['filename']); ?>If user_input is '$(rm -rf /)', it will attempt to delete all files.
import os
os.system('echo ' + user_input)If userInput is '8.8.8.8 && cat /etc/passwd', it will execute both commands.
const { exec } = require('child_process');
exec('ping ' + userInput, (error, stdout, stderr) => {
console.log(stdout);
});