Shadowsocks: What AEAD Hides and What It Leaks

Shadowsocks and SOCKS5 share an address grammar and nothing else. We re-implemented the published AEAD wire format and encrypted 550 target headers across four ciphers to find out what the encryption conceals, what it leaves in the open, and where a plain SOCKS5 endpoint is still the simpler tool.

Every stream was sealed with a fresh random salt, decrypted back to prove the header survived, and sized from the outside. The run covered seven target shapes, from a bare IPv4 address to a 253-character domain, under aes-128-gcm, aes-192-gcm, aes-256-gcm and chacha20-ietf-poly1305.

550AEAD encryptions measured
200 / 200salts unique across draws
73 Bfirst packet for any IPv4 target
1 stotal run time

Encryption hides the destination string, not the destination's shape: packet size alone separates address types.

measured

1. The same address grammar, a different envelope

A SOCKS5 client opens a socket, sends a greeting, agrees on a method, then hands the server a target written as one address-type byte followed by the address and a two-byte port. A Shadowsocks client does none of that. There is no greeting and no method list, because the password itself is the method: both sides derive keys from it and start encrypting immediately. The target travels inside the first encrypted chunk, and it uses the identical SOCKS5 byte layout.

SOCKS5 address-type markers reused inside the Shadowsocks target header, with header sizes including the port.
Address typeMarkerAddress fieldHeader size
IPv40x014 bytes7 bytes with port
Domain name0x031 length byte plus the name4 bytes plus name length
IPv60x0416 bytes19 bytes with port

Earlier pages in this series measured that grammar from the outside. The Chrome wire capture found every CONNECT target arriving as a readable domain string, and the SSH forwarding test saw hostnames cross the channel as plain text. Shadowsocks takes the same bytes and puts them behind an authenticated-encryption layer, so the question worth measuring is how much that layer actually conceals.

2. The wire, measured

On the TCP path each chunk is written as an encrypted two-byte payload length with a 16-byte tag, followed by the encrypted payload with its own tag, and the stream opens with a random salt from which both sides derive the session key. A middle observer therefore sees a salt, an opaque 18-byte length block, and a body whose size is visible even though its content is not. We encrypted seven target shapes fifty times each under aes-256-gcm with fresh salts; the full run finished inside one second, 06:12:12Z on 29 October 2026, and every decryption restored the exact original header bytes.

First-packet wire totals for seven target shapes under aes-256-gcm, each measured across fifty fresh salts.
TargetTypeHeaderFirst packet
1.2.3.4:443IPv47 B73 B, every run
example.comDomain15 B81 B, every run
www.google.comDomain18 B84 B, every run
i.ytimg.com.gstatic.comDomain27 B93 B, every run
63-char labelDomain71 B137 B, every run
253-char domainDomain254 B320 B, every run
[IPv6]:443IPv619 B85 B, every run

Each row is a fixed number. Encryption randomizes the content but not the size, and the size is a function of the address the user typed. Without holding the password, an observer who logs only packet totals can separate an IPv4 target from an IPv6 one from any domain of a given length: the 32-byte salt and 34 bytes of framing put every address type in a non-overlapping band.

3. What the password does, and what a reused salt does

The password is stretched once into a master key, and each stream mixes it with the salt through an HKDF step labelled for the protocol to produce a session subkey. We derived 50 subkeys from 50 distinct salts and got 50 distinct values, then confirmed the other side: the same salt always reproduces the same subkey. That determinism is why salt handling is a security rule rather than a style choice. Encrypting the same target header twice with the same salt produced byte-identical ciphertext, both copies hashing to 94c3f7b3ef8deeae, while shifting the nonce by one position changed the encrypted length block entirely, from be3ddba674dc2a1e to 7d3d7bccc2de3f0b.

The practical reading is symmetrical. A client that picks salts honestly, as ours did across 200 draws with zero collisions, makes every stream a fresh key. A client that reuses a salt hands any recorder a replay: the identical bytes can be re-sent to the server and will decrypt into a valid-looking header. This is why real Shadowsocks servers track every salt they have accepted and refuse repeats, and why replay protection was the headline change in the protocol's newer editions.

4. The cipher choice moves the frame

Four ciphers are in common use, and the measurement shows their fingerprint is the salt length. The same example.com header landed as a 65-byte first packet on aes-128-gcm, 73 bytes on aes-192-gcm, and 81 bytes on both aes-256-gcm and chacha20-ietf-poly1305, whose salt and key sizes are identical at 32 bytes each. Nothing else in the frame varies, so an observer can often name the cipher from the first packet alone, before any content is read.

First-packet size for the same example.com header under four common Shadowsocks AEAD ciphers.
CipherKeySaltFirst packet
aes-128-gcm16 B16 B65 B
aes-192-gcm24 B24 B73 B
aes-256-gcm32 B32 B81 B
chacha20-ietf-poly130532 B32 B81 B

The UDP path is tighter still. Each datagram carries its own salt plus the target header plus the payload under one tag, with no length block in between. The same four targets measured 65, 73, 76 and 85 bytes, so on datagram traffic the address class is exposed in every single packet rather than only the first. Applications that send small recurring probes are therefore the easiest to fingerprint by size, whatever they encrypt.

5. What an observer can and cannot do with this

Stating the limits plainly: this was a computation-only experiment against a fixed test password, with no Shadowsocks server and no real client in the loop, and the numbers are properties of the wire format rather than of any particular implementation. Within those bounds the findings are exact. The address bytes are unrecoverable without the password, and decryption restored all seven original headers perfectly. But packet sizes are not encrypted anywhere in the design, so traffic analysis by length class works against every deployment equally. Padding exists in the protocol's newer editions precisely because of this, at the cost of extra bytes on every chunk.

There is also a lighter alternative worth naming. If the threat model does not include a censor reading the stream, a plain SOCKS5 endpoint does the same job with none of this machinery: the trade-off measured across our pool pages is that its headers are readable, its methods are negotiable, and roughly one socket in four on a public list answers at all. Shadowsocks is the choice when the connection itself is being watched; an ordinary SOCKS5 proxy is the choice when only reliability matters.

Need a list you can point any client at?

Download RoxyBrowser

Each profile keeps its own cookie jar and proxy, so an encrypted tunnel and a clean identity are separate decisions.

Frequently Asked Questions

Is Shadowsocks the same protocol as SOCKS5?

It reuses the same address grammar but not the same wire. A Shadowsocks target header is byte-for-byte the SOCKS5 form: one address-type byte, the address, and a two-byte port. What changes is the envelope. There is no greeting, no method negotiation and no reply codes; the header travels encrypted inside the first authenticated chunk instead of in plaintext on the socket.

Can an observer tell what a Shadowsocks connection connects to?

The address itself stays encrypted, but the frame does not. In this measurement the first packet was a fixed size per target class: 73 bytes for an IPv4 target, 81 for example.com, 85 for an IPv6 address and 320 for a maximum-length domain, all under aes-256-gcm. Size alone separates address types without reading any plaintext.

Why do Shadowsocks servers reject a reused salt?

Because the same salt reproduces the same session key. Two streams encrypted with the same salt, password and target produced byte-identical ciphertext in this run, with matching digests. A recording client can replay that stream verbatim, so servers track seen salts and drop the ones they have already accepted.

Does the cipher choice change what leaks?

It changes the frame sizes, not the leak. The same example.com header measured 65 bytes on aes-128-gcm, 73 on aes-192-gcm, and 81 on both aes-256-gcm and chacha20-ietf-poly1305, because only the salt length differs across the 256-bit pair. Every cipher kept the length class readable from the outside.