@@ -183,7 +183,7 @@ def use(mod, opts = { })
183
183
# Migrates the meterpreter instance to the process specified
184
184
# by pid. The connection to the server remains established.
185
185
#
186
- def migrate ( pid , writable_dir = "/tmp/" )
186
+ def migrate ( pid , writable_dir = nil )
187
187
keepalive = client . send_keepalives
188
188
client . send_keepalives = false
189
189
process = nil
@@ -207,20 +207,22 @@ def migrate(pid, writable_dir="/tmp/")
207
207
raise RuntimeError , "Cannot migrate into non existent process" , caller
208
208
end
209
209
210
- # We can't migrate into a process that we are unable to open
210
+ # We cannot migrate into a process that we are unable to open
211
211
# On linux, arch is empty even if we can access the process
212
- if client . platform =~ /win/ && ( process [ 'arch' ] == nil || process [ 'arch' ] . empty? )
213
- raise RuntimeError , "Cannot migrate into this process (insufficient privileges)" , caller
212
+ if client . platform =~ /win/
213
+ if process [ 'arch' ] == nil || process [ 'arch' ] . empty?
214
+ raise RuntimeError , "Cannot migrate into this process (insufficient privileges)" , caller
215
+ end
214
216
end
215
217
216
- # And we also cant migrate into our own current process...
218
+ # And we also cannot migrate into our own current process...
217
219
if process [ 'pid' ] == client . sys . process . getpid
218
220
raise RuntimeError , "Cannot migrate into current process" , caller
219
221
end
220
222
221
223
if client . platform =~ /linux/
222
224
if writable_dir . blank?
223
- writable_dir = "/tmp/"
225
+ writable_dir = tmp_folder
224
226
end
225
227
226
228
stat_dir = client . fs . filestat . new ( writable_dir )
@@ -231,7 +233,7 @@ def migrate(pid, writable_dir="/tmp/")
231
233
# Rex::Post::FileStat#writable? isn't available
232
234
end
233
235
234
- blob = generate_payload_stub ( client , process )
236
+ blob = generate_payload_stub ( process )
235
237
236
238
# Build the migration request
237
239
request = Packet . create_request ( 'core_migrate' )
@@ -361,10 +363,10 @@ def shutdown
361
363
362
364
private
363
365
364
- def generate_payload_stub ( client , process )
366
+ def generate_payload_stub ( process )
365
367
case client . platform
366
368
when /win/i
367
- blob = generate_windows_stub ( client , process )
369
+ blob = generate_windows_stub ( process )
368
370
when /linux/i
369
371
blob = generate_linux_stub
370
372
else
@@ -374,7 +376,7 @@ def generate_payload_stub(client, process)
374
376
blob
375
377
end
376
378
377
- def generate_windows_stub ( client , process )
379
+ def generate_windows_stub ( process )
378
380
c = Class . new ( ::Msf ::Payload )
379
381
c . include ( ::Msf ::Payload ::Stager )
380
382
@@ -437,6 +439,16 @@ def elf_ep(payload)
437
439
return ep
438
440
end
439
441
442
+ def tmp_folder
443
+ tmp = client . sys . config . getenv ( 'TMPDIR' )
444
+
445
+ if tmp . blank?
446
+ tmp = '/tmp'
447
+ end
448
+
449
+ tmp
450
+ end
451
+
440
452
end
441
453
442
454
end ; end ; end
0 commit comments