@@ -68,33 +68,33 @@ def load_library(opts)
68
68
load_flags = LOAD_LIBRARY_FLAG_LOCAL
69
69
70
70
# No library path, no cookie.
71
- if ( library_path == nil )
71
+ if library_path . nil?
72
72
raise ArgumentError , "No library file path was supplied" , caller
73
73
end
74
74
75
75
# Set up the proper loading flags
76
- if ( opts [ 'UploadLibrary' ] )
76
+ if opts [ 'UploadLibrary' ]
77
77
load_flags &= ~LOAD_LIBRARY_FLAG_LOCAL
78
78
end
79
- if ( opts [ 'SaveToDisk' ] )
79
+ if opts [ 'SaveToDisk' ]
80
80
load_flags |= LOAD_LIBRARY_FLAG_ON_DISK
81
81
end
82
- if ( opts [ 'Extension' ] )
82
+ if opts [ 'Extension' ]
83
83
load_flags |= LOAD_LIBRARY_FLAG_EXTENSION
84
84
end
85
85
86
86
# Create a request packet
87
87
request = Packet . create_request ( 'core_loadlib' )
88
88
89
89
# If we must upload the library, do so now
90
- if ( ( load_flags & LOAD_LIBRARY_FLAG_LOCAL ) != LOAD_LIBRARY_FLAG_LOCAL )
90
+ if ( load_flags & LOAD_LIBRARY_FLAG_LOCAL ) != LOAD_LIBRARY_FLAG_LOCAL
91
91
image = ''
92
92
93
93
::File . open ( library_path , 'rb' ) { |f |
94
94
image = f . read
95
95
}
96
96
97
- if ( image != nil )
97
+ if ! image . nil?
98
98
request . add_tlv ( TLV_TYPE_DATA , image , false , client . capabilities [ :zlib ] )
99
99
else
100
100
raise RuntimeError , "Failed to serialize library #{ library_path } ." , caller
@@ -103,7 +103,7 @@ def load_library(opts)
103
103
# If it's an extension we're dealing with, rename the library
104
104
# path of the local and target so that it gets loaded with a random
105
105
# name
106
- if ( opts [ 'Extension' ] )
106
+ if opts [ 'Extension' ]
107
107
library_path = "ext" + rand ( 1000000 ) . to_s + ".#{ client . binary_suffix } "
108
108
target_path = library_path
109
109
end
@@ -113,17 +113,17 @@ def load_library(opts)
113
113
request . add_tlv ( TLV_TYPE_LIBRARY_PATH , library_path )
114
114
request . add_tlv ( TLV_TYPE_FLAGS , load_flags )
115
115
116
- if ( target_path != nil )
116
+ if ! target_path . nil?
117
117
request . add_tlv ( TLV_TYPE_TARGET_PATH , target_path )
118
118
end
119
119
120
120
# Transmit the request and wait the default timeout seconds for a response
121
121
response = self . client . send_packet_wait_response ( request , self . client . response_timeout )
122
122
123
123
# No response?
124
- if ( response == nil )
124
+ if response . nil?
125
125
raise RuntimeError , "No response was received to the core_loadlib request." , caller
126
- elsif ( response . result != 0 )
126
+ elsif response . result != 0
127
127
raise RuntimeError , "The core_loadlib request failed with result: #{ response . result } ." , caller
128
128
end
129
129
@@ -147,19 +147,19 @@ def load_library(opts)
147
147
# memory on the remote machine
148
148
#
149
149
def use ( mod , opts = { } )
150
- if ( mod == nil )
150
+ if mod . nil?
151
151
raise RuntimeError , "No modules were specified" , caller
152
152
end
153
153
# Get us to the installation root and then into data/meterpreter, where
154
154
# the file is expected to be
155
155
modname = "ext_server_#{ mod . downcase } "
156
156
path = MeterpreterBinaries . path ( modname , client . binary_suffix )
157
157
158
- if ( opts [ 'ExtensionPath' ] )
158
+ if opts [ 'ExtensionPath' ]
159
159
path = opts [ 'ExtensionPath' ]
160
160
end
161
161
162
- if path == nil
162
+ if path . nil?
163
163
raise RuntimeError , "No module of the name #{ modname } .#{ client . binary_suffix } found" , caller
164
164
end
165
165
@@ -191,24 +191,24 @@ def migrate( pid )
191
191
192
192
# Determine the architecture for the pid we are going to migrate into...
193
193
client . sys . process . processes . each { | p |
194
- if ( p [ 'pid' ] == pid )
194
+ if p [ 'pid' ] == pid
195
195
process = p
196
196
break
197
197
end
198
198
}
199
199
200
200
# We cant migrate into a process that does not exist.
201
- if ( process == nil )
201
+ if process . nil?
202
202
raise RuntimeError , "Cannot migrate into non existent process" , caller
203
203
end
204
204
205
205
# We cant migrate into a process that we are unable to open
206
- if ( process [ 'arch' ] == nil or process [ 'arch' ] . empty? )
206
+ if process [ 'arch' ] . nil? or process [ 'arch' ] . empty?
207
207
raise RuntimeError , "Cannot migrate into this process (insufficient privileges)" , caller
208
208
end
209
209
210
210
# And we also cant migrate into our own current process...
211
- if ( process [ 'pid' ] == client . sys . process . getpid )
211
+ if process [ 'pid' ] == client . sys . process . getpid
212
212
raise RuntimeError , "Cannot migrate into current process" , caller
213
213
end
214
214
@@ -217,10 +217,10 @@ def migrate( pid )
217
217
c . include ( ::Msf ::Payload ::Stager )
218
218
219
219
# Include the appropriate reflective dll injection module for the target process architecture...
220
- if ( process [ 'arch' ] == ARCH_X86 )
220
+ if process [ 'arch' ] == ARCH_X86
221
221
c . include ( ::Msf ::Payload ::Windows ::ReflectiveDllInject )
222
222
binary_suffix = "x86.dll"
223
- elsif ( process [ 'arch' ] == ARCH_X86_64 )
223
+ elsif process [ 'arch' ] == ARCH_X86_64
224
224
c . include ( ::Msf ::Payload ::Windows ::ReflectiveDllInject_x64 )
225
225
binary_suffix = "x64.dll"
226
226
else
@@ -231,7 +231,7 @@ def migrate( pid )
231
231
migrate_stager = c . new ( )
232
232
233
233
dll = MeterpreterBinaries . path ( 'metsrv' , binary_suffix )
234
- if dll == nil
234
+ if dll . nil?
235
235
raise RuntimeError , "metsrv.#{ binary_suffix } not found" , caller
236
236
end
237
237
migrate_stager . datastore [ 'DLL' ] = dll
@@ -262,7 +262,7 @@ def migrate( pid )
262
262
request . add_tlv ( TLV_TYPE_MIGRATE_PID , pid )
263
263
request . add_tlv ( TLV_TYPE_MIGRATE_LEN , blob . length )
264
264
request . add_tlv ( TLV_TYPE_MIGRATE_PAYLOAD , blob , false , client . capabilities [ :zlib ] )
265
- if ( process [ 'arch' ] == ARCH_X86_64 )
265
+ if process [ 'arch' ] == ARCH_X86_64
266
266
request . add_tlv ( TLV_TYPE_MIGRATE_ARCH , 2 ) # PROCESS_ARCH_X64
267
267
else
268
268
request . add_tlv ( TLV_TYPE_MIGRATE_ARCH , 1 ) # PROCESS_ARCH_X86
@@ -310,7 +310,7 @@ def migrate( pid )
310
310
# Update the meterpreter platform/suffix for loading extensions as we may have changed target architecture
311
311
# sf: this is kinda hacky but it works. As ruby doesnt let you un-include a module this is the simplest solution I could think of.
312
312
# If the platform specific modules Meterpreter_x64_Win/Meterpreter_x86_Win change significantly we will need a better way to do this.
313
- if ( process [ 'arch' ] == ARCH_X86_64 )
313
+ if process [ 'arch' ] == ARCH_X86_64
314
314
client . platform = 'x64/win64'
315
315
client . binary_suffix = 'x64.dll'
316
316
else
0 commit comments