Skip to content

Finalmask fragment: Add disorder and disoob modes - #7469

Closed
aaaaxcept wants to merge 1 commit into
XTLS:mainfrom
aaaaxcept:feat/fragment-disorder
Closed

aaaaxcept wants to merge 1 commit into
XTLS:mainfrom
aaaaxcept:feat/fragment-disorder

Conversation

@aaaaxcept

Copy link
Copy Markdown

Motivation

Russian TSPU has evolved from simple SNI-based blocking to analyzing TCP-level handshake patterns, including shaping and dropping connections based on ClientHello analysis (#5332, #6293). Plain fragmentation alone no longer suffices.

What TSPU does now

The inspector no longer just reads the first ClientHello record in isolation. It reassembles the client hello from multiple TCP fragments, so merely cutting the hello into pieces with delays (the current fragment behavior) is not enough: the censor waits for the neighboring segments, collects them into a complete picture, and still sees the SNI. Reports from the issues:

  • TCP + Reality gets blocked #5332 "TCP + Reality gets blocked" (148 comments, RPRX participated): "russian censor blocking strategy has evolved significantly... now they've learned to detect anomalies in tcp connection patterns even when the tls handshake completes successfully". The problem lives at the packet/flow level, not just at SNI level.
  • Russia blocks 2026 #6293 "Russia blocks 2026": users report that nothing else helped - fragmentation, mux, SNI change, even the host - i.e. the existing fragment mask alone is no longer sufficient against current TSPU behavior. Also noted: Roskomnadzor has been matching known TLS fingerprint lists, so plain fragment needs a next-level countermeasure.
  • RPRX closing TCP + Reality gets blocked #5332 with a promise to keep finding ways around censorship ("as long as the network is not completely cut off, we will find a way out") - this feature is exactly in line with the project's stated goals.
  • The sqsvp comment in Russia blocks 2026 #6293 observes that TSPU sits in front of the NAT, which is precisely the hop the disorder trick exploits (see below).

Prior art: byedpi (hufrea/byedpi) --disorder / --disoob modes, zapret and GoodbyeDPI, all of which converged on the same class of TCP-level tricks against the Russian censor. Only the concept is reused here, no code.

How disorder defeats reassembly

The ClientHello is split into segments. Segments with odd index are sent with TTL=1:

  • They die on the first router hop, which is at or before the TSPU box. The DPI does see them, but they never reach the server.
  • The server is missing those bytes, so TCP retransmits them via RTO - already with the restored default TTL, and they arrive.
  • The censor sees a garbled sequence: half the hello right away, holes, then slow retransmissions. By the time it can reassemble anything reliably, the classification window has passed. Blocking has nothing to latch onto.

disoob additionally sends the first segment's boundary byte as TCP urgent data (MSG_OOB) with a fake marker value; the real byte follows in the normal stream. DPI implementations that mishandle urgent data choke on it, while ordinary receivers skip the urgent byte and see the byte-exact stream.

This extends the existing finalmask fragment mask with a mode field: normal (default, current behavior byte-for-byte compatible), disorder, disoob. No new config knobs: TTL is fixed at 1, the urgent marker is fixed. Extending finalmask masks incrementally matches the maintainer's stated intent.

Changes

  • transport/internet/finalmask/fragment/config.proto: enum Mode { NORMAL, DISORDER, DISOOB }, field mode = 13; config.pb.go regenerated with go run ./infra/vprotogen (-mode check passes).
  • transport/internet/finalmask/fragment/conn.go: Write() refactored into split (splitClientHello/splitRaw) + send (writeSegments) phases, so segments can be flagged before any byte goes out. markDisorder flags odd-index segments. Dying segments follow the order setTTL(1) -> write -> sleep -> setTTL(def): the write returns when the data reached the kernel send buffer, not the wire, so restoring the TTL before a hold time could silently win the race and send the doomed segment unharmed. The configured delay doubles as the hold time; with all-zero delays a 10 ms grace hold is applied (a config warning points this out). DISOOB sends data[:pos] with a fake byte at pos via MSG_OOB, then the real byte in the plain stream (byedpi send_oob() semantics). TCP_NODELAY is enabled for non-normal modes so the small writes actually leave as separate segments. Splice() returns false for non-normal modes so the splice fast path cannot bypass the masking.
  • disorder_unix.go / disorder_windows.go / disorder_other.go (new, build-tagged): TTL via IP_TTL / IPV6_UNICAST_HOPS (picked by remote address family) on unix-like, WSASend with MSG_OOB on Windows, explicit not-supported error on plan9/js (fail loudly, no silent degradation).
  • infra/conf/transport_finalmask.go: mode JSON field with case-insensitive parsing, unknown values rejected with a clear error, default stays normal.
  • Tests: fragment/conn_test.go (7 tests / 84 subtests over real loopback TCP, byte-exact stream integrity in all modes, split-count proof, server-side semantics, 64-combination sweep of hello sizes x split lengths x modes) and infra/conf/transport_finalmask_fragment_test.go (JSON path via StreamConfig, ToMemoryStreamConfig runtime init for every mode, invalid-mode errors).

Verification

  • go test ./transport/... ./infra/conf/... clean; go vet, go run ./infra/vprotogen -mode check, go run ./infra/vformat clean on the touched files.
  • Cross-compilation builds: linux, darwin, freebsd, windows, android, ios.
  • Verified on real wire (Linux VPS, tcpdump on egress iface, TLS to 1.1.1.1:443 through freedom outbound with fragment mode=disorder / mode=disoob):
    • disorder: ClientHello segments alternate ttl 1 / ttl 64; server ACKs show SACK holes (e.g. sack 1 {13:19} after the killed seq 7:13 segment); the missing segments are RTO-retransmitted with the restored default TTL and the handshake completes.
    • disoob: first ClientHello segment goes out with URG set (Flags [P.U], urg 7 at the split boundary) plus the same ttl=1 alternation; stream reassembles correctly.
    • go test -race clean on the fragment package.

Limitations (by design)

  • Disordered/urgent tricks are powerless against a DPI with full stream reassembly that tolerates holes and RTO retransmissions. The target is TSPU-class inspectors, against which byedpi --disorder/--disoob currently work in Russia. The retransmission adds roughly 200 ms-1 s to the first handshake only.
  • The fake urgent byte is only seen by DPI parsers that inline urgent data; well-behaved receivers never observe it.

@Fangliding

Copy link
Copy Markdown
Member

dup #6103

@Fangliding Fangliding closed this Nov 22, 2026
@aaaaxcept

Copy link
Copy Markdown
Author

Hi @Fangliding, thanks for taking a look. I'd like to respectfully clarify why I believe this is not a duplicate of #6103:

  • TLS : tls spoofing #6103 (TLS spoofing) is a fake-packet technique: it injects a forged ClientHello with a decoy SNI ahead of the real one plus TCP header manipulation - the byedpi --fake / zapret fake class.
  • This PR is a different mechanism: the real ClientHello is split into segments, odd ones are sent with TTL=1 (they die on the first hop; the server recovers them via RTO retransmissions), optionally with TCP urgent data at the split boundary - the byedpi --disorder / --disoob class. There are no fake packets and no decoy SNI; what breaks is the inspector's reassembly of the real ClientHello.

The two techniques are complementary rather than duplicating - which is exactly why byedpi ships them as separate modes (--fake vs --disorder/--disoob): they solve different subtasks and are detected differently by DPI.

Also worth noting: #6103 has been a draft since May, currently has merge conflicts, and hasn't been reviewed yet, while this PR is ready for review and includes real-wire verification (tcpdump: ttl 1/64 alternation, SACK holes on server ACKs, URG flag at the split boundary).

Could you please reconsider - happy to answer any technical questions. If the concern is overlapping scope, I can split this into a feature issue for discussion instead.

@Fangliding

Copy link
Copy Markdown
Member

To be honest, I'm tired of seeing these such tricks, which are nothing more than working for a few months and then the firewall inventing a new reassembler. Perhaps it will consume more taxpayers' money to compensate for the decreased efficiency

@aaaaxcept

Copy link
Copy Markdown
Author

Thanks for the honest feedback - I understand the core team's position on arms-race tricks.

One point for the record: this runs opt-in via a config field, adds zero maintenance surface when unused, and users currently run a separate byedpi process alongside Xray precisely for these modes - in-core would apply the trick only to the ClientHello and drop the second tool.

That said, the call is yours; if the direction for the core is protocol-level solutions only, I respect that. The branch (aaaaxcept:feat/fragment-disorder) stays up for anyone who wants it as a patch. Thanks for reviewing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants