Skip to main content

Overview

The BypassEngine is the core component responsible for detecting and fragmenting TLS ClientHello and HTTP request packets to bypass deep packet inspection (DPI). It supports ISP-specific presets and customizable fragmentation strategies.

BypassEngine

Constructor

pub fn new(config: BypassConfig) -> Self
Creates a new bypass engine with the specified configuration.
config
BypassConfig
required
Configuration for the bypass engine
BypassEngine
BypassEngine
New instance of the bypass engine

Methods

process_outgoing

pub fn process_outgoing(&self, data: &[u8]) -> BypassResult
Processes outgoing packet data, detecting protocol and applying fragmentation if applicable.
data
&[u8]
required
Raw packet data to process
BypassResult
BypassResult
Result containing fragments, delays, and metadata
Example:
use turkey_dpi_engine::{BypassEngine, BypassConfig};

let engine = BypassEngine::new(BypassConfig::default());
let packet = b"\x16\x03\x01...";

let result = engine.process_outgoing(packet);

if result.modified {
    println!("Protocol: {:?}", result.protocol);
    println!("Hostname: {:?}", result.hostname);
    println!("Fragments: {}", result.fragments.len());
    
    // Send fragments with delay
    for fragment in result.fragments {
        send_packet(&fragment);
        if let Some(delay) = result.inter_fragment_delay {
            thread::sleep(delay);
        }
    }
    
    // Send fake packet if configured
    if let Some(fake) = result.fake_packet {
        send_with_ttl(&fake, 1);
    }
}

BypassConfig

Structure

pub struct BypassConfig {
    pub fragment_sni: bool,
    pub tls_split_pos: usize,
    pub fragment_http_host: bool,
    pub http_split_pos: usize,
    pub send_fake_packets: bool,
    pub fake_packet_ttl: u8,
    pub fragment_delay_us: u64,
    pub use_tcp_segmentation: bool,
    pub min_segment_size: usize,
    pub max_segment_size: usize,
}

Fields

fragment_sni
bool
default:"true"
Enable SNI fragmentation for TLS ClientHello packets
tls_split_pos
usize
default:"3"
Position to split TLS ClientHello (0 = split at SNI midpoint)
fragment_http_host
bool
default:"true"
Enable fragmentation of HTTP Host header
http_split_pos
usize
default:"2"
Offset from Host header start to split HTTP requests
send_fake_packets
bool
default:"false"
Send fake packets with corrupted SNI before real packets
fake_packet_ttl
u8
default:"1"
TTL for fake packets (should expire before reaching destination)
fragment_delay_us
u64
default:"0"
Microseconds to delay between sending fragments
use_tcp_segmentation
bool
default:"true"
Use TCP segmentation for initial fragment
min_segment_size
usize
default:"1"
Minimum TCP segment size for fragmentation
max_segment_size
usize
default:"40"
Maximum TCP segment size for first fragment

ISP Presets

Default

let config = BypassConfig::default();
General-purpose configuration suitable for most scenarios.

Turk Telekom

let config = BypassConfig::turk_telekom();
Optimized preset for Turk Telekom DPI systems. Configuration:
  • tls_split_pos: 2
  • http_split_pos: 2
  • max_segment_size: 20

Vodafone TR

let config = BypassConfig::vodafone_tr();
Optimized for Vodafone Turkey network. Configuration:
  • tls_split_pos: 3
  • http_split_pos: 3
  • fragment_delay_us: 100
  • max_segment_size: 30

Superonline

let config = BypassConfig::superonline();
Optimized for Superonline ISP. Configuration:
  • tls_split_pos: 1
  • http_split_pos: 1
  • max_segment_size: 15

Aggressive

let config = BypassConfig::aggressive();
Maximum fragmentation for stubborn DPI systems. Configuration:
  • tls_split_pos: 0 (splits at SNI midpoint)
  • http_split_pos: 1
  • fragment_delay_us: 10000 (10ms)
  • max_segment_size: 5
Example:
use turkey_dpi_engine::BypassConfig;

// Use ISP-specific preset
let config = BypassConfig::turk_telekom();

// Or create custom configuration
let custom = BypassConfig {
    fragment_sni: true,
    tls_split_pos: 2,
    fragment_http_host: true,
    http_split_pos: 3,
    send_fake_packets: false,
    fake_packet_ttl: 1,
    fragment_delay_us: 500,
    use_tcp_segmentation: true,
    min_segment_size: 1,
    max_segment_size: 25,
};

BypassResult

Structure

pub struct BypassResult {
    pub fragments: Vec<Bytes>,
    pub inter_fragment_delay: Option<Duration>,
    pub fake_packet: Option<Bytes>,
    pub modified: bool,
    pub protocol: DetectedProtocol,
    pub hostname: Option<String>,
}

Fields

fragments
Vec<Bytes>
Packet fragments to send (in order)
inter_fragment_delay
Option<Duration>
Delay to insert between sending fragments
fake_packet
Option<Bytes>
Fake packet with corrupted SNI (send first with low TTL)
modified
bool
Whether the packet was fragmented (false = passthrough)
protocol
DetectedProtocol
Detected protocol: TlsClientHello, HttpRequest, or Unknown
hostname
Option<String>
Extracted hostname from SNI or Host header
Example:
let result = engine.process_outgoing(packet_data);

match result.protocol {
    DetectedProtocol::TlsClientHello => {
        println!("TLS handshake to: {:?}", result.hostname);
    }
    DetectedProtocol::HttpRequest => {
        println!("HTTP request to: {:?}", result.hostname);
    }
    DetectedProtocol::Unknown => {
        // Packet passed through unmodified
    }
}

// Check if packet was fragmented
if result.modified {
    assert!(result.fragments.len() >= 2);
}

DetectedProtocol

Enum

pub enum DetectedProtocol {
    TlsClientHello,
    HttpRequest,
    Unknown,
}
TlsClientHello
variant
Packet is a TLS ClientHello with SNI extension
HttpRequest
variant
Packet is an HTTP request with Host header
Unknown
variant
Packet type could not be identified (passthrough)

Complete Example

use turkey_dpi_engine::{BypassEngine, BypassConfig, DetectedProtocol};
use std::thread;

fn main() {
    // Create engine with ISP-specific preset
    let engine = BypassEngine::new(BypassConfig::vodafone_tr());
    
    // Sample TLS ClientHello packet (truncated)
    let tls_packet = vec![
        0x16, 0x03, 0x01, 0x00, 0x5a,  // TLS Record
        0x01, 0x00, 0x00, 0x56,        // Handshake
        0x03, 0x03,                     // TLS 1.2
        // ... random bytes ...
    ];
    
    // Process packet
    let result = engine.process_outgoing(&tls_packet);
    
    match result.protocol {
        DetectedProtocol::TlsClientHello => {
            println!("Detected TLS ClientHello");
            println!("Server: {}", result.hostname.unwrap_or_default());
            println!("Fragments: {}", result.fragments.len());
            
            // Send fake packet first (if enabled)
            if let Some(fake) = result.fake_packet {
                send_packet_with_ttl(&fake, 1);
            }
            
            // Send fragments with delay
            for (i, fragment) in result.fragments.iter().enumerate() {
                send_packet(fragment);
                
                // Add delay between fragments (not after last)
                if i < result.fragments.len() - 1 {
                    if let Some(delay) = result.inter_fragment_delay {
                        thread::sleep(delay);
                    }
                }
            }
        }
        DetectedProtocol::HttpRequest => {
            println!("Detected HTTP request");
            // Handle HTTP fragmentation...
        }
        DetectedProtocol::Unknown => {
            // Send unmodified
            send_packet(&result.fragments[0]);
        }
    }
}

fn send_packet(data: &[u8]) {
    // Implementation: send via raw socket or packet filter
}

fn send_packet_with_ttl(data: &[u8], ttl: u8) {
    // Implementation: send with specific TTL
}

See Also

  • Config - Advanced configuration system
  • Pipeline - Full packet processing pipeline

Build docs developers (and LLMs) love