Abstract
Network traffic analysis (NTA) is critical for cybersecurity, yet traditional machine learning models often suffer from poor generalization and high development costs. TrafficLLM addresses these challenges by adapting Large Language Models (LLMs) to the network traffic domain through a novel dual-stage fine-tuning framework. By bridging the modality gap between natural language and raw packet data, TrafficLLM achieves state-of-the-art performance in threat detection and traffic generation, outperforming existing methods by significant margins while maintaining efficiency.
1. Introduction
Traditional machine learning (ML) models for network traffic analysis are typically "brittle," relying on handcrafted features and designed for narrow, single-task applications. This leads to low generalization when faced with "concept drift" or novel attack vectors. While LLMs offer superior reasoning and generalization capabilities, they are not natively suited for network traffic. Raw packets consist of structured, heterogeneous metadata (IPs, ports, flags) that create a significant modality gap when processed by standard natural language tokenizers. Furthermore, the computational cost of full model retraining for every traffic pattern change is prohibitive.
2. Methodology
TrafficLLM introduces three core technical innovations to bridge the gap between LLMs and network security operations.
2.1 Traffic-Domain Tokenization
Standard LLM tokenizers, such as Byte Pair Encoding (BPE), often fragment protocol fields into nonsensical tokens. TrafficLLM utilizes a specialized tokenizer trained on large-scale traffic corpora. This approach preserves field names and common values, reducing average token length by approximately 50% and significantly improving processing efficiency.
2.2 Dual-Stage Tuning Pipeline
To prevent performance degradation during multi-task learning, TrafficLLM employs a two-step training process:
- Natural Language Instruction Tuning: Orients the model to the specific task (e.g., "Identify the malware family in this flow").
- Task-Specific Traffic Tuning: Trains the model on the underlying patterns of the traffic data itself.
2.3 Extensible Adaptation (EA-PEFT)
Instead of full parameter fine-tuning, the framework leverages P-Tuning v2. This allows the core LLM knowledge to remain frozen while training modular Parameter-Efficient Fine-Tuning (PEFT) sets. This modularity enables rapid updates for new threats while drastically reducing resource requirements.
3. Experimental Setup and Datasets
The study utilized a comprehensive LLM tuning dataset for the traffic domain, comprising approximately 0.4 million samples across 10 scenarios and 229 traffic types. Key tasks included Malware Traffic Detection (MTD), Botnet Detection (BND), and Web Attack Detection (WAD). Generalization was benchmarked using the APP-53 and DAPT 2020 datasets to evaluate performance on unseen "zero-day" data.
4. Results and Discussion
TrafficLLM demonstrates superior performance across detection, generalization, and efficiency metrics.
4.1 Detection and Generalization
The model achieved F1-scores of 0.9875, outperforming state-of-the-art methods like ET-BERT by up to 80.12% in specific scenarios. Crucially, on unseen traffic data, TrafficLLM showed an 18.6% performance improvement over traditional ML models, highlighting its robustness against zero-day threats.
4.2 Generation Fidelity and Efficiency
In synthetic traffic generation, the model achieved an F1-score of 0.9483, producing packets nearly indistinguishable from real traffic. Through INT4 quantization, inference latency was reduced to 0.14s per sample, making it 3.5x faster than specialized deep learning models like FS-Net.
5. Conclusion
TrafficLLM successfully adapts LLMs for network traffic analysis by addressing the modality gap and training inefficiencies. While current inference speeds are better suited for forensic analysis than real-time backbone filtering, the framework provides a scalable, high-performance foundation for future AI-driven security operations. Future work will explore smaller language models and more aggressive compression to further reduce hardware requirements.
Summary updated