TunnelBandit: seeing what your SSH tunnels are doing
Anyone who moves traffic through SSH for a living ends up with the same problem. You have four or five tunnels running, you set them up over an hour, and twenty minutes later you cannot remember which local port goes where. ps tells you the command lines, which is not the same as knowing what is working. A tunnel that died is indistinguishable from one that is simply idle.
This is not only a pentest problem. Plenty of people hit it administering cloud hosts: you are SSH’d into a box, something is listening on its loopback, and you want to reach it from a browser on your own machine. That is a forward tunnel, and the moment you have three of them the bookkeeping is the hard part.
So I built TunnelBandit: a terminal interface over the SSH you already have, built so the answer to “what is up and what is moving” is a glance rather than an investigation.
The screen
Sessions on the left, tunnels on the right. All output below is real, from a lab with two hosts.
| |
| |
Every column there answers a question I kept asking myself and having to work out by hand.
L and R say which machine the listening end is on, which is the thing most often confused and the thing a command line states least clearly. The arrow gives the direction traffic moves relative to that listener: → outbound, ← inbound, ⇄ for a dynamic proxy that is both. Colour carries all of it too, but never alone, so the display survives a monochrome terminal and a colourblind reader.
The sparkline is eight characters of recent throughput beside the rate. A number alone cannot tell you whether 491 B/s is a spike or a plateau, and that distinction is usually what you want.
Idle tunnels render dim, so the one doing something is the brightest thing on screen.
The tunnels outlive the interface
TunnelBandit runs as a daemon that owns the sessions, with the terminal interface as a separate, stateless client. Quit the interface with q and your tunnels keep running; reattach later and the display repopulates. Only Q shuts the daemon down.
That split is also what makes the next part work.
Tunnels through tunnels
Forward a far host’s SSH port to a local port, then open a session on that local port, and you are two hops deep. Your tunnels now reach things only the far host can see.
| |
The trouble is that the second command’s host is your own loopback. That is true of the address you dialled and tells you nothing about where the session landed. Plain tooling shows you paul@127.0.0.1 and leaves you to remember the rest.
TunnelBandit works it out:
| |
The indent and └ show the chain; the line underneath names the host it really reaches. Nothing is probed for this. A session whose host is a loopback address and whose port matches one of your own local listeners is reached through that tunnel, so the chain is known before any traffic flows.
The same ambiguity bites the tunnel rows, where it is easier to miss. A target of 127.0.0.1:8080 means a different machine depending on which session carries it, and the R glyph cannot tell you which. So the row says so:
| |
And the detail pane spells out the route:
| |
A nested session also dies when the tunnel beneath it dies, and its own SSH takes minutes to notice. TunnelBandit marks the session and its tunnels degraded within a refresh, naming the carrier that went.
What happened while you were not looking
The lists tell you what is true now. The activity pane tells you what changed, which is the question you actually have on returning to a terminal you left running on a second monitor.
| |
The daemon keeps this history, not the interface, and replays it when a window attaches. That ordering matters: a log the interface built by watching would be empty in the window you open after something broke, which is the window that wanted it.
Two decisions about authentication
Host key checking never stops a tunnel. A host you have never reached before opens normally. No known_hosts is read or written, so nothing about host identity can fail a connection and your own file is left alone.
That is a trade, and the display says so rather than letting you assume otherwise. The key presented is still recorded and compared against what that host showed last time, so a change raises an error on the session while the connection still succeeds. Enforcement and detection turn out to be separable, and keeping the second one costs nothing.
Hosts that want a password work, and you do not have to know in advance. If a host refuses your key and says a password would be accepted, you get a masked prompt and the session comes up. SSH will not take a secret from an argument or a variable, so this goes through its askpass mechanism: the daemon holds the password in memory between you typing it and SSH asking for it, hands it over once, and drops it. It reaches no command line, no environment, no log and no file on disk.
Where it is honest about limits
Per-tunnel byte counts come from polling kernel socket counters, so bytes moved between the last poll and a connection closing cannot be seen from outside the process. The totals are approximate and the display marks them (approx) rather than implying precision it does not have.
A relay running on the far host cannot be measured from your machine at all, and that reads as “not measurable” instead of a confident zero that would look like no traffic.
The activity history holds 500 entries and does not survive a daemon restart.
Running it
| |
Tunnels are created from an entry line that takes what you would type at a shell, so ssh -L 8080:10.0.0.5:80 user@host works as written and no new syntax is required. There is a guided wizard on w for when you want the direction decided for you, and a tools pane on t for key generation, ssh-copy-id, transfers and proxychains configs.
It is Linux-only by design, since it leans on Unix sockets, /proc and ss.
TunnelBandit is on GitHub: RedTeamRaccoon/TunnelBandit. It drives the OpenSSH, socat and netcat already on your system rather than reimplementing them.