mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-25 17:30:56 +08:00
5.6 KiB
5.6 KiB
Opt-in SOCKS5 UDP ASSOCIATE & Raw UDP Recording (P4.1c)
ARTEX extends the opt-in SOCKS5 inbound listener with RFC 1928 UDP ASSOCIATE (0x03), IPv4 first, enforcing per-datagram destination policy and recording forwarded datagrams separately from HTTP traffic in SQLite. Transparent UDP (IP_RECVORIGDSTADDR) is out of scope here and planned separately (C2).
Opt-in Configuration (Off by Default)
| Environment Variable | Default | Behavior |
|---|---|---|
ARTEX_SOCKS5_UDP_ENABLED |
unset (off) | Set to 1 / true / on / yes to enable RFC 1928 UDP ASSOCIATE on the SOCKS5 listener (starting the SOCKS5 listener on ARTEX_SOCKS5_ADDR or 127.0.0.1:1080 unless ARTEX_SOCKS5_ENABLED is explicitly 0/false/off/no). |
ARTEX_SOCKS5_ENABLED |
unset (off) | Explicit 0 / false / off / no disables the entire SOCKS5 listener (TCP and UDP) even if ARTEX_SOCKS5_UDP_ENABLED is set. |
ARTEX_SOCKS5_ADDR |
127.0.0.1:1080 |
Bind address for the SOCKS5 TCP control listener; per-association IPv4 UDP relay sockets bind on the same local IPv4 interface on an ephemeral port (:0). |
- Flag off means no listener:
- With all SOCKS5 flags unset/off, no SOCKS5 listener and no UDP relay socket are started.
- With SOCKS5 TCP enabled and
ARTEX_SOCKS5_UDP_ENABLEDoff,UDP ASSOCIATE(0x03) is refused with RFC 1928 reply0x07(Command not supported) and no UDP socket is opened.
- Requires traffic recorder: like P4.1a and P4.1b, the server only starts the SOCKS5 listener when the traffic recorder is enabled (inside the traffic proxy block in
server/manager.go). - Non-loopback warning: the same authentication caveat from docs/traffic-socks5.md applies—RFC 1929 username/password accepts any credentials, so keep the listener bound to loopback (
127.0.0.1) or restrict access at the host firewall.
Protocol Scope & Lifetime
- IPv4 first:
UDP ASSOCIATEaccepts IPv4 (0x01) and domain (0x03) requests (including0.0.0.0:0per RFC 1928 §4). IPv6 (0x04)UDP ASSOCIATErequests return0x08(Address type not supported); IPv6 UDP datagram destinations are dropped.- Each client UDP datagram header (
RSV=0x0000,FRAG=0x00,ATYP=0x01IPv4 orATYP=0x03domain resolved to IPv4) is parsed individually.
- No fragmentation reassembly:
- Per RFC 1928 §7, datagrams with
FRAG != 0are dropped without reassembly. - Each forwarded
FRAG == 0datagram (and each upstream reply datagram) is recorded as it arrives without cross-datagram reassembly.
- Per RFC 1928 §7, datagrams with
- Client source pinning:
- Incoming client UDP datagrams on the ephemeral relay port are accepted only from the expected IPv4 client address (the
DST.ADDR/DST.PORTgiven inUDP ASSOCIATE, or the TCP control connection's peer IP pinned on the first valid datagram). - Upstream reply datagrams are accepted only from destinations (
ip:port) to which the association previously forwarded an allowed datagram.
- Incoming client UDP datagrams on the ephemeral relay port are accepted only from the expected IPv4 client address (the
- Tied to the TCP control connection:
- Closing the SOCKS5 TCP control connection immediately closes both UDP sockets and terminates the association.
- Exceeding
UDPIdleTimeout,UDPMaxDatagrams, orUDPMaxBytes, or callingTraffic.Close(), also closes the association and its TCP control connection cleanly.
Policy Enforcement Per Datagram Destination
Before forwarding every client-to-server UDP datagram to (host, port):
- Target gate (
intercept.Interceptor.ResolveUDP4/intercept.PinnedUDP4Resolver): enforces global asset block rules (domain, IP, and CIDR, before and after fresh IPv4 DNS resolution) and any enabledintercept.TargetScopepins/exemptions, returning the verified IPv4*net.UDPAddr. - Egress governor (
egress.Do(egress.Current(), ...)): enforces the active noise profile (PaceTimeout, default30s) before sending. - Fail-closed drop (no silent passthrough): any datagram whose destination is denied by the target gate, fails DNS/IPv4 resolution, or is refused by the egress governor is dropped without sending bytes upstream and without recording a forwarded datagram. Subsequent allowed datagrams on the same association continue normally.
Raw UDP Storage (SQLite)
Each forwarded datagram writes one row to the raw_udp_datagrams table in the SQLite traffic index (traffic/traffic.go, indexSchema — no PostgreSQL migration):
- Columns:
id(udp-<ms>-<seq>),association_id(udpa-<ms>-<seq>),protocol('udp'),host,port,direction('c2s'|'s2c'),ts(unix milliseconds),size,preview,blob. - No HTTP exchange row: raw UDP datagrams never insert into
exchanges. - Preview & atomic blob spilling:
- Payloads up to
UDPPreviewBytes(default8 KiB) stay inline inpreview. - Payloads above
UDPPreviewByteskeep the leadingUDPPreviewBytesinline and spill the full datagram payload atomically (temp file + rename) into_blobs/sha256/with a reference registered inblob_refsunder the datagram'sudp-*ID.
- Payloads up to
Operational Bounds
| Parameter | Default |
|---|---|
MaxConcurrent |
64 active TCP streams + UDP associations combined |
UDPMaxDatagrams |
1000 forwarded datagrams (c2s + s2c) per association |
UDPMaxBytes |
4 MiB forwarded payload bytes (c2s + s2c) per association |
UDPPreviewBytes |
8 KiB inline preview per datagram before blob spill |
UDPIdleTimeout |
2m inactivity timeout per association |
HandshakeTimeout |
10s for greeting, auth, and UDP ASSOCIATE request |
DialTimeout |
30s per-datagram target gate / DNS lookup bound |
PaceTimeout |
30s per-datagram egress governor wait bound |