CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/multi/handler.rb
Views: 1904
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Exploit::Remote
7
Rank = ManualRanking
8
9
#
10
# This module does basically nothing
11
# NOTE: Because of this it's missing a disclosure date that makes msftidy angry.
12
#
13
14
def initialize(info = {})
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 apple_ios 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
'DefaultOptions' => { 'PAYLOAD' => 'generic/shell_reverse_tcp' }
38
)
39
)
40
41
register_advanced_options(
42
[
43
OptBool.new(
44
"ExitOnSession",
45
[ true, "Return from the exploit after a session has been created", true ]
46
),
47
OptInt.new(
48
"ListenerTimeout",
49
[ false, "The maximum number of seconds to wait for new sessions", 0 ]
50
)
51
]
52
)
53
end
54
55
def exploit
56
if datastore['DisablePayloadHandler']
57
print_error "DisablePayloadHandler is enabled, so there is nothing to do. Exiting!"
58
return
59
end
60
61
stime = Time.now.to_f
62
timeout = datastore['ListenerTimeout'].to_i
63
loop do
64
break if session_created? && datastore['ExitOnSession']
65
break if timeout > 0 && (stime + timeout < Time.now.to_f)
66
Rex::ThreadSafe.sleep(1)
67
end
68
end
69
end
70
71