"Censorship middleboxes are stateful systems constrained by memory. They cannot afford to buffer millions of out-of-order packets indefinitely. By desynchronizing packet order and segmenting protocol boundaries, we force the censor to drop inspection or break the internet."
Ayoub Zulfiqar, Offensive Middlebox Evasion & Packet Mechanics
What is Butterfly?
Butterfly is an enterprise-grade cross-platform network security and anti-censorship suite engineered in Flutter and Dart to defeat Deep Packet Inspection (DPI) and DNS tampering across Linux, Windows, and Android using zapret2 packet desynchronization, driverless TLS fragmentation, and curated encrypted DNS resolvers.
How Deep Packet Inspection Works
When an encrypted HTTPS connection begins, the client transmits a ClientHello message in plaintext. Within this packet lies the Server Name Indication (SNI) extension, revealing the target domain (e.g., target-site.com).
DPI middleboxes passively monitor network transit pipes. The moment they match a restricted domain in the SNI field, they synthesize and inject a spoofed TCP RST (Reset) packet toward the client and destination server, terminating the connection before TLS handshake negotiation completes.
┌──────────────┐ TLS ClientHello (SNI: target-site.com) ┌───────────────────┐
│ Client App │ ──────────────────────────────────────────────────────▶ │ Destination Host │
└──────────────┘ └───────────────────┘
▲
│ [Passively Intercepts]
┌───────────────────────┐
│ ISP / State DPI │
│ Middlebox Inspection │
└──────────┬────────────┘
│ Injects Spoofed TCP RST!
▼
[Connection Terminated]
Strategy 1: zapret2 Packet Desynchronization (Kernel Mode)
Butterfly integrates the battle-tested zapret2 engine to desynchronize the DPI middlebox's TCP state machine:
- TCP slicing (
z-split) divides the initial handshake and payload into tiny segments, breaking the SNI token across packet boundaries. - Out-of-order delivery (
z-disorder) emits subsequent payload segments before initial segments, forcing standard RFC 793 reassembly on destinations while exhausting inspection state in middleboxes. - Fake TTL spoofing (
z-fake-ttl) injects synthetic packets with calibrated Time-To-Live limits that expire immediately after crossing the middlebox, resetting inspection filters before genuine traffic arrives.
Strategy 2: Driverless Userspace TLS Fragmentation (Rootless Mode)
Kernel packet drivers like WinDivert or nftables require elevated root or administrative privileges, which are unavailable in restricted corporate environments or standard Android systems.
To solve this, Butterfly implements a driverless userspace HTTP CONNECT proxy written in pure Dart that runs locally on 127.0.0.1:8085:
// Pure-Dart TLS ClientHello fragmentation across SNI boundary
void fragmentClientHello(Socket clientSocket, Socket serverSocket, Uint8List clientHello) {
int sniOffset = findSniExtensionOffset(clientHello);
// Split the ClientHello into two distinct TCP segments
Uint8List part1 = clientHello.sublist(0, sniOffset + 1);
Uint8List part2 = clientHello.sublist(sniOffset + 1);
// Transmit part 1 and flush the TCP buffer
serverSocket.add(part1);
serverSocket.flush().then((_) {
// Brief microsecond delay forces middlebox packet boundary processing
Future.delayed(const Duration(milliseconds: 1), () {
serverSocket.add(part2);
serverSocket.flush();
});
});
}
The Persistent DNS Safety Net
A common failure mode of desktop network tools is leaving network adapters configured with dead DNS IPs if the software crashes. Butterfly eliminates this with an atomic pre-flight state machine:
- Before mutating any adapter settings via
resolvectl,nmcli, ornetsh, Butterfly writes a snapshot of original settings tostate.json. - On process shutdown, the settings are restored cleanly.
- If the system experiences a hard crash or kernel panic, Butterfly's startup supervisor detects the orphaned
state.jsonand immediately restores original adapter configurations before launching the UI.
Censorship Circumvention Feature Matrix
| Circumvention Technique | Standard Encrypted DNS (DoH/DoT) | Traditional VPN | Butterfly Suite |
|---|---|---|---|
| DNS Poisoning Defense | Protected | Protected | Protected (28+ curated resolvers + clean-IP scan) |
| Plaintext SNI Filtering | Blocked (No protection) | Bypassed (High latency) | Bypassed (Zero latency overhead via zapret2 & TLS frag) |
| Root / Kernel Requirement | None | Requires TUN Driver | Flexible: Kernel mode with fail-open or Rootless Userspace mode |
| Crash Protection | None | Often breaks DNS on crash | Guaranteed via persistent state.json safety net |
Frequently Asked Questions
What is Butterfly and how does it bypass Deep Packet Inspection (DPI)?▼
Butterfly is an enterprise cross-platform network security suite built in Flutter that circumvents DPI using zapret2 packet desynchronization (TCP segment slicing, out-of-order delivery, fake TTL injection) and pure-Dart driverless TLS ClientHello fragmentation.
How does driverless TLS ClientHello fragmentation work without root or kernel drivers?▼
Butterfly operates a userspace HTTP CONNECT proxy on 127.0.0.1:8085 that inspects the TLS handshake and slices the ClientHello packet directly across the Server Name Indication (SNI) extension boundary, confusing middlebox filters without kernel modification.