Use netcat to bridge thru firewall?

1

2

I have a machine behind a firewall. It's my machine, I have set up ssh, but it's completely firewalled. My solution has been to use a reverse shell set up on a cron basis to reconnect if it fails using netcat. The command is bash -i >& /dev/tcp/myhostname.duckdns.org/10000 0>&1 and on my local computer nc -l 10000. Up until now this has worked, because I can tell it to join my private VPN with a command. For some reason that command isn't working. So, I'm able to "login" via the spawned bash shell but I cannot ssh back to my computer because Pseudo-terminal will not be allocated because stdin is not a terminal. and I haven't set up ssh keys on that system ever, and it won't let me log in with a password.

So I've been trying to find a solution using netcat but have been unsuccessful. What I am envisioning is something like this:

[server] ---netcat--> [my-computer:port1]

such that I can piggyback off that to log in to the sshd server and fix whatever needs fixing. But I can't figure out the netcat commands that would accomplish that. Any help?

justin

Posted 2016-06-22T02:55:05.507

Reputation: 121

Answers

1

Figured out an answer for the rest of internet (and myself). Here's how to achieve port forwarding with only netcat (verified working on OS X El Capitan):

On server behind (incoming) firewall:

nc localhost 22 >& /dev/tcp/<your-hostname>/<open port on local computer, i.e. 9000> 0>&1

On local computer:

cd /tmp; mkfifo backpipe
nc -l 9000 0<backpipe | nc -l 9001 | tee backpipe

On local computer, separate terminal:

ssh localhost -p 9001

justin

Posted 2016-06-22T02:55:05.507

Reputation: 121