How bol-van/zapret2 works
1. Core purpose and shape
This repository is an autonomous anti-DPI toolkit called zapret2. Its center is a packet-processing engine that intercepts traffic from the OS, inspects packet dissections, and applies obfuscation/desynchronization strategies before forwarding, dropping, or splitting traffic.
2. Two main runtime engines
There are two primary executables/engines: nfq2/nfqws for Linux/BSD-style packet interception through kernel queues/firewall hooks, and a Windows variant built around WinDivert (nfq2/win.c, nfq2/windows/windivert/*). Both share the same strategy model, but the interception boundary differs by OS.
3. Packet interception boundary
Traffic enters the system from OS-level plumbing, not from a proxy layer. On Linux/OpenWrt the repo uses nftables/iptables-style NFQUEUE redirection and conntrack-aware filters; on Windows it uses WinDivert filters such as --wf-tcp-out, --wf-udp-in, and raw filter expressions. This interception layer is meant to keep most packets in the kernel and only hand relevant flows to user space.
4. Engine pipeline in nfq2
The C engine receives packets, classifies them by L7 protocol and payload type, maintains flow state, and builds a structured “dissect” representation. That representation is then passed through one or more Lua desync instances. The engine decides whether to pass, modify, send fragmented variants, or drop the original packet.
5. Lua strategy layer as the main behavior boundary
The major architectural split is between the C packet engine and the Lua strategy library. lua/zapret-lib.lua, lua/zapret-antidpi.lua, lua/zapret-obfs.lua, and related scripts contain the higher-level anti-DPI tactics, payload generation, and helper functions. The C side provides packet parsing, state tracking, blobs, and sending primitives; Lua expresses strategy logic.
6. Strategy composition model
Instead of hard-coded “modes”, zapret2 uses chained --lua-desync instances inside profiles. Each instance can modify the current dissect, cut itself off after it is no longer useful, and contribute a verdict. Profiles are filtered by protocol, payload type, hostlist membership, and in/out range. This makes the strategy system the core architectural unit rather than a single monolithic firewall rule.
7. Data inputs for obfuscation
The repo ships many binary payload templates in files/fake/* for TLS, HTTP, QUIC, WireGuard, STUN, Discord media discovery, and other protocol signatures. These are loaded as Lua blobs or referenced directly by strategy code. This asset layer is essential because the engine relies on realistic fake packets rather than abstract transforms only.
8. Hostlist and ipset integration
The ipset/ directory contains scripts for downloading, building, and maintaining domain/IP lists used for selective targeting or exclusion. These lists feed the engine’s filtering stage so strategies can be applied only to chosen destinations or classes of traffic. This is one of the main policy/data boundaries in the system.
9. OS/service integration and startup
The init.d/ tree contains service definitions for OpenWrt, OpenRC, systemd, sysvinit, runit, s6, pfSense, and Windows bundle examples. These are not just installers; they define how the packet engine is brought up, how filters are installed, and how list-update timers/services run. The repo is therefore both an engine and a deployment bundle.
10. Build and packaging architecture
Makefile, install_*.sh, docs/compile/*, and the OpenWrt packaging subtree show that the project is built for multiple targets: Linux, embedded OpenWrt, and Windows. There is also some platform-specific support code in nfq2/andr/ and nfq2/windows/, indicating cross-compilation and adapter layers rather than a single native target.
11. Protocol handling and support libraries
Inside nfq2/ the code is split into protocol parsing, conntrack, packet queues, filtering, timers, helpers, hostlists, ipset handling, gzip, crypto, and randomization. The crypto subdirectory suggests TLS/QUIC-related manipulation support, while protocol.c, desync.c, and filter.c likely form the core packet decision path.
12. External integration points
The repo does not depend on external DPI services. Its only important external dependencies are OS packet filtering frameworks, WinDivert on Windows, and standard toolchains/libraries for building. That makes the architecture self-contained and primarily edge-deployed.
13. Operational flow to diagram
A useful diagram would show: OS traffic → firewall/divert filter → engine queue → protocol/payload classification → Lua strategy chain → modified packets sent back to network stack. Side inputs feeding that flow are hostlists/ipsets, blobs/fake payload files, and init/service configuration.
14. What is intentionally not centralized
There is no single “configuration server” or “policy backend.” Strategy behavior is distributed across Lua scripts, lists, service wrappers, and OS-specific filter definitions. That decentralization is central to the repo’s architecture and is what makes it portable across Linux, embedded routers, BSD, and Windows.
Main entry points: protocol.c Packet core · win.c win entry · nfqws.c nfqws · Makefile Build system
Components 19
Runtime engines
OS-specific packet interception and packet-processing executables.
- nfqws · Linux/BSD-style engine that receives queued packets, classifies flows, and applies desync actions.
nfq2/nfqws.c - win entry · Windows-side entrypoint that bridges the shared engine model to WinDivert.
nfq2/win.c - WinDivert · Windows packet interception backend and filter integration.
nfq2/windows/windivert/windivert.h - Packet core · Shared packet-processing internals: queueing, protocol detection, state tracking, and send/drop decisions.
nfq2/protocol.c - Desync · Core decision point that applies obfuscation, fragmentation, and verdict selection.
nfq2/desync.c - Flow filter · Filters flows by protocol, host, payload type, and other profile constraints.
nfq2/filter.c
Strategy layer
Lua-driven anti-DPI behavior and packet obfuscation tactics.
- Lua bridge · Embeds Lua and passes dissected flow state between C packet logic and strategy scripts.
nfq2/lua.c - Lua lib · Shared Lua helpers and blob handling used by strategies.
lua/zapret-lib.lua - Anti-DPI · Main anti-DPI strategy scripts that compose desync instances and payload transforms.
lua/zapret-antidpi.lua - Obfs · Obfuscation-oriented Lua tactics and payload generation helpers.
lua/zapret-obfs.lua
Policy inputs
Hostlists, ipsets, and flow-selection data used to target traffic.
- Hostlists · Domain and IP lists used for inclusion, exclusion, and selective targeting.
ipset - List scripts · Scripts that fetch, build, and refresh ipset and domain lists.
ipset/get_antizapret_domains.sh
Payload assets
Binary templates used to impersonate realistic protocol traffic.
- Fake packets · Protocol-shaped binary blobs for TLS, QUIC, WireGuard, HTTP, STUN, and other signatures.
files/fake
Deployment
Service wrappers, init scripts, and platform packaging.
- OpenWrt init · OpenWrt firewall hooks and startup scripts for installing filters and launching the engine.
init.d/openwrt/zapret2 - systemd units · systemd service and timer units for the engine and list updates.
init.d/systemd/zapret2.service - Windows filters · Windows filter examples and bundle guidance for WinDivert-based deployment.
init.d/windivert.filter.examples
Tooling
Build, compile, and diagnostic support utilities.
- Build system · Top-level build orchestration for native, embedded, and Windows targets.
Makefile - Compile docs · Platform-specific build instructions and cross-compilation notes.
docs/compile/build_howto_windows.txt - Blockcheck · Scripted traffic tests and protocol probes used to validate DPI behavior.
blockcheck2.sh
Connections 22
- win entry → WinDivert: captures traffic · Windows entry uses WinDivert to intercept packets before user-space processing.
- nfqws → Packet core: drives core · The main executable drives the shared packet-processing pipeline.
- win entry → Packet core: shares core · Windows entry reuses the same shared packet engine logic.
- Packet core → Flow filter: classifies flows · Packets are matched against protocol and profile filters before strategy execution.
- Packet core → Desync: applies tactics · Dissected packets are handed to desync logic for modification or drop decisions.
- Desync → Lua bridge: invokes lua · C engine passes dissect state into Lua strategy instances.
- Lua bridge → Lua lib: loads helpers · Lua runtime depends on shared helper functions and blob utilities.
- Lua lib → Anti-DPI: supports · Anti-DPI scripts build on common Lua helpers.
- Lua lib → Obfs: supports · Obfuscation scripts reuse shared Lua primitives.
- Anti-DPI → Fake packets: consumes blobs · Strategies reference realistic fake packet templates for protocol impersonation.
- Obfs → Fake packets: consumes blobs · Obfuscation tactics use binary payload templates and signatures.
- Hostlists → Flow filter: selects targets · Host and IP lists constrain which flows receive anti-DPI treatment.
- List scripts → Hostlists: updates lists · Maintenance scripts fetch and build the policy lists used by the engine.
- OpenWrt init → nfqws: starts engine · OpenWrt service scripts launch the packet engine and install firewall hooks.
- systemd units → nfqws: runs service · systemd units supervise the engine runtime.
- systemd units → List scripts: refreshes lists · Timer/service pair updates targeting lists on a schedule.
- Windows filters → win entry: configures filters · Windows deployment examples define divert filter expressions and startup behavior.
- Build system → nfqws: builds · Top-level build orchestration compiles the Linux/BSD engine.
- Build system → win entry: builds · Top-level build orchestration compiles the Windows entry and related objects.
- Build system → Compile docs: documents · Build instructions describe cross-compilation and packaging targets.
- Blockcheck → Packet core: tests engine · Diagnostic scripts exercise packet handling and desync behavior.
- Blockcheck → Anti-DPI: tests tactics · Protocol probes validate the strategy layer against representative traffic.