Portfolio Blog Code Repository Contact

The AI Arms Race: Machine Learning in Deep Packet Inspection

This is part 10 of the Black Phoenix Protocol (BPP) engineering blog series. If you haven't yet, start with Day Zero.


Throughout the development of BPP and our testing against BPP Guardian, we've relied on overcoming static heuristics. We bypass active probing, we spoof JA3 fingerprints, we match timing profiles, and we evade Shannon entropy thresholding by using structured, camouflage-heavy protocols (XTLS-REALITY).

But the landscape of censorship is not static. State-level actors often referred to collectively as the Great Firewall (GFW) or equivalent national filtering systems are shifting their strategies.

We are entering an era where Deep Packet Inspection (DPI) is being supercharged by Machine Learning (ML). This is the new arms race.

Why Statistical Entropy is No Longer Enough

In Part 08, we explored Shannon entropy. Standard DPI looks for packets that are "too random" (approaching an entropy of 8.0 bits/byte), which indicates a raw encrypted proxy stream (like standard Shadowsocks). BPP avoids this by framing its payloads within standard TLS records that have a mix of headers and encrypted payloads, closely matching the entropy profile of legitimate HTTPS traffic.

However, ML classifiers do not look at single, static metrics. They look at features over time.

Instead of asking, "Is this packet's entropy > 7.9?", an ML model asks:

  • "What is the sequence of packet lengths in the first 10 packets?"
  • "What is the inter-arrival time between the client's Request and the server's Response?"
  • "Does the burst of data flowing back from the server match the expected behavior of streaming a YouTube video, or does it look like someone downloading a large binary over a proxy?"

These models use techniques like Random Forests and deep Neural Networks to classify flows based on their spatio-temporal features.

Training the Classifier: How They See Us

To understand this threat, I spent a few weeks acting as the adversary once again. I captured gigabytes of standard web browsing traffic (browsing Wikipedia, streaming videos, reading news) and gigabytes of BPP traffic (tunneling SSH, downloading large files over BPP, general proxy use).

I extracted the following features for the first 20 packets of every flow:

  1. Packet lengths (Client -> Server)
  2. Packet lengths (Server -> Client)
  3. Inter-arrival timings

I fed this into a simple Random Forest classifier using Python's scikit-learn. The results were sobering.

Even with XTLS-REALITY perfectly mimicking the TLS handshake and JA3 fingerprinting matching Chrome, the classifier was able to distinguish BPP traffic from legitimate browsing traffic with a >90% accuracy rate, simply based on the behavioral pattern of the encrypted data blocks.

Legitimate web browsing is bursty: a request is made, a large chunk of HTML/images comes back, and then silence while the user reads. Proxy traffic, especially when tunneling SSH or bulk downloads, has a completely different tempo.

Adversarial Perturbations: The Countermeasure

If they use ML to classify, we must use adversarial techniques to confuse the classifier. In the realm of Computer Vision, adversarial perturbations (adding invisible noise to an image) can make an ML model classify a picture of a stop sign as a speed limit sign. We need the equivalent for network traffic.

Packet Padding and Shaping

In BPP, we already implemented basic traffic shaping (Part 04), but it needs to evolve. We need Stochastic Padding and Timing Jitter.

  1. Randomized Padding: We cannot pad packets to a uniform size (that's an anomaly itself). Instead, we must draw padding sizes from a probability distribution that mimics legitimate protocols (e.g., matching the packet size distribution of HTTP/2 streaming).
  2. Artificial Delays: To defeat inter-arrival timing analysis, the BPP client and server must occasionally buffer packets and send them with microsecond delays, smoothing out the aggressive bursting typical of proxy tunnels.

The Cost of Camouflage

The tradeoff is brutal. Every byte of padding we add to confuse an ML classifier consumes bandwidth. Every millisecond of artificial delay we introduce increases latency.

We are constantly balancing on a knife-edge: Un-detectability vs. Usability. If we pad too aggressively, the proxy becomes too slow for practical use. If we prioritize speed, we generate traffic patterns that ML models can spot.

The Future

Machine Learning DPI is currently expensive to run at scale. Analyzing the behavioral features of millions of concurrent connections requires massive computational resources, which is why it is often deployed selectively or intermittently.

But compute gets cheaper every year. The BPP engine will need a major architectural update in the future introducing a dynamic traffic shaping engine that actively models and mimics specific applications (e.g., a "YouTube Profile" or a "Zoom Profile") to poison the features ML models rely upon.

The battle has moved from cryptography to behavioral psychology.


Next up in Part 11, we will step away from the code and look at the physical realm: deploying the Phoenix on cloud infrastructure and maintaining strict OPSEC.

Amine Boutouil

Cybersecurity & Infrastructure Engineer | Network Architecture & Secure Systems Design

boutouil.me →