Skip to main content

A lightweight DNS proxy designed to bypass DNS spoofing by exploiting timing differences between fake and legitimate packets

Project description

LatterDNS

LatterDNS is a lightweight, experimental DNS proxy designed to bypass DNS spoofing; a common censorship method used by the Great Firewall (GFW); by exploiting the timing difference between fake and legitimate packets.

"The truth arrives late."

How It Works

This tool operates on a simple observation: Censorship is a race.

  1. The Trigger: When you query a blocked domain (e.g., facebook.com), the firewall detects the request.

  2. The Race: The firewall attempts to "poison" your DNS cache by racing to send you a fake response (usually a random or reset IP) before the legitimate DNS server can respond.

  3. The Exploit: Because the firewall is injecting packets locally/en route, the fake response almost always arrives first. The legitimate response from the real DNS server travels a longer path and arrives second (milliseconds later).

LatterDNS simply discards the first response it sees for every query and accepts the second one.

Visualizing the Logic

sequenceDiagram
    participant Client
    participant LatterDNS
    participant GFW
    participant RealDNS

    Client->>LatterDNS: Query: facebook.com
    LatterDNS->>RealDNS: Forward Query
    Note over GFW: GFW detects keyword!
    GFW-->>LatterDNS: Fake IP (First Packet)
    Note over LatterDNS: 🛑 BLOCKED (Too fast)
    RealDNS-->>LatterDNS: Real IP (Second Packet)
    Note over LatterDNS: ✅ ACCEPTED (The Latter)
    LatterDNS->>Client: Real IP

Installation

Normal Usage

pip install latterdns

Development

git clone https://github.com/itsamirhn/latterdns.git
cd latterdns
uv pip install -e .

Usage

Once installed, you can run LatterDNS from anywhere using the latterdns command.

# Basic usage (defaults to listening on port 1053)
latterdns

# Custom upstream (Google DNS) and stricter timeouts
latterdns --upstream-host 8.8.8.8 --latter-timeout 0.15

# Enable debug logging
latterdns --log-level DEBUG

Available Options:

You can view all options anytime by running latterdns --help:

Usage: latterdns [OPTIONS]

  LatterDNS - Returns the latter DNS response packet from upstream.

Options:
  --listen-port INTEGER           Port to listen on  [default: 1053]
  --upstream-host TEXT            Upstream DNS host  [default: 1.1.1.1]
  --upstream-port INTEGER         Upstream DNS port  [default: 53]
  --former-timeout FLOAT          Timeout for former packet  [default: 1.0]
  --latter-timeout FLOAT          Timeout for latter packet  [default: 0.1]
  --log-level [DEBUG|INFO|WARNING|ERROR|CRITICAL]
                                  Logging level  [default: INFO]
  --help                          Show this message and exit.

🧪 How to Test

To verify that LatterDNS is working, you need to query a domain known to be poisoned by the GFW.

1. Without LatterDNS (The Control Test) Run a query against a standard upstream DNS. You should see a suspicious IP (often changed) or a connection reset.

dig @8.8.8.8 facebook.com +short
# Result: 1.2.3.4 (Fake IP / Poisoned Result)

2. With LatterDNS Point your query to the local port where LatterDNS is running (e.g., 1053).

dig @127.0.0.1 -p 1053 facebook.com +short
# Result: 157.240.x.x (Real Facebook IP)

⚠️ Limitations & Trade-offs

  • Latency for Unblocked Domains: For unblocked domains (where the GFW sends nothing), the proxy receives the legitimate packet first. It must wait latter-timeout (default 0.1s) to ensure no other packet is coming before returning the result. This adds ~100ms latency to every unblocked query.

  • Packet Loss: If the legitimate packet (the second one) is lost in transit, the proxy will timeout and return the first packet (the fake one), failing to bypass the block.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

latterdns-0.1.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

latterdns-0.1.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file latterdns-0.1.0.tar.gz.

File metadata

  • Download URL: latterdns-0.1.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for latterdns-0.1.0.tar.gz
Algorithm Hash digest
SHA256 712a9a02c4b78667f1ceec7534e1fbc7f65c2a9ede52bca968180fd427dd65cd
MD5 c086355e8b28a681809682e3b9f676f8
BLAKE2b-256 9a69964e130f6b12a632a1d5293af00e2b4ea065d87e569771994292846c1510

See more details on using hashes here.

File details

Details for the file latterdns-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: latterdns-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for latterdns-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d73fa7499abf7ebbdb135bcc7094db365555cdd654c9b7c2dcf2f9affd1171f2
MD5 313bfea98b6cc9562c5b1b88df58a734
BLAKE2b-256 82d8892dd95377eff5db01254e36ee9f64d1ed45b66b58d6b9e173d1339e585f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page