A Visual Guide to SSH Tunnels: Local and Remote Port Forwarding
iximiuz.com
iximiuz.com
Our solution was to run a public host (the Reverse Bastion) that would, upon user request, generate a shell-less linux account for the user and install their public key. The user was then given an SSH command to run from inside their corp network that would connect to Reverse Bastion and establish a reverse tunnel pointing at their database. That way we could "connect" to that user's dedicated port on the Reverse Bastion and our traffic would traverse the tunnel and pop out inside their network, bound for their database. Since it's all TCP tunneling, JDBC drivers had no idea they were hopscotching around networks and did DB queries like usual. As long as you have the user accounts totally locked down and people's port assignments locked to their users via iptables, it was a walled (tunneled?) garden.
The only thing that works reliably is a proper VPN (configured for machine to machine access, not based on username/password which has the same brittleness issue) which these days is available at every customer's site.
Port forwarding goes both ways.
I may, or may not, have used ssh forwarding and reversing forwarding to create a shadow IT tunnel(s) between my home and work when VPN was acting up.
Also, SOCKS proxy is very useful if you can puncture a hole home and your work requires a proxy to access the World Wide Web from the office location.
If you have the funds the Deep Packet Inspection is a big way to defeat attempts to tunnel through HTTPS, DNS, or the like.
Even then you haven’t really solved that particular issue as it’s a people problem not a tech problem. It’s like trying to stop an employee from robbing the bank by getting a thicker vault door in that it’s just not the right type of incentive/disincentive to make an impact.
DPI just makes it harder, so does terminating ssl earlier, or blocking outbound ports.
When measuring security by "number of boxes checked", yes. Unfortunately, these boxes are often overly generic, years too old, or both.
> If you have the funds the Deep Packet Inspection is a big way to defeat attempts to tunnel through HTTPS, DNS, or the like.
What's there to inspect (unless you are decrypting all TLS in a middlebox with a root CA trusted by all clients)? How would you distinguish a "normal" WebSocket connection (as used by many sites these days) from a tunneled SSH connection, for example?
If you generally want to allow your users to reach the broader public internet (or even just web), this approach seems completely futile.
Doing something like this from host B:
ssh -N -R 1080 user@A
Will allow a browser running on A access network through a SOCKS5 proxy on B while setting the proxy as localhost:1080.I use a reverse SSH tunnel to access my home network when traveling.
Ex:
- [Machine-A (on my LAN, behind NAT, with a dynamic IP address)] maintains a long lived SSH connection to [Machine-B (a VPS with a public IP)] with a reverse tunnel configuration.
- I can then SSH into Machine-B and follow the tunnel back into Machine-A, and from there access the rest of my home network.
It works pretty well. I can access files on my NAS and check on my Raspberry Pi cameras without needing to put either on "the cloud". Although I have to admit I always have to pull up a resource like the one in OP whenever I want to setup something like this, I've never learned it by heart and always need a refresher.
Personally, the metaphor that made it work for me was "postcards going to a motel." As in AHA, when I'm doing SSH Tunnelling, Room 22 is the only one open and receiving mail, all the other rooms are locked. Now, there might be a website behind the door on locked room 443, and I can send my postcards to room 22 with the instructions to send them on over to 443 once they get there, and over at the motel they'll also know to do the reverse.
Bookmarked / saved to PKM.
Aside from the pretty Excalidraw diagrams, clear prose, and IRL use cases, I'm grateful for eg this tiny gem:
"The mnemonics are "ssh -L local:remote" and "ssh -R remote:local" and it's always the left-hand side that opens a new port."
It should be read as local port (forwarding) and remote port (forwarding).
With local, the listening port is local. With remote, it is remote.
Also this is one of the coolest uses of SSH tunnels that I recently found: https://github.com/regymm/termux-reverse-ssh
It's pretty scary how some vendors poke holes into your home network using tunnels.
ssh connect
remote myserver:80
to local 172.27.17.2:8080
one-way
The syntax should totally do away with the concept of tunneling, connecting ports is easier to grasp IMHO.
BTW I'm not sure that the "one-way" argument is really needed.Then any local machine can e.g. curl yourip:8080 and the request will go through your machine, over the SSH tunnel, to the remote machine