SSH SOCKS5 Proxy: 3 Dialects, No Failure Reply

The usual one-liner is ssh -N -D 1080 user@host, and it does create a SOCKS proxy, but it creates a peculiar one. No password is ever asked of the client, more than one dialect walks through the same port, and a target that cannot be reached is not answered with an error code at all.

We pointed a Windows OpenSSH 10.3 client at a test SSH daemon we control, so every forwarding request could be logged at the far end and every reply byte read at the near end. Nineteen probes later, the picture is specific enough to write down: the port belongs to the session, the reply describes the tunnel rather than the destination, and the name lookup always happens on the other machine.

3dialects answered on the same port
1SSH channel per SOCKS connection
0reply bytes when a target fails
2.1 ssilence before a refused target closes

Treat the reply code from an ssh -D port as news about the channel, not about the website. The only reliable signal that a target is reachable is a byte of application data coming back through the tunnel.

measured

1. The port is a child of the session

Nothing about the command line is abnormal: -N suppresses the shell, -D names a local port, and the client binds it after authentication. What surprises people is the order. With authentication refused, the client exited on a Permission denied message and netstat showed no listening socket at all; with a key that authenticated, 127.0.0.1:1080 appeared and stayed for exactly as long as the session lived.

Two details follow from that. The bind address is loopback rather than every interface, so a second machine cannot borrow the tunnel without an explicit override, and the port disappears the moment the connection drops. A checker that polls the port is therefore testing the session, not the proxy, and an empty answer at startup means the login has not finished rather than that the forwarding is broken.

The other structural fact is fan-in. Each SOCKS connection became its own SSH channel: nine forwarding requests arrived at the far end for nine client connections, multiplexed over the single encrypted session. That is why a hundred open tabs do not open a hundred SSH logins, and also why one stalled channel can be closed without touching the rest.

2. One port, three dialects

Search traffic calls it a SOCKS5 proxy, and it is, but the same listener also answers SOCKS4. A SOCKS4 request for a literal address came back as 00 5A, and a SOCKS4a request, which carries the hostname after the address field, was granted and then returned a full HTTP response inside the tunnel. A client configured for the older protocol is not turned away.

SOCKS5 itself is narrower than the protocol allows. Every greeting that offered no-authentication was answered 05 00, whether or not it also offered username and password, and a greeting that offered only username and password was closed with zero bytes instead of the 05 ff that a compliant server would send. There is no credential to negotiate and, more awkwardly, no error to read when a client insists on one.

Dialect matrix for the same ssh -D listener: what each probe sent, what came back, and whether the tunnel completed.
DialectWhat the probe sentWhat came backEnd to end
SOCKS5, no authentication05 01 0005 00, then a CONNECT replyHTTP 200 inside the tunnel
SOCKS5, credentials only05 01 02Zero bytes, socket closedNever reached a request
SOCKS4, literal address04 01 plus a packed address00 5ATarget did not answer on port 80
SOCKS4a, hostname04 01 plus type 0.0.0.1 and a name00 5AHTTP 200 inside the tunnel
SOCKS5, BIND command05 02Zero bytes after 1 msNot supported

Incoming connections are not part of dynamic forwarding, so a client that needs a listen command finds a closed socket within a millisecond.

3. A dead target is a hang-up, not an error code

This is the part that costs people hours. When the far end cannot open the connection, the client closes the SOCKS socket without sending a reply. A refused target produced zero bytes after 2.1 seconds, an unroutable one produced zero bytes after 4.0 seconds, and in neither case did anything resembling 05 05 appear on the wire.

The delay is the only information available, and it is diagnostic: it is the time the server spent trying. Two seconds tends to mean a fast refusal at the far end, four seconds means the far end waited on a timeout, and a client that gives up sooner than the server does reports its own timeout while the channel is still negotiating.

How much the reply means depends on the server's ordering, which we could vary because the daemon was ours. A server that confirmed the channel before dialling the target made a dead address look identical to a live one, and the client relayed that optimism as 05 00 in eleven milliseconds. A server that dialled first, then confirmed, produced the silent close instead.

Same targets under two server admission orders: confirm-then-dial versus dial-then-confirm.
Server behaviourLive targetRefused targetUnroutable target
Confirms, then dials05 00 in 3 ms05 00 in 11 ms05 00 in 12 ms
Dials, then confirms05 00 in 290 msClosed, no reply, 2.1 sClosed, no reply, 4.0 s

So a checker that treats 05 00 as proof of life is reading a statement about the SSH channel. With a permissive far end it reports every address as healthy, and with a strict one it reports nothing at all, because there is no failure code to read. The proof that a site is reachable is a response arriving inside the tunnel, not the grant that preceded it.

4. The far end resolves every name

Dynamic forwarding hands the destination to the server as text. The forwarding requests that arrived at our daemon carried example.com as a string, carried the literal 93.184.215.14 as a string as well, and carried the loopback address in the same form, so no address space was collapsed on the client side.

That is the practical advantage of the arrangement. A hostname that only resolves inside the remote network becomes reachable from a laptop that has never heard of it, because the lookup happens on the machine with the right resolver. It also means the local DNS settings, hosts file and split-horizon rules have no influence on a proxied request, which cuts both ways when a name resolves differently on the two sides.

The SOCKS4a row in the previous table is the same mechanism with the older spelling: the hostname sits after the user identifier and travels untouched, which is why it worked end to end.

5. What the reply does not tell you

The grant itself carries almost nothing. A successful CONNECT came back as 05 00 00 01 followed by 0.0.0.0 and a port number, and that port number was the port that had been requested rather than any port the far end had bound. Two probes to different services returned 0050 and 0001, matching their targets exactly.

So the address field is a placeholder, and nothing in the reply identifies the local side of the tunnel or the route it took. Reading a hop count or a source address out of it is not possible.

Concurrency, by contrast, behaves. Two tunnels opened at the same moment were both granted and both returned a full response, and they shared the one encrypted connection without interference. That combination, three dialects in, no failure code out, and a placeholder in the middle, is what a plain -D tunnel is: a thin adapter between two protocols that were designed for different assumptions about who reports errors.

A tunnel dies with its session; an exit that a profile owns keeps its address across restarts.

Download RoxyBrowser

Each profile holds its own static endpoint with its own authentication, so a closed terminal cannot take the route away and no second machine needs the SSH command.

Frequently Asked Questions

Does the SOCKS port from ssh -D need a password from the client?

No. The listener selected the no-authentication method in every case where it was offered and replied 05 00. When a client offered only username and password, the socket was closed with zero bytes rather than answered with 05 ff, so there is no method-negotiation error to read.

Why is nothing listening on the port before I log in?

Because the port is created by the authenticated session, not by the command. With authentication refused the client exited on Permission denied and netstat showed no listening socket, while a successful session held 127.0.0.1:1080 for as long as it lived and released it when it ended.

Does ssh -D resolve names on the client or on the server?

On the server, always. The forwarding requests that arrived at the far end carried the hostname as a string, and an IPv4 target arrived as the text 93.184.215.14 rather than a packed address, so the local resolver is never consulted for a proxied request.

Why does a site fail with an empty reply instead of a SOCKS error?

Because a failed channel open has no SOCKS equivalent in this implementation. A refused target closed the client socket after 2.1 seconds with zero bytes and an unreachable one after 4.0 seconds with zero bytes, so clients report an empty response rather than a reply code such as 05 05.