Skip to content

Commit 2d9e14b

Browse files
committed
Land rapid7#8763, exploit/multi/handler improvements
ExitOnSession=false && Passive
2 parents d5d1b4b + 3548692 commit 2d9e14b

File tree

1 file changed

+40
-36
lines changed

1 file changed

+40
-36
lines changed

modules/exploits/multi/handler.rb

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,49 +12,53 @@ class MetasploitModule < Msf::Exploit::Remote
1212
#
1313

1414
def initialize(info = {})
15-
super(update_info(info,
16-
'Name' => 'Generic Payload Handler',
17-
'Description' => %q{
18-
This module is a stub that provides all of the
19-
features of the Metasploit payload system to exploits
20-
that have been launched outside of the framework.
21-
},
22-
'License' => MSF_LICENSE,
23-
'Author' => ['hdm'],
24-
'References' => [ ],
25-
'Payload' =>
26-
{
27-
'Space' => 10000000,
28-
'BadChars' => '',
29-
'DisableNops' => true,
30-
},
31-
'Platform' => %w{ android bsd java js linux osx nodejs php python ruby solaris unix win mainframe multi },
32-
'Arch' => ARCH_ALL,
33-
'Targets' => [ [ 'Wildcard Target', { } ] ],
34-
'DefaultTarget' => 0
35-
))
15+
super(
16+
update_info(
17+
info,
18+
'Name' => 'Generic Payload Handler',
19+
'Description' => %q(
20+
This module is a stub that provides all of the
21+
features of the Metasploit payload system to exploits
22+
that have been launched outside of the framework.
23+
),
24+
'License' => MSF_LICENSE,
25+
'Author' => [ 'hdm', 'bcook-r7' ],
26+
'References' => [ ],
27+
'Payload' =>
28+
{
29+
'Space' => 10000000,
30+
'BadChars' => '',
31+
'DisableNops' => true
32+
},
33+
'Platform' => %w[android bsd java js linux osx nodejs php python ruby solaris unix win mainframe multi],
34+
'Arch' => ARCH_ALL,
35+
'Targets' => [ [ 'Wildcard Target', {} ] ],
36+
'DefaultTarget' => 0,
37+
'Stance' => Msf::Exploit::Stance::Passive
38+
)
39+
)
3640

3741
register_advanced_options(
3842
[
39-
OptBool.new("ExitOnSession", [ false, "Return from the exploit after a session has been created", true ]),
40-
OptInt.new("ListenerTimeout", [ false, "The maximum number of seconds to wait for new sessions", 0])
41-
])
43+
OptBool.new(
44+
"ExitOnSession",
45+
[ true, "Return from the exploit after a session has been created", false ]
46+
),
47+
OptInt.new(
48+
"ListenerTimeout",
49+
[ false, "The maximum number of seconds to wait for new sessions", 0 ]
50+
)
51+
]
52+
)
4253
end
4354

4455
def exploit
45-
if not datastore['ExitOnSession'] and not job_id
46-
fail_with(Failure::Unknown, "Setting ExitOnSession to false requires running as a job (exploit -j)")
47-
end
48-
4956
stime = Time.now.to_f
50-
print_status "Starting the payload handler..."
51-
while(true)
52-
break if session_created? and datastore['ExitOnSession']
53-
break if ( datastore['ListenerTimeout'].to_i > 0 and (stime + datastore['ListenerTimeout'].to_i < Time.now.to_f) )
54-
55-
select(nil,nil,nil,1)
57+
timeout = datastore['ListenerTimeout'].to_i
58+
loop do
59+
break if session_created? && datastore['ExitOnSession']
60+
break if timeout.positive? && (stime + timeout < Time.now.to_f)
61+
sleep(1)
5662
end
5763
end
58-
59-
6064
end

0 commit comments

Comments
 (0)