SOCKS4/5 Proxy Encoder Null Byte and Credential Injection
Description
Security Vulnerability Report: SOCKS4/5 Proxy Encoder Null Byte and Credential Injection in Netty
1. Vulnerability Summary
| Field | Value |
|---|---|
| Product | Netty |
| Version | 4.2.12.Final (and all prior versions with codec-socks) |
| Component | io.netty.handler.codec.socksx.v4.Socks4ClientEncoder / io.netty.handler.codec.socksx.v5.Socks5ClientEncoder |
| Vulnerability Type | CWE-626: Null Byte Interaction Error / CWE-20: Improper Input Validation |
| Impact | Domain Spoofing / SOCKS4 UserId Truncation / Authentication Data Injection |
| CVSS 3.1 Score | 7.5 (High) |
| CVSS 3.1 Vector | CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N |
2. Affected Components
SOCKS5:
Socks5ClientEncoder— domain address field accepts null bytesSocks5ClientEncoder— password auth request accepts null bytes and CRLF in username/password
SOCKS4:
Socks4ClientEncoder— userid field accepts embedded null bytes (creates ambiguous null-terminated string)Socks4ClientEncoder— SOCKS4a domain field accepts embedded null bytes (domain truncation)
3. Vulnerability Description
3.1 SOCKS5 Domain Null Byte Injection
SOCKS5 domain addresses are encoded as 1-byte length + domain string. Null bytes within the domain string are accepted without validation:
Encoded: [05 01 00 03] [11] evil\0.example.com [01 BB]
↑len=17 ↑null byte in domainDifferent SOCKS5 proxy implementations handle embedded null bytes differently:
- Some truncate at null → connect to
evilinstead ofevil\0.example.com - Some process the full string → connect to the intended host
- This differential behavior enables domain spoofing
3.2 SOCKS5 Auth Credential Injection
SOCKS5 password authentication (RFC 1929) uses 1-byte length + string for username and password. Null bytes and CRLF characters are accepted:
Encoded: [01] [0B] admin\0root [10] pass\r\ninjected
↑len ↑null ↑len ↑CRLFIf the SOCKS5 proxy uses null-terminated string processing, the username becomes admin (truncated), and the password may be similarly truncated or misinterpreted.
3.3 SOCKS4 UserId Null Byte Truncation
SOCKS4 uses null-terminated strings for userid. An embedded null byte creates two null bytes in the packet — the embedded one and the protocol terminator. This makes the packet structurally ambiguous:
Standard: [header 8 bytes] [userid] [00]
Injected: [header 8 bytes] [admin] [00] [injected-userid] [00]
↑ proxy stops here ↑ trailing dataThe trailing data after the first null byte may be interpreted as:
- Start of SOCKS4a domain (if IP is 0.0.0.x)
- Garbage data (protocol confusion)
3.4 SOCKS4a Domain Null Byte Truncation
SOCKS4a appends a null-terminated domain after the userid. An embedded null creates the same ambiguity:
Standard: [header] [userid\0] [domain\0]
Injected: [header] [user\0] [evil\0.example.com\0]
↑ proxy connects to "evil"5. Impact Analysis
| Impact Category | Description |
|---|---|
| Domain Spoofing | Null byte truncation connects to evil instead of evil.example.com |
| Auth Bypass | Null byte in username truncates to shorter name, potentially matching a different account |
| Protocol Confusion | Extra null bytes in SOCKS4 packets create ambiguous protocol framing |
| SSRF | Combined with domain spoofing, can redirect proxy connections to internal hosts |