The public redacted skeleton for mld_chaffing_v2.py, “Virtual Mirror,” describes a connection-level chaff prototype: observe rates, emit extra small web requests under an idle condition, and evaluate statistical changes and resource cost. The distributions and classifier numbers below are reproducible illustrations; defensive effectiveness and runtime costs still need measurements.
The public resources include architecture notes, redacted code and test templates. Controller secrets, real nodes and complete deployment settings remain local.
1. Why Encryption Does Not Hide Traffic Shape
TLS and SSL protect payloads. They stop an observer from reading request parameters, response bodies, and application data. Traffic analysis, however, does not always need plaintext. Deep packet inspection systems and machine-learning traffic classifiers can work with metadata such as packet length, inter-arrival time, burst duration, upload/download ratio, connection lifetime, TLS record size, and idle periods.
This is the metadata leak problem. Video streaming, web browsing, repository sync, and interactive shells can remain distinguishable even after payload encryption because their statistical shapes are different. Encryption protects content. It does not automatically protect traffic fingerprints.
Virtual Mirror tries to alter observable features with randomized web requests during idle windows. Whether that reduces target identification depends on the observation point and attack model; an observer may separate the extra connections or learn their new fingerprint.
2. Information Entropy And Adversarial ML
A traffic classifier usually turns a session window into a feature vector. Typical features include:
- Upload and download bytes per time window
- Gaps between request bursts
- Ratio of small packets to large packets
- Connection setup, idle, retry, and close rhythm
- Distribution of short-lived and long-lived connections
Those features can feed random forests, gradient-boosted trees, neural networks, or sequence models. The model does not need plaintext when a class of applications has a sufficiently stable statistical boundary.
Information entropy gives us a way to talk about uncertainty in a distribution:
H(X) = - sum p(x_i) * log2(p(x_i))
Regularity and entropy depend on the feature, bins and temporal dependencies. Random noise can change them without making classes harder to separate. Measure marginal entropy, conditional sequence predictability and classifier separability separately. Random perturbations are not automatically adversarial examples optimized against a model.
Noise budgets affect bandwidth, latency and identifiability together. Low-frequency idle triggering is a resource policy to test against other timings and budgets, including whether the noise creates its own stable fingerprint.
3. Mathematical Validation: Entropy, Distribution Distance, And Confusion Matrices
To evaluate this defense, compare classifier separability under the same sampling window and check that extra bandwidth and latency stay within an acceptable budget.
Represent one traffic window as a feature vector X. The label Y is either “target traffic” or “background traffic.” Without chaffing, let the target distribution be P_t(X) and the background distribution be P_b(X). Whether a classifier can identify the target depends on the distance between those two distributions, not on whether the payload is encrypted.
For a computable model, let C(X) be the background-observation distribution and constrain alpha to [0,1]. If an observation comes from C with probability alpha and otherwise from P_t, the convex mixture below follows. Adding requests within a session and then aggregating features does not generally produce this mixture; alpha is not directly a byte-overhead fraction.
Q_t(X) = (1 - alpha) * P_t(X) + alpha * C(X)
In a simplified but useful binary model, assume the background distribution is C(X) and both classes have equal priors. The Bayes optimal error rate is:
P_error* = 1/2 * (1 - TV(P_t, P_b))
TV is the total variation distance. After mixing in the same background noise:
TV(Q_t, C)
= TV((1 - alpha)P_t + alpha C, C)
= (1 - alpha) * TV(P_t, C)
Therefore:
P_error*(after)
= 1/2 * (1 - (1 - alpha)TV(P_t, C))
= P_error*(before) + alpha * TV(P_t, C) / 2
Under the equal-prior observation-mixture model with background C and 0≤alpha≤1, alpha > 0 increases Bayes error when the original target is separable. This establishes a change in that model. Whether the prototype produces the corresponding Q_t must first be checked from collected data.
Now take a small reproducible example. Suppose we only use the “request interval” feature and bin it into four buckets: very short, short, medium, and long. The target traffic is initially concentrated:
P_t = [0.70, 0.20, 0.08, 0.02]
C = [0.25, 0.25, 0.25, 0.25]
alpha = 0.25
Q_t = 0.75 * P_t + 0.25 * C
= [0.5875, 0.2125, 0.1225, 0.0775]
The Shannon entropy rises from H(P_t)=1.229 bits to H(Q_t)=1.583 bits. The Jensen-Shannon divergence between target and background drops from 0.199 bits to 0.102 bits, and total variation distance drops from 0.450 to 0.3375. The Bayes optimal error rate increases from 27.5% to 33.1%.
A confusion matrix shows how to validate this with a real classifier. Suppose we have 100 target windows and 100 background windows, and the classifier predicts whether a window is target traffic. Before chaffing:
| Predicted target | Predicted background | |
|---|---|---|
| Actual target | TP = 90 | FN = 10 |
| Actual background | FP = 12 | TN = 88 |
The metrics are:
Accuracy = (TP + TN) / N = (90 + 88) / 200 = 89.0%
Precision = TP / (TP + FP) = 90 / 102 = 88.2%
Recall = TP / (TP + FN) = 90 / 100 = 90.0%
F1 = 2PR / (P + R) = 89.1%
If chaffing makes the target harder to identify, a later run might look like this:
| Predicted target | Predicted background | |
|---|---|---|
| Actual target | TP = 62 | FN = 38 |
| Actual background | FP = 25 | TN = 75 |
Accuracy = (62 + 75) / 200 = 68.5%
Precision = 62 / 87 = 71.3%
Recall = 62 / 100 = 62.0%
F1 = 66.3%
The 100+100 windows and confusion matrices are evaluation templates, not production measurements. A validation should keep sampling, splits and priors comparable, include an attacker retrained/tuned on chaffed data, and compare ROC-AUC, F1, detection at fixed false-positive rates, Jensen-Shannon divergence and bandwidth/CPU/p95 cost. Report the dataset and attacker for which the result holds.
4. The mld_chaffing_v2.py control flow
The design reads rates from a Clash-compatible controller and sends GET/HEAD through a local proxy under an idle condition. The public skeleton retains parameters and the main loop but leaves controller reading and target sending as redacted placeholders. It is not a runnable service or evidence of current service state.
The important parameters are visible:
LOCAL_PROXY = "http://127.0.0.1:<local-proxy-port>"
CLASH_API_URL = "http://127.0.0.1:<controller-port>"
IDLE_THRESHOLD_BPS = 15360 # 15 KB/s
The intended monitor reads /traffic and updates current_down_bps and current_up_bps. The loop waits 0.5 seconds before checking, with another 0.1–0.3 seconds of jitter on the idle branch. Continuous idle triggering therefore includes that extra wait. The 15360 B/s threshold equals 15 KiB/s or 15.36 kB/s; interpret the retained code/table label “15KB/s” using that binary threshold.
if current_down_bps < IDLE_THRESHOLD_BPS and current_up_bps < IDLE_THRESHOLD_BPS:
time.sleep(random.uniform(0.1, 0.3))
threading.Thread(target=fire_micro_pulse, daemon=True).start()
The fragment uses 15–450 padding characters and an 80/20 GET/HEAD selection, then reads one GET iterator chunk and closes. iter_content(chunk_size=1024) controls application iteration, not total wire bytes. Headers, TLS records, decompression/network buffering and in-flight data add cost. Measure the observable profile and actual network usage.
method = random.choices(["GET", "HEAD"], weights=[80, 20], k=1)[0]
padding = random_ascii(random.randint(15, 450))
if method == "GET":
response = session.get(url_with_padding, timeout=5, stream=True)
next(response.iter_content(chunk_size=1024), None)
response.close()
Secrets should come from environment variables, not source files. The target pool should be allowlisted so the script does not generate meaningless traffic toward unsuitable sites. Logs should be redacted by default and should not expose proxy ports, controller credentials, or real egress topology.
The public skeleton has no sample-freshness check or in-flight concurrency cap. Initial zero rates do not establish real idleness. A complete implementation needs successful fresh samples, an idle recheck after jitter, and bounded concurrent requests and per-minute budgets before assessing application impact.
5. Connection-Level Routing, Not Packet-Level Reordering
Virtual Mirror fits better beside a connection-level routing policy than inside low-level packet routing. Packet-level reordering can create out-of-order delivery, retransmission, latency jitter, and difficult debugging. Connection-level distribution keeps one TCP connection on one path, preserving stable TCP semantics.
In a dual-node design, the primary and backup exits are connection-level targets. Under normal conditions, new connections prefer the primary path. If latency, failure rate, or exit health crosses a threshold, new connections can move to the backup. Existing connections are not forcibly split across paths.
This design has four practical advantages:
- Less added reordering: connection-level scheduling adds no per-packet split/reorder layer; TCP still handles network reordering.
- Clearer scheduling boundaries: an exit change can affect new scheduling only, while existing connections can still fail with the old exit.
- Simpler emergency escape: the backup path can stay quiet until needed.
- Independent noise budget: the chaff thread perturbs idle windows but does not take over application traffic.
Connection routing selects exits; the chaff module budgets extra requests. Record their states separately to distinguish exit failures from noise overhead.
6. Stress Testing And Performance Trade-Offs
This defense has a cost. Even when a pulse reads only 1 KB of response data, it still creates extra connections, HTTP work, Python thread scheduling, object allocation, and proxy activity. The v2 prototype exposes these public parameters:
| Parameter | Current value | Why it matters |
|---|---|---|
| Idle threshold | 15 KB/s | Only trigger during low-speed windows |
| State check interval | 0.5 seconds | Balances responsiveness and CPU wakeups |
| Jitter | 0.1 – 0.3 seconds | Avoids creating a fixed pulse rhythm |
| Padding length | 15 – 450 characters | Perturbs request size and URL length |
| GET/HEAD mix | 80 / 20 | Mixes request shapes while limiting downloads |
| GET response read | About 1 KB | Keeps a response profile without large bandwidth cost |
A complete stress test should measure CPU usage, resident memory, peak thread count, pulses per minute, retry count, and the effect on real page loads or downloads. These stress-test measurements have not yet been collected. The companion resources include a redacted test-log template and a classifier-evaluation template for future measured results.
If this prototype needs to support heavier concurrency, the next engineering step is to move from ad hoc threads to asyncio, add target-pool rate limits, load all secrets from environment variables, implement a local circuit breaker, and cap pulses per minute. System-level tuning should focus on file descriptor limits, connection tracking capacity, DNS caching, and Python object lifecycle before increasing emission frequency.
7. Conclusion: Defensive Obfuscation Is Engineering, Not Magic
Traffic analysis and defensive obfuscation will keep evolving together. Classifiers can learn more complex temporal features. Defenders can add more careful noise budgets, connection-level routing, health feedback, and log minimization. The system design should also consider encryption, availability, egress health checks, minimal logs, measured noise, and user experience together.
The value of mld_chaffing_v2.py is that it turns the problem into a small experiment: read live traffic rate, detect idle windows, emit controlled micro-pulses, then observe the cost and benefit. The next useful step is reproducibility: fixed input traffic, fixed sampling windows, and public metrics comparing feature distributions before and after chaffing.
Redacted companion resources are available in the resource library, including architecture notes and a secret-free code skeleton. Chinese readers can open the Chinese version.
FAQ
Does this modify real TCP payloads?
No. The current v2 prototype does not decrypt or rewrite application flows. It emits additional small semantic requests during idle windows to perturb the external statistical profile.
Why not emit pure random bytes?
Pure random bytes can become suspicious by themselves. This experiment uses web-like micro-pulses so the noise resembles ordinary client background behavior instead of a new stable fingerprint.
Will this hurt performance?
It can. Any chaff system needs idle thresholds, jitter, response caps, and circuit breakers. Measure the cost before leaving it enabled permanently.
The same idea – change the attacker’s economics rather than trying to block outright – runs this site’s own anti-abuse gate: the IP reputation scorer shows the score computed for your address and the weight of every signal. The score sets proof-of-work difficulty; it never decides admission by itself.