zapret2 Documentation

repository·master·Indexed 26 days ago

https://github.com/bol-van/zapret2

An autonomous DPI (Deep Packet Inspection) countermeasures tool designed to bypass blocks and protocol throttling of HTTP(S) sites and signature-based analysis of TCP/UDP protocols. Optimized for OpenWrt routers and supporting Linux, FreeBSD, OpenBSD, and Windows, zapret2 utilizes Lua scripting in nfqws2 and winws2 to provide flexible traffic manipulation, protocol obfuscation, and desynchronization strategies without relying on external servers.

Tokens
79.7K
Snippets
124
Records
384
Agent score
89%

What's inside zapret2

  1. Overview of zapret2

    master

    zapret2 is an autonomous DPI (Deep Packet Inspection) countermeasures tool that does not require connection to third-party servers. It is designed to bypass blocks or throttling of HTTP(S) sites and signature-based analysis of TCP and UDP protocols (e.g., for blocking VPNs). It can also be used for partial transparent protocol obfuscation.

    Supported Platforms:

    • Low-power embedded devices (e.g., routers running OpenWrt)
    • Traditional Linux systems
    • FreeBSD
    • OpenBSD
    • Windows

    Note: MacOS is not supported.

  2. Understand the nfqws2 traffic processing pipeline

    master

    The nfqws2 processing pipeline follows these stages:

    1. Interception: Packets are passed from the OS kernel to the nfqws2 user-mode process via interception methods (e.g., Linux netfilter).
    2. Dissection: The packet is parsed into a dissect structure representing OSI layers (IP, IPv6, TCP, UDP, and data fields).
    3. Conntrack: The built-in conntrack subsystem tracks flows (L3/L4 data), monitors direction, packet/byte counts, and TCP sequence numbers. It handles message reassembly and decryption if necessary.
    4. Payload Identification: Signatures identify payload types to determine the flow protocol.
    5. Profile Classification: Profiles containing filters (L3, L4, L6/L7) and actions are scanned in order. The first matching profile is selected and cached in the conntrack entry.
    6. Lua Execution: Actions within a profile are executed as Lua function instances via --lua-desync parameters.
    7. Verdict Aggregation: Each Lua instance returns a verdict (VERDICT_PASS, VERDICT_MODIFY, or VERDICT_DROP). The final verdict is determined by priority: DROP > MODIFY > PASS.
    8. Transmission: The final packet (original or modified) is sent back to the kernel.
  3. Orchestrate automation with zapret-auto.lua

    master
    The zapret-auto.lua library allows you to separate control logic (orchestration) from action logic (antidpi functions). Instead of a simple linear application of instances, you can program complex strategies, such as dynamic strategy switching (e.g., if one strategy fails, try another).
  4. Understand the ipset list management system

    master

    The ipset directory contains shell scripts that manage files with fixed names. These files are categorized into two types:

    1. User lists: Managed manually by the user and not modified by the software. They can contain hostnames, IPv4/IPv6 addresses, or CIDR subnets.
    2. Generated lists: Produced by the software (e.g., via downloading or resolving hostnames). These should not be edited manually as changes may be overwritten.

    Key File Naming Conventions:

    • IPv6 lists: Append 6 before the extension (e.g., zapret-ip-user6.txt).
    • Compressed lists: If GZIP_LISTS is enabled in config, generated lists may have a .gz extension.
    HostlistTypePurposeAssociated IP lists
    zapret-hosts-user.txtUserIncludezapret-ip-user.txt, zapret-ip-user6.txt
    zapret-hosts-user-exclude.txtUserExcludezapret-ip-exclude.txt, zapret-ip-exclude6.txt
    zapret-hosts-user-ipban.txtUserTraffic Redirectionzapret-ip-user-ipban.txt, zapret-ip-user-ipban6.txt
    --GeneratedTraffic Redirectionzapret-ip-ipban.txt, zapret-ip-ipban6.txt
    zapret-hosts.txtGeneratedIncludezapret-ip.txt, zapret-ip6.txt
  5. Key differences between zapret1 and zapret2

    master

    While zapret1 (specifically nfqws1) had attack strategies hardcoded in C, zapret2 (specifically nfqws2) moves the traffic manipulation logic into a Lua scripting language. This allows for greater flexibility and easier development of new DPI bypass strategies.

    Core features retained in zapret2:

    • Protocol recognition
    • Reassembly
    • Decryption
    • Profile management
    • Hostlists and ipsets
    • Basic filtering

    The Lua Integration: nfqws2 provides Lua code with a structured tree representation of incoming packets (dissects), similar to Wireshark. It also provides results from the assembly or decryption of protocols like TLS and QUIC. The C core provides helper functions for sending packets, working with binary data, parsing TLS, and finding marker positions.

  6. Understand the zapret2 project structure

    master

    zapret2 is a packet manipulation project designed to bypass Deep Packet Inspection (DPI) or perform protocol obfuscation. The architecture is split into a C core for interception and a Lua layer for traffic modification logic.

    Core Components

    • nfqws2 (Linux), dvtws2 (BSD), or winws2 (Windows): The primary C-based packet manipulator. It handles interception, filtering, protocol recognition, and raw packet transmission. It does not contain traffic modification logic; it calls Lua code to perform those tasks.
    • Lua Libraries: The actual traffic modification logic resides in Lua scripts called by the C core. Key libraries include:
      • zapret-lib.lua: Base helper library.
      • zapret-antidpi.lua: DPI attack library.
      • zapret-auto.lua: Orchestration library for dynamic decision-making.
      • zapret-obfs.lua: Protocol obfuscation.
      • zapret-pcap.lua: Traffic capture to .cap files.

    Kernel Interception

    Traffic redirection is handled by the following kernel tools depending on the OS:

    • Linux: iptables or nftables.
    • FreeBSD: ipfw.
    • OpenBSD: pf.
    • Windows: Built into winws2 via the WinDivert driver.

    Secondary Tools

    • blockcheck2: Tool for automated strategy testing.
    • mdig: Multi-threaded hostlist resolver for large lists.
    • ip2net: Aggregates individual IP addresses into subnets.
    • Startup Scripts: Linux scripts (init.d, common, ipset, etc.) used to coordinate nfqws2 and kernel tables. These scripts use a configuration file located in the project root.
  7. Filter by Network Presence (SSID and NLM)

    master

    You can apply different strategies based on the network connection (e.g., Wi-Fi vs. Ethernet).

    Wi-Fi Filtering (SSID):

    • Linux: Use --filter-ssid. nfqws2 resolves the SSID on the active interface and matches it against the provided list.
    • Windows: Use --ssid-filter. It monitors all Wi-Fi adapters. To use different strategies for different SSIDs, you must run multiple instances of winws2, as the filter activates/deactivates interception globally for that instance.

    Network List Manager (NLM) Filtering:

    • Use --nlm-filter[=all] or --nlm-list[=all] to filter by network GUIDs.
    • --nlm-list[=all] returns a list of GUIDs for connected networks.
    • Provide a comma-separated list of GUIDs to --nlm-filter to target specific networks recognized by the OS.
    • Note: On newer Windows systems, you may need to manually assign GUIDs via PowerShell or Registry if the system categorizes them incorrectly.
  8. Configure WinDivert for Windows 7

    master

    Due to changes in Windows 7 driver signing requirements, you may need to provide specific versions of WinDivert files to ensure compatibility with zapret2. You can use one of the following methods:

    1. Replace existing WinDivert64.sys and WinDivert.dll with version 2.2.0-C or 2.2.0-D from reqrypt.org.
    2. Apply the ESU (Extended Security Updates) hack.
    3. Use the "BypassESU" patcher.
    4. Use UpdatePack7R2.
  9. Configure Yandex DNS on OpenWrt via dnsmasq

    master

    To use Yandex DNS on port 1253 on an OpenWrt system, update your configuration files as follows:

    1. In /etc/config/dhcp, add the Yandex server to the dnsmasq configuration.
    2. In /etc/config/network, ensure the wan interface does not use peer DNS.
    # /etc/config/dhcp
    config dnsmasq
     list server '77.88.8.88#1253'
    
    # /etc/config/network
    config interface 'wan'
     option peerdns '0'
  10. Setup Windows ARM64

    master

    Running zapret2 on Windows ARM64 requires addressing the lack of a signed WinDivert driver and Cygwin support:

    1. Enable Test Signing

    You must enable test signature mode by running: bcdedit /set {current} testsigning on

    2. Driver Replacement

    Use the unsigned WinDivert64.sys driver from the zapret-win-bundle.

    3. Running the Binary

    • Windows 11 ARM64: Use the x64 build (leveraging x64 emulation). You must replace WinDivert64.sys with the ARM64 version, but you do not need to replace WinDivert.dll.
    • Windows 10 ARM64: Since there is no x64 emulation, you can theoretically use the win32 (x86) variant and place the ARM64 WinDivert64.sys driver in the same directory (note: this is unverified).
  11. Integrate zapret2 with systemd

    master

    To manually integrate zapret2 with systemd-based Linux distributions, follow these steps:

    1. Autostart

    cp /opt/zapret2/init.d/systemd/zapret2.service /lib/systemd/system
    systemctl daemon-reload
    systemctl enable zapret2

    2. List update timer

    To ensure lists are updated at a random time every 2 days (suitable for desktops that are not always on):

    cp /opt/zapret2/init.d/systemd/zapret2-list-update.* /lib/systemd/system
    systemctl daemon-reload
    systemctl enable zapret2-list-update.timer
    systemctl start zapret2-list-update.timer
    cp /opt/zapret2/init.d/systemd/zapret2.service /lib/systemd/system
    systemctl daemon-reload
    systemctl enable zapret2
  12. Use zapret2 startup scripts

    master

    The zapret2 executable provides startup scripts for Linux and OpenWRT (located in init.d/sysv for Linux and init.d/openwrt for OpenWRT). The primary command is passed as the first argument $1.

    Note: If INIT_APPLY_FW is not set to 1 in your config, the firewall will not be started by the start command. On OpenWRT with fw3 (iptables), the firewall is managed separately and start/stop/restart commands only affect the daemons.