Semi-Supervised Learning for Anomaly Traffic Detection via Bidirectional Normalizing Flows

Zhangxuan Dang, Yu Zheng, Xinglin Lian, Chunlei Peng, Qiuyu Chen, Xinbo Gao

TL;DR

Detecting network traffic anomalies is notoriously difficult because "bad" data is rare and constantly evolving. This paper introduces a three-stage framework that uses Bidirectional Normalizing Flows to "hallucinate" pseudo-anomaly samples from a latent representation of normal traffic. By training a simple classifier to distinguish between real normal traffic and these generated pseudo-anomalies, the model achieves state-of-the-art detection performance while remaining exceptionally lightweight for real-world deployment.

What Problem Does This Paper Address?

Most network intrusion detection systems rely on supervised learning, which requires massive, accurately labeled datasets of both normal and malicious traffic. However, collecting representative anomaly data is a "cat-and-mouse" game: attacks change daily, and labeling them is labor-intensive.

While semi-supervised methods (training only on normal data) exist, they often struggle with "meaningless" anomalies. In computer vision, you can create a fake anomaly by rotating an image or adding noise. If you do that to a network packet, you destroy its semantic structure (like IP headers or TCP flags), creating "garbage" data that doesn't help a model learn the subtle difference between a legitimate request and a sophisticated attack. The challenge is: How do we generate realistic-looking "fake" anomalies for data that has no spatial structure?

Methods

The authors propose a three-stage pipeline:

  1. Feature Extraction (The Reconstruction Stage): They use a GAN-based architecture (Encoder $G_E$, Decoder $G_D$, and Discriminator $D$) to learn a compressed latent representation ($z$) of normal traffic. By forcing the model to reconstruct the packets, the encoder learns to capture the essential "DNA" of normal traffic.
  2. Bidirectional Normalizing Flow (The "Secret Sauce"): Normalizing Flows are a class of models that can transform complex data distributions into simple ones (like a standard Gaussian/Normal distribution) using reversible operations.
  3. Normalization: The model maps the normal latent vectors ($z$) into a standard normal space ($c$).
  4. Generation: To create pseudo-anomalies, the authors add random noise to this standard space and push it backward through the flow. This generates "pseudo-anomaly" latent vectors ($\hat{z}$) that are statistically similar to normal traffic but reside just outside the "normal" boundaries.
  5. Classification: Finally, a simple classifier is trained to tell the difference between the real normal latent vectors ($z$) and the generated pseudo-anomalies ($\hat{z}$).

Crucially, during inference (actual deployment), the model discards the decoder and the flow module. It only uses the Encoder and the Classifier, making it incredibly fast and memory-efficient.

Datasets

The framework was evaluated on three widely used network traffic benchmarks:

  • UNB-CIC Tor and non-Tor: Focuses on detecting traffic hidden within the Tor network.
  • ISCX VPN and non-VPN: Focuses on identifying encapsulated traffic.
  • DataCon2020: A challenging dataset derived from real-world malicious and benign software traffic, characterized by high similarity between normal and abnormal samples.

Key Insights and Ideas

  • Latent Space Manipulation: The biggest "aha" moment is that adding noise to raw packets is useless, but adding noise to the latent representation via a Normalizing Flow creates highly effective training signals. It allows the model to explore the "edge" of normality.
  • Efficiency through Pruning: Many anomaly detection models are bloated. By using the Flow module only as a "teacher" during training to generate samples, the authors can "prune" the model for deployment. Their model uses only 3.91M parameters and 0.02G FLOPs, significantly lower than competitors like GANomaly or PatchCore.
  • Semantic Preservation: Because the pseudo-anomalies are generated in the latent space learned by the reconstruction task, they retain the underlying "logic" of network traffic rather than becoming random bit-noise.

Key Results

The proposed method, dubbed ATD-via-Flows, outperformed several state-of-the-art (SOTA) methods:

  • Detection Accuracy: It achieved an AUROC of 0.8658 on the VPN dataset and 0.8458 on the Tor dataset, beating the next best methods by 6% and 15%, respectively.
  • Computational Efficiency: It maintained the lowest FLOPs (computational cost) among all tested SOTA models, making it ideal for high-speed network nodes where latency is critical.
  • Ablation Success: The authors proved that directly adding noise to the latent vector (without the Normalizing Flow) resulted in much poorer performance, validating the need for the bidirectional flow module.

Limitations and Future Work

The main limitation noted is the performance on the DataCon2020 dataset (AUROC of 0.7292). The authors attribute this to the extreme similarity between benign and malicious encrypted traffic in that specific set.

Future work could involve:

  • Refining Noise Distributions: Currently, noise is sampled from a simple Gaussian. More sophisticated noise-sampling strategies might produce even more "realistic" pseudo-anomalies.
  • Cross-Domain Generalization: While the model generalizes well, further testing on completely "unseen" protocols would strengthen the case for its robustness in wild, unmanaged network environments.

Summary updated

BibTeX
@article{dang2025semi,
  author = {Zhangxuan Dang and Yu Zheng and Xinglin Lian and Chunlei Peng and Qiuyu Chen and Xinbo Gao},
  title = {{Semi-Supervised Learning for Anomaly Traffic Detection via Bidirectional Normalizing Flows}},
  journal = {IEEE Trans. Netw. Serv. Manag},
  year = {2025},
  doi = {10.1109/tnsm.2025.3591533},
}
Figure