A Contrastive Dual-Task Framework for Few-Shot Traffic Classification in IoT Networks
Abstract
1. Introduction
- We propose CDTF, a contrastive dual-task hybrid pre-training framework for encrypted traffic classification in IoT networks. CDTF introduces contrastive representation learning into hybrid pre-training by organizing traffic samples in a shared embedding space, where transferable representations can be learned from available base-class data and efficiently adapted to novel traffic categories with limited task-specific labeled samples.
- We design two pre-training tasks, namely Supervised Triplet Pretraining (STP) and Dynamic Burst Masking (DBM), to address inter-class representation confusion and contextual instability in encrypted traffic. STP constructs triplets from base-class annotations to explicitly enhance intra-class compactness and inter-class separability, thereby mitigating the influence of shared network components and common communication libraries. DBM reconstructs masked BURST tokens in a self-supervised manner to capture stable contextual dependencies and improve robustness against noise, local perturbations, and distribution shifts.
- Extensive experiments on seven public datasets and two custom datasets demonstrate that CDTF achieves state-of-the-art performance across multi-task, few-shot, and distribution-shift scenarios. CDTF improves Precision over the strongest baseline by 4.14 percentage points in website traffic classification, 4.61 percentage points under the few-shot setting, and 2.89 percentage points under cipher-suite distribution shift, with all gains statistically significant under paired t-tests ().
2. Related Work
2.1. Feature-Based Traffic Classification
2.2. Deep Learning Methods
2.3. Pretraining-Based Methods
3. Methodology
3.1. Data Preprocessing and Triplet Construction
- Bidirectional Flow Parsing via Five-Tuple
- BURST Segmentation and Feature Construction
- Class Categorization and Triplet Construction
3.2. Hybrid Pre-Training
3.2.1. Supervised Triplet Pretraining
3.2.2. Dynamic Burst Masking
3.3. Fine-Tuning
4. Experiment
4.1. Experimental Setup
4.1.1. Datasets
4.1.2. Evaluation Metrics
4.1.3. Implementation
4.2. Multi-Task Evaluations
4.3. Few-Shot and Distribution Shift Evaluations
4.4. Complexity Analyses
4.5. Ablation Study
5. Conclusions
Author Contributions
Funding
Institutional Review Board Statement
Informed Consent Statement
Data Availability Statement
Acknowledgments
Conflicts of Interest
References
- Shen, M.; Ye, K.; Liu, X.; Zhu, L.; Kang, J.; Yu, S.; Li, Q.; Xu, K. Machine Learning-Powered Encrypted Network Traffic Analysis: A Comprehensive Survey. IEEE Commun. Surv. Tutor. 2023, 25, 791–824. [Google Scholar] [CrossRef]
- Sharma, A.; Lashkari, A.H. A survey on encrypted network traffic: A comprehensive survey of identification/classification techniques, challenges, and future directions. Comput. Netw. 2025, 257, 110984. [Google Scholar] [CrossRef]
- Elmaghraby, R.T.; Abdel Aziem, N.M.; Sobh, M.A.; Bahaa-Eldin, A.M. Encrypted network traffic classification based on machine learning. Ain Shams Eng. J. 2024, 15, 102361. [Google Scholar] [CrossRef]
- Chen, Z.; Cheng, G.; Niu, D.; Zhao, Y.; Zhou, Y.; Jiang, S. Ultimate Encrypted Traffic Feature Engineering: HTTPS Encrypted Traffic Classification Using Restored Application Data Unit Length. IEEE Trans. Dependable Secur. Comput. 2025, 23, 1290–1307. [Google Scholar] [CrossRef]
- Wang, H.; Li, J.; Wu, H.; Hovy, E.; Sun, Y. Pre-Trained Language Models and Their Applications. Engineering 2023, 25, 51–65. [Google Scholar] [CrossRef]
- Ma, Y.; Li, Z.; Xue, H.; Chang, J. A balanced supervised contrastive learning-based method for encrypted network traffic classification. Comput. Secur. 2024, 145, 104023. [Google Scholar] [CrossRef]
- Sen, S.; Spatscheck, O.; Wang, D. Accurate, scalable in-network identification of p2p traffic using application signatures. In Proceedings of the 13th International Conference on World Wide Web (WWW ’04), New York, NY, USA, 17–20 May 2004; pp. 512–521. [Google Scholar] [CrossRef]
- Deri, L.; Martinelli, M.; Bujlow, T.; Cardigliano, A. nDPI: Open-source high-speed deep packet inspection. In Proceedings of the 2014 International Wireless Communications and Mobile Computing Conference (IWCMC), Nicosia, Cyprus, 4–8 August 2014; pp. 617–622. [Google Scholar] [CrossRef]
- Taylor, V.F.; Spolaor, R.; Conti, M.; Martinovic, I. AppScanner: Automatic Fingerprinting of Smartphone Apps from Encrypted Network Traffic. In Proceedings of the 2016 IEEE European Symposium on Security and Privacy (EuroS&P), Saarbruecken, Germany, 21–24 March 2016; pp. 439–454. [Google Scholar] [CrossRef]
- Panchenko, A.; Lanze, F.; Zinnen, A.; Henze, M.; Pennekamp, J.; Wehrle, K.; Engel, T. Website Fingerprinting at Internet Scale. In Proceedings of the 23rd Annual Network and Distributed System Security Symposium, San Diego, CA, USA, 21–24 February 2016; Internet Society: Reston, VA, USA, 2016. [Google Scholar] [CrossRef]
- Al-Naami, K.; Chandra, S.; Mustafa, A.; Khan, L.; Lin, Z.; Hamlen, K.; Thuraisingham, B. Adaptive encrypted traffic fingerprinting with bi-directional dependence. In Proceedings of the 32nd Annual Conference on Computer Security Applications (ACSAC ’16), New York, NY, USA, 5–8 December 2016; pp. 177–188. [Google Scholar] [CrossRef]
- Anderson, B.; McGrew, D. Machine Learning for Encrypted Malware Traffic Classification: Accounting for Noisy Labels and Non-Stationarity. In Proceedings of the 23rd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining (KDD ’17), New York, NY, USA, 13–17 August 2017; pp. 1723–1732. [Google Scholar] [CrossRef]
- Niu, W.; Zhuo, Z.; Zhang, X.; Du, X.; Yang, G.; Guizani, M. A Heuristic Statistical Testing Based Approach for Encrypted Network Traffic Identification. IEEE Trans. Veh. Technol. 2019, 68, 3843–3853. [Google Scholar] [CrossRef]
- Shamsimukhametov, D.; Kurapov, A.; Liubogoshchev, M.; Khorov, E. Early Traffic Classification With Encrypted ClientHello: A Multi-Country Study. IEEE Access 2024, 12, 142979–142993. [Google Scholar] [CrossRef]
- Sengupta, S.; Ganguly, N.; De, P.; Chakraborty, S. Exploiting Diversity in Android TLS Implementations for Mobile App Traffic Classification. In Proceedings of the The World Wide Web Conference (WWW ’19), New York, NY, USA, 13–17 May 2019; pp. 1657–1668. [Google Scholar] [CrossRef]
- Sirinam, P.; Imani, M.; Juarez, M.; Wright, M. Deep Fingerprinting: Undermining Website Fingerprinting Defenses with Deep Learning. In Proceedings of the 2018 ACM SIGSAC Conference on Computer and Communications Security (CCS ’18), New York, NY, USA, 15–19 October 2018; pp. 1928–1943. [Google Scholar] [CrossRef]
- Liu, C.; He, L.; Xiong, G.; Cao, Z.; Li, Z. FS-Net: A Flow Sequence Network For Encrypted Traffic Classification. In Proceedings of the IEEE INFOCOM 2019—IEEE Conference on Computer Communications, Paris, France, 29 April–2 May 2019; pp. 1171–1179. [Google Scholar] [CrossRef]
- Karagiannis, T.; Papagiannaki, K.; Faloutsos, M. BLINC: Multilevel traffic classification in the dark. In Proceedings of the 2005 Conference on Applications, Technologies, Architectures, and Protocols for Computer Communications (SIGCOMM ’05), New York, NY, USA, 22–26 August 2005; pp. 229–240. [Google Scholar] [CrossRef]
- Van Ede, T.; Bortolameotti, R.; Continella, A.; Ren, J.; Dubois, D.J.; Lindorfer, M.; Choffnes, D.; Van Steen, M.; Peter, A. Flowprint: Semi-supervised mobile-app fingerprinting on encrypted network traffic. In Proceedings of the Network and distributed system security symposium (NDSS), San Diego, CA, USA, 23–26 February 2020; Volume 27. [Google Scholar] [CrossRef]
- Shen, M.; Zhang, J.; Zhu, L.; Xu, K.; Du, X. Accurate Decentralized Application Identification via Encrypted Traffic Analysis Using Graph Neural Networks. IEEE Trans. Inf. Forensics Secur. 2021, 16, 2367–2380. [Google Scholar] [CrossRef]
- Li, X.; Guo, J.; Song, Q.; Xie, J.; Sang, Y.; Zhao, S.; Zhang, Y. Listen to Minority: Encrypted Traffic Classification for Class Imbalance with Contrastive Pre-Training. In Proceedings of the 2023 20th Annual IEEE International Conference on Sensing, Communication, and Networking (SECON), Madrid, Spain, 11–14 September 2023; pp. 447–455. [Google Scholar] [CrossRef]
- Zhang, H.; Xiao, X.; Yu, L.; Li, Q.; Ling, Z.; Zhang, Y. One Train for Two Tasks: An Encrypted Traffic Classification Framework Using Supervised Contrastive Learning. arXiv 2024, arXiv:2402.07501. [Google Scholar] [CrossRef]
- Lin, X.; Xiong, G.; Gou, G.; Li, Z.; Shi, J.; Yu, J. ET-BERT: A Contextualized Datagram Representation with Pre-training Transformers for Encrypted Traffic Classification. In Proceedings of the ACM Web Conference 2022 (WWW ’22), New York, NY, USA, 25–29 April 2022; pp. 633–642. [Google Scholar] [CrossRef]
- Zhao, R.; Zhan, M.; Deng, X.; Wang, Y.; Wang, Y.; Gui, G.; Xue, Z. Yet another traffic classifier: A masked autoencoder based traffic transformer with multi-level flow representation. In Proceedings of the Thirty-Seventh AAAI Conference on Artificial Intelligence and Thirty-Fifth Conference on Innovative Applications of Artificial Intelligence and Thirteenth Symposium on Educational Advances in Artificial Intelligence (AAAI’23/IAAI’23/EAAI’23); AAAI Press: Washington, DC, USA, 2023. [Google Scholar] [CrossRef]
- Zhou, G.; Guo, X.; Liu, Z.; Li, T.; Li, Q.; Xu, K. TrafficFormer: An Efficient Pre-trained Model for Traffic Data. In Proceedings of the 2025 IEEE Symposium on Security and Privacy (SP), San Francisco, CA, USA, 12–15 May 2025; pp. 1844–1860. [Google Scholar] [CrossRef]
- Lin, X.; He, L.; Gou, G.; Yu, J.; Guan, Z.; Li, X.; Guo, J.; Xiong, G. CETP: A novel semi-supervised framework based on contrastive pre-training for imbalanced encrypted traffic classification. Comput. Secur. 2024, 143, 103892. [Google Scholar] [CrossRef]
- Zhan, M.; Yang, J.; Jia, D.; Fu, G. EAPT: An encrypted traffic classification model via adversarial pre-trained transformers. Comput. Netw. 2025, 257, 110973. [Google Scholar] [CrossRef]
- Gil, G.D.; Lashkari, A.H.; Mamun, M.S.I.; Ghorbani, A.A. Characterization of Encrypted and VPN Traffic using Time-related Features. In Proceedings of the 2nd International Conference on Information Systems Security and Privacy—ICISSP; INSTICC; SciTePress: Setúbal, Portugal, 2016; pp. 407–414. [Google Scholar] [CrossRef]
- Moustafa, N.; Ahmed, M.; Ahmed, S. Data Analytics-Enabled Intrusion Detection: Evaluations of ToN_IoT Linux Datasets. In Proceedings of the 2020 IEEE 19th International Conference on Trust, Security and Privacy in Computing and Communications (TrustCom), Guangzhou, China, 29 December 2020–1 January 2021; pp. 727–735. [Google Scholar] [CrossRef]
- Neto, E.C.P.; Dadkhah, S.; Ferreira, R.; Zohourian, A.; Lu, R.; Ghorbani, A.A. CICIoT2023: A Real-Time Dataset and Benchmark for Large-Scale Attacks in IoT Environment. Sensors 2023, 23, 5941. [Google Scholar] [CrossRef] [PubMed]
- Gahtan, B.; Shahla, R.J.; Bronstein, A.M.; Cohen, R. Exploring QUIC Dynamics: A Large-Scale Dataset for Encrypted Traffic Analysis. arXiv 2025, arXiv:2410.03728. [Google Scholar] [CrossRef]
- Wickramasinghe, N.; Shaghaghi, A.; Tsudik, G.; Jha, S. SoK: Decoding the Enigma of Encrypted Network Traffic Classifiers. In Proceedings of the 2025 IEEE Symposium on Security and Privacy (SP), San Francisco, CA, USA, 12–15 May 2025; pp. 1825–1843. [Google Scholar] [CrossRef]
- Luo, X.; Liu, C.; Xiong, G.; Gou, G.; Li, Z.; Shi, J.; Guo, L.; Fang, B. BAPTISM: A Robust Framework for Encrypted Malicious Traffic Identification With Low-Quality Training Data. IEEE Trans. Inf. Forensics Secur. 2026, 21, 960–975. [Google Scholar] [CrossRef]




| Stage | Task | Dataset | Flow | Class |
|---|---|---|---|---|
| Hybrid Pre-training | - | CIC-ISCX2016 (NonVPN) | 40 k | 10 |
| ToN-IoT | 27 k | 9 | ||
| CSTNET-TLS1.3 | 54 k | 120 | ||
| Fine-tuning | Application Classification | CIC-ISCX2016 (VPN) | 22 k | 11 |
| Attack Classification | CIC-IoT2023 | 60 k | 34 | |
| Website Traffic Classification | VisQUIC | 46 k | 18 | |
| Malware Detection | CIC-AndMal2017 | 100 k | 4/11/11 | |
| CipherSpectrum | 41 k | 41 | ||
| Distribution Shift | Group1 | 12 k | 3 | |
| Group2 | 13 k | 3 |
| Task | Application Classification | Attack Classification | Website Traffic Classification | |||
| Dataset | CIC-ISCX2016 | CIC-IoT2023 | VisQUIC | |||
| Method | PRE | REC | PRE | REC | PRE | REC |
| AppScanner | ||||||
| CUMUL | ||||||
| GraphDApp | ||||||
| ET-BERT | ||||||
| TrafficFormer | ||||||
| CLE-TFE | ||||||
| CDTF | ||||||
| Task | Malware Detection | |||||
| Dataset | CIC-AndMal2017 (Adware) | CIC-AndMal2017 (SMSmalware) | CIC-AndMal2017 (Scareware) | |||
| Method | PRE | REC | PRE | REC | PRE | REC |
| AppScanner | ||||||
| CUMUL | ||||||
| GraphDApp | ||||||
| ET-BERT | ||||||
| TrafficFormer | ||||||
| CLE-TFE | ||||||
| CDTF | ||||||
| Dataset | CIC-ISCX2016 | CIC-IoT2023 | VisQUIC | |||
|---|---|---|---|---|---|---|
| Method | PRE | REC | PRE | REC | PRE | REC |
| AppScanner | ||||||
| CUMUL | ||||||
| GraphDApp | ||||||
| CLE-TFE | ||||||
| ET-BERT | ||||||
| TrafficFormer | ||||||
| CDTF | ||||||
| Method | AES-256 | ChaChaPoly | Mix | |||
|---|---|---|---|---|---|---|
| PRE | REC | PRE | REC | PRE | REC | |
| AppScanner | ||||||
| CUMUL | ||||||
| GraphDApp | ||||||
| CLE-TFE | ||||||
| ET-BERT | ||||||
| TrafficFormer | ||||||
| CDTF | ||||||
| Method | Model Size (MB) | Fine-Tuning Time (s) | Inference Time (s) | Performance | |||
|---|---|---|---|---|---|---|---|
| AC | TC | WTC | MD | ||||
| AppScanner | 8 | 109.18 | 0.45 | ||||
| CUMUL | 3 | 96.21 | 0.12 | ||||
| GraphDApp | 15 | 40.45 | 1.07 | ||||
| CLE-TFE | 200 | 464.99 | 30.59 | ||||
| ET-BERT | 504 | 272.92 | 14.83 | ||||
| TrafficFormer | 506 | 158.61 | 7.39 | ||||
| CDTF | 170 | 92.58 | 4.47 | ||||
| Method | Metric | |||
|---|---|---|---|---|
| ACC | PRE | REC | F1 | |
| w/o DBM | 75.22 ± 1.33 | 69.98 ± 0.95 | 70.02 ± 1.88 | 69.91 ± 0.52 |
| w/o STP | 60.25 ± 0.48 | 59.10 ± 0.32 | 57.77 ± 0.52 | 58.06 ± 0.83 |
| w/o hybrid pre-training | 59.26 ± 2.25 | 47.81 ± 1.63 | 52.15 ± 1.04 | 49.99 ± 1.54 |
| full CDTF | 99.38 ± 0.14 | 99.82 ± 0.04 | 99.01 ± 0.26 | 99.33 ± 0.10 |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2026 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license.
Share and Cite
Lu, Z.; Chen, M.; Cui, S.; Zhao, B.; Zheng, Y. A Contrastive Dual-Task Framework for Few-Shot Traffic Classification in IoT Networks. Sensors 2026, 26, 3471. https://doi.org/10.3390/s26113471
Lu Z, Chen M, Cui S, Zhao B, Zheng Y. A Contrastive Dual-Task Framework for Few-Shot Traffic Classification in IoT Networks. Sensors. 2026; 26(11):3471. https://doi.org/10.3390/s26113471
Chicago/Turabian StyleLu, Zikui, Mo Chen, Sailong Cui, Bingbing Zhao, and Yaoyuan Zheng. 2026. "A Contrastive Dual-Task Framework for Few-Shot Traffic Classification in IoT Networks" Sensors 26, no. 11: 3471. https://doi.org/10.3390/s26113471
APA StyleLu, Z., Chen, M., Cui, S., Zhao, B., & Zheng, Y. (2026). A Contrastive Dual-Task Framework for Few-Shot Traffic Classification in IoT Networks. Sensors, 26(11), 3471. https://doi.org/10.3390/s26113471

