sni-spoofing-dpi-bypass
```markdown
What this skill does
```markdown
---
name: sni-spoofing-dpi-bypass
description: Bypass Deep Packet Inspection (DPI) firewalls using IP/TCP header manipulation and SNI spoofing techniques in Python
triggers:
- bypass DPI with SNI spoofing
- how to use SNI spoofing to bypass firewall
- TCP header manipulation to evade censorship
- IP fragmentation DPI bypass Python
- implement SNI spoofing script
- circumvent deep packet inspection
- spoof TLS SNI to bypass blocking
- patterniha SNI spoofing setup
---
# SNI-Spoofing DPI Bypass
> Skill by [ara.so](https://ara.so) — Daily 2026 Skills collection.
SNI-Spoofing is a Python-based tool that bypasses Deep Packet Inspection (DPI) systems by manipulating IP and TCP headers. It works by fragmenting TLS ClientHello packets so the SNI (Server Name Indication) field is split across multiple TCP segments, preventing DPI middleboxes from inspecting the destination hostname while still allowing the connection to succeed end-to-end.
---
## How It Works
DPI systems inspect the SNI field in TLS ClientHello to block connections to specific domains. SNI-Spoofing defeats this by:
1. **TCP segmentation** — Splitting the ClientHello across multiple TCP packets so the SNI is never in a single inspectable packet.
2. **IP fragmentation** — Fragmenting IP packets so DPI reassembly is bypassed.
3. **Raw socket manipulation** — Using Scapy or raw sockets to craft custom IP/TCP headers with precise control over fragmentation offsets and flags.
---
## Installation
### Requirements
- Python 3.8+
- Root/Administrator privileges (required for raw sockets)
- Linux (recommended; Windows has limited raw socket support)
```bash
git clone https://github.com/patterniha/SNI-Spoofing.git
cd SNI-Spoofing
pip install -r requirements.txt
```
### Dependencies
```bash
pip install scapy
```
On Linux, ensure `nftables` or `iptables` does not interfere with outgoing packets:
```bash
# Drop kernel RST packets for the port you're intercepting
sudo iptables -A OUTPUT -p tcp --tcp-flags RST RST -j DROP
```
---
## Project Structure
```
SNI-Spoofing/
├── main.py # Entry point / core proxy logic
├── sni.py # SNI extraction and packet splitting
├── utils.py # Helper functions (checksum, headers)
└── requirements.txt
```
---
## Key Concepts & API
### SNI Extraction from TLS ClientHello
```python
def extract_sni(data: bytes) -> str | None:
"""
Extract the SNI hostname from a raw TLS ClientHello payload.
Returns None if not found.
"""
try:
if data[0] != 0x16: # TLS Handshake
return None
if data[5] != 0x01: # ClientHello
return None
# Skip TLS record header (5 bytes) + handshake header (4 bytes)
# + client_version (2) + random (32) + session_id_length (1+n)
pos = 9
session_id_len = data[pos]
pos += 1 + session_id_len
# Skip cipher suites
cipher_suites_len = int.from_bytes(data[pos:pos+2], 'big')
pos += 2 + cipher_suites_len
# Skip compression methods
compression_len = data[pos]
pos += 1 + compression_len
# Extensions
extensions_len = int.from_bytes(data[pos:pos+2], 'big')
pos += 2
end = pos + extensions_len
while pos < end:
ext_type = int.from_bytes(data[pos:pos+2], 'big')
ext_len = int.from_bytes(data[pos+2:pos+4], 'big')
pos += 4
if ext_type == 0x0000: # SNI extension
# server_name_list_length (2) + name_type (1) + name_length (2)
name_len = int.from_bytes(data[pos+3:pos+5], 'big')
return data[pos+5:pos+5+name_len].decode('utf-8')
pos += ext_len
except Exception:
return None
return None
```
### TCP Segmentation of ClientHello
```python
from scapy.all import IP, TCP, Raw, send
def send_fragmented_client_hello(
dst_ip: str,
dst_port: int,
src_port: int,
seq: int,
client_hello: bytes,
split_position: int = None
):
"""
Split TLS ClientHello into two TCP segments at split_position.
Default split: right before the SNI hostname bytes.
"""
if split_position is None:
# Split in the middle of the packet to bisect SNI
split_position = len(client_hello) // 2
part1 = client_hello[:split_position]
part2 = client_hello[split_position:]
pkt1 = (
IP(dst=dst_ip) /
TCP(dport=dst_port, sport=src_port, seq=seq, flags="PA") /
Raw(load=part1)
)
pkt2 = (
IP(dst=dst_ip) /
TCP(dport=dst_port, sport=src_port, seq=seq + len(part1), flags="PA") /
Raw(load=part2)
)
send(pkt1, verbose=False)
send(pkt2, verbose=False)
```
### IP Fragmentation Approach
```python
from scapy.all import IP, TCP, Raw, fragment, send
def send_ip_fragmented(dst_ip: str, dst_port: int, payload: bytes):
"""
Send payload as IP fragments to bypass DPI reassembly.
Fragment size of 8 bytes ensures SNI is split across fragments.
"""
packet = IP(dst=dst_ip) / TCP(dport=dst_port) / Raw(load=payload)
fragments = fragment(packet, fragsize=8)
for frag in fragments:
send(frag, verbose=False)
```
---
## Running the Tool
Most usage requires root:
```bash
sudo python3 main.py --host <TARGET_DOMAIN> --port 443
```
### Common CLI Options
```bash
# Basic usage - connect through SNI-spoofed tunnel
sudo python3 main.py --host example.com --port 443
# Specify local proxy port to bind
sudo python3 main.py --host example.com --port 443 --local-port 8080
# Use IP fragmentation mode
sudo python3 main.py --host example.com --port 443 --mode fragment
# Use TCP split mode (default)
sudo python3 main.py --host example.com --port 443 --mode split
# Specify custom split offset (byte position to split ClientHello)
sudo python3 main.py --host example.com --port 443 --split-at 40
```
---
## Full Working Example: Transparent Proxy with SNI Splitting
```python
#!/usr/bin/env python3
"""
Minimal transparent proxy that intercepts TLS ClientHello
and resends it split across two TCP segments.
Requires: pip install scapy
Run as root.
"""
import socket
import threading
from scapy.all import IP, TCP, Raw, send, sniff, conf
conf.verb = 0 # Suppress Scapy output
TARGET_HOST = "example.com"
TARGET_PORT = 443
LOCAL_PORT = 8080
def extract_sni(data: bytes) -> str | None:
try:
if len(data) < 6 or data[0] != 0x16 or data[5] != 0x01:
return None
pos = 9
pos += 1 + data[pos]
cipher_len = int.from_bytes(data[pos:pos+2], 'big')
pos += 2 + cipher_len
pos += 1 + data[pos]
pos += 2 # skip extensions length field
while pos < len(data) - 4:
ext_type = int.from_bytes(data[pos:pos+2], 'big')
ext_len = int.from_bytes(data[pos+2:pos+4], 'big')
pos += 4
if ext_type == 0:
name_len = int.from_bytes(data[pos+3:pos+5], 'big')
return data[pos+5:pos+5+name_len].decode()
pos += ext_len
except Exception:
pass
return None
def handle_client(client_sock: socket.socket, target_ip: str):
try:
client_hello = client_sock.recv(4096)
sni = extract_sni(client_hello)
print(f"[*] Intercepted ClientHello, SNI: {sni}")
# Connect to real server with raw socket for first packet
raw = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
raw.connect((target_ip, TARGET_PORT))
split_at = len(client_hello) // 2
raw.send(client_hello[:split_at])
raw.send(client_hello[split_at:])
# Relay remaining data bidirectionally
def relay(src, dst):
try:
while chunk := src.recv(4096):
dst.send(chunk)
except Exception:
pass
t1 = threading.Thread(target=relay, args=(raw, client_sock), daemon=True)
Related in Writing & Docs
jax-development
IncludedUse this skill when the user is writing, debugging, profiling, refactoring, reviewing, benchmarking, parallelising, exporting, or explaining JAX code, or when they mention JAX, jax.numpy, jit, grad, value_and_grad, vmap, scan, lax, random keys, pytrees, jax.Array, sharding, Mesh, PartitionSpec, NamedSharding, pmap, shard_map, Pallas, XLA, StableHLO, checkify, profiler, or the JAX repo. It helps turn NumPy or PyTorch-style code into pure functional JAX, fix tracer/control-flow/shape/PRNG bugs, remove recompiles and host-device syncs, choose transforms and sharding strategies, inspect jaxpr/lowering/IR, and benchmark compiled code correctly.
nature-article-writer
IncludedDrafts, rewrites, diagnostically critiques, and style-calibrates primary research manuscripts for Nature and Nature Portfolio journals. Use when the user wants a Nature-style title, summary paragraph or abstract, introduction, results, discussion, methods, figure legends, presubmission enquiry, cover letter, reviewer response, or when a scientific draft sounds generic, jargon-heavy, structurally weak, or AI-ish and needs precise, broad-reader-friendly prose without inventing data, analyses, or references. Best for primary research articles and letters rather than reviews or press releases unless explicitly adapting one.
deckrd
IncludedDocument-driven framework that derives requirements, specifications, implementation plans, and executable tasks from goals through structured AI dialogue. Use when user says "write requirements", "create spec", "plan implementation", "derive tasks", "structure this feature", "break down into tasks", or "document this module". Also use for reverse engineering existing code into docs (/deckrd rev). Do NOT use for direct code writing — use /deckrd-coder after tasks are generated. Do NOT use when the user only wants to run or fix existing code without planning.
clinical-decision-support
IncludedGenerate professional clinical decision support (CDS) documents for pharmaceutical and clinical research settings, including patient cohort analyses (biomarker-stratified with outcomes) and treatment recommendation reports (evidence-based guidelines with decision algorithms). Supports GRADE evidence grading, statistical analysis (hazard ratios, survival curves, waterfall plots), biomarker integration, and regulatory compliance. Outputs publication-ready LaTeX/PDF format optimized for drug development, clinical research, and evidence synthesis.
handling-sf-data
IncludedSalesforce data operations with 130-point scoring. Use this skill to create, update, delete, bulk import/export, generate test data, and clean up org records using sf CLI and anonymous Apex. TRIGGER when: user creates test data, performs bulk import/export, uses sf data CLI commands, needs data factory patterns for Apex tests, or needs to seed/clean records in a Salesforce org. DO NOT TRIGGER when: SOQL query writing only (use querying-soql), Apex test execution (use running-apex-tests), or metadata deployment (use deploying-metadata).
accelint-ac-to-playwright
IncludedConvert and validate acceptance criteria for Playwright test automation. Use when user asks to (1) review/evaluate/check if AC are ready for automation, (2) assess if AC can be converted as-is, (3) validate AC quality for Playwright, (4) turn AC into tests, (5) generate tests from acceptance criteria, (6) convert .md bullets or .feature Gherkin files to Playwright specs, (7) create test automation from requirements. Handles both bullet-style markdown and Gherkin syntax with JSON test plan generation and validation.