NFS no_root_squash/no_all_squash misconfiguration PE
Last updated
Last updated
Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Soma _ /etc/exports _ faili, ikiwa unapata directory ambayo imewekwa kama no_root_squash, basi unaweza kufikia hiyo kutoka kama mteja na kuandika ndani ya hiyo directory kama ungekuwa root wa mashine hiyo.
no_root_squash: Chaguo hili kimsingi linampa mamlaka mtumiaji root kwenye mteja kufikia faili kwenye seva ya NFS kama root. Na hii inaweza kusababisha athari kubwa za usalama.
no_all_squash: Hii ni sawa na chaguo la no_root_squash lakini inatumika kwa watumiaji wasiokuwa root. Fikiria, una shell kama mtumiaji nobody; umeangalia faili ya /etc/exports; chaguo la no_all_squash lipo; angalia faili ya /etc/passwd; fanya kama mtumiaji asiye root; tengeneza faili la suid kama mtumiaji huyo (kwa kuunganisha kwa kutumia nfs). Tekeleza suid kama mtumiaji nobody na kuwa mtumiaji tofauti.
Ikiwa umepata udhaifu huu, unaweza kuutumia:
Kuweka hiyo directory kwenye mashine ya mteja, na kama root kunakili ndani ya folda iliyounganishwa /bin/bash binary na kumpa haki za SUID, na kutekeleza kutoka kwa mashine ya mwathirika hiyo bash binary.
Kuweka hiyo directory kwenye mashine ya mteja, na kama root kunakili ndani ya folda iliyowekwa payload yetu iliyotengenezwa ambayo itatumia ruhusa ya SUID, itapeleka SUID haki, na kuendesha kutoka kwa mashine ya mwathirika hiyo binary (unaweza kupata hapa baadhi ya C SUID payloads).
Kumbuka kwamba ikiwa unaweza kuunda tunnel kutoka kwa mashine yako hadi mashine ya mwathirika unaweza bado kutumia toleo la Remote kutekeleza kupanda kwa haki hii kwa kutunga bandari zinazohitajika.
Trick ifuatayo ni katika kesi faili /etc/exports
inaonyesha IP. Katika kesi hii hutoweza kutumia kwa njia yoyote exploit ya mbali na utahitaji kudhulumu hila hii.
Sharti lingine muhimu ili exploit ifanye kazi ni kwamba export ndani ya /etc/export
lazima litumie bendera insecure
.
--Sijui kama /etc/export
inaonyesha anwani ya IP hila hii itafanya kazi--
Hali hii inahusisha kutumia faida ya NFS iliyowekwa kwenye mashine ya ndani, ikitumia kasoro katika spesifikesheni ya NFSv3 ambayo inaruhusu mteja kubainisha uid/gid yake, ambayo inaweza kuwezesha ufikiaji usioidhinishwa. Kutekeleza kunahusisha kutumia libnfs, maktaba inayoruhusu kutunga wito wa NFS RPC.
Hatua za ukusanyaji wa maktaba zinaweza kuhitaji marekebisho kulingana na toleo la kernel. Katika kesi hii maalum, syscalls za fallocate zilikuwa zimeandikwa nje. Mchakato wa ukusanyaji unajumuisha amri zifuatazo:
The exploit involves creating a simple C program (pwn.c
) that elevates privileges to root and then executing a shell. The program is compiled, and the resulting binary (a.out
) is placed on the share with suid root, using ld_nfs.so
to fake the uid in the RPC calls:
Compile the exploit code:
Place the exploit on the share and modify its permissions by faking the uid:
Execute the exploit to gain root privileges:
Once root access is obtained, to interact with the NFS share without changing ownership (to avoid leaving traces), a Python script (nfsh.py) is used. This script adjusts the uid to match that of the file being accessed, allowing for interaction with files on the share without permission issues:
Kimbia kama:
Jifunze na fanya mazoezi ya AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Jifunze na fanya mazoezi ya GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)