Manuscript Offprint

arXiv:2609.37672

NetLexicon: Learning Discrete Behavioral Representations for Encrypted Web Traffic Analysis

Xiangyu Gao, Tong Li, Ziqiang Wang, Yinchao Zhang, Rongbang Wu, Zhenxing Zhang, Jing Hu, Hanlin Huang, Xinle Du, Su Yao, Qi Li, Ke Xu

Abstract

Encrypted Web traffic analysis requires effective representations of observable communication behavior. Existing pretraining methods often adapt NLP/CV objectives and sequence architectures, motivating learning objectives that capture traffic-specific interaction patterns. We present NetLexicon, a discrete pretraining framework that learns reusable behavioral states from unlabeled traffic. It converts contextual traffic windows into discrete states through vector quantization, constructing a compact traffic lexicon. We design two complementary pretraining objectives. State Transition Prediction (STP) forecasts subsequent sequence structure and packet features from observed history, while Statistical Feature Alignment (SFA) grounds learned states in window-level traffic statistics. Together, they guide the lexicon to capture recurring communication behaviors and their evolution.

We evaluate NetLexicon on four benchmarks covering Web application identification, service type identification, and malware detection. NetLexicon improves Macro-F1 by up to 25.5 percentage points over the strongest baseline on each benchmark and reduces fine-tuning time per epoch by up to 23.6Γ— relative to the evaluated baselines. Further analysis shows that the learned discrete states capture recognizable patterns in packet size, timing, and data transfer. These results demonstrate that incorporating observable behavioral structure into pretraining supports effective, efficient, and interpretable representations for encrypted traffic analysis.

1 Introduction

Web activities such as page retrieval and content delivery produce observable traffic patterns even under encryption. Encrypted traffic analysis uses observable packet lengths, directions, and timing to identify websites, applications, and potential threats, supporting Web service management, network measurement, and security [11,28][11, 28]. To support these tasks, supervised models learn to associate observed traffic patterns with application or activity labels, making labeled examples central to their training and adaptation. High-quality labels are expensive to obtain and maintain, while evolving services, applications, and network environments cause distribution shifts that require repeated model updates [43][43]. This motivates learning reusable representations from abundant unlabeled traffic to reduce downstream labeling requirements and adaptation costs.

Self-supervised pretraining offers a promising approach [8, 15, 20, 48]. Inspired by natural language processing (NLP) and computer vision (CV), recent methods learn traffic representations through tokenization, serialization, and masked prediction and

Figure

Figure 1: Model size and classification performance on CipherSpectrum [43]. NetLexicon achieves the highest Macro-F1 with under 2M parameters.

reconstruction objectives, while exploring larger or more complex backbones [5, 20, 40, 48, 49, 51]. Figure 1 compares performance and model size on CipherSpectrum [43], where NetLexicon achieves the highest Macro-F1 with under 2M parameters. This motivates a closer look at objective design: how can traffic-intrinsic behavioral characteristics support efficient learning of meaningful communication representations?

In this paper, traffic semantics refers to the patterns of data transfer and interaction produced by application activities and protocol exchanges, such as concentrated responses following requests, sustained bulk transfer, and intermittent exchanges of small amounts of data. Packet lengths characterize exchange volume, inter-arrival times capture transmission rhythms, and direction changes and burst structures describe endpoint interactions [9,26,28][9, 26, 28]. For example, a short upstream burst followed by large downstream packets in Web traffic may reflect content delivery following a request, while small bidirectional exchanges separated by longer intervals may reflect lightweight background interactions. Their combination and evolution within flow context provide a direct basis for learning traffic semantics.

Existing methods have advanced input organization and sequence modeling. As summarized in Table 1, prior approaches incorporate flow-level context and traffic-specific objectives to varying degrees, while explicitly grounding learned representations in observable behavior remains underexplored. Learning reusable traffic semantics calls for objectives that connect two complementary properties: temporal dependencies make the current interaction predictive of subsequent transmissions, while recurring packet-length, direction, and timing patterns provide observable characteristics of shared behaviors across flows. These observations motivate our central question: how can self-supervised traffic pretraining abstract encrypted interaction patterns into reusable behavioral states and learn their evolution over time?

Gao et al.

Table 1: Comparison of traffic pretraining designs.

MethodHeader OnlyFlow Context1^{1}Traffic Objective2^{2}Behavior Grounding3^{3}
ET-BERT [20]βœ•βœ“βœ“βœ•
YaTC [48]βœ•βœ“βœ•βœ•
NetMamba [40]βœ•βœ“βœ•βœ•
TrafficFormer [51]βœ•βœ“βœ“βœ•
Pcap-Encoder [49]βœ“βœ•βœ“βœ•
NetLexicon (Ours)βœ“βœ“βœ“βœ“

1^{1} The model encodes multiple packets to capture inter-packet dependencies.

2^{2} The pretraining task is tailored to traffic characteristics.

3^{3} Representations are aligned with observable traffic behavior.

We introduce NetLexicon 1^{1} , a discrete pretraining framework that encodes packet and burst sequences within flow-level context using header fields and metadata such as packet sizes and timing. It maps window representations to a finite set of codewords through vector quantization [38], constructing a traffic lexicon. Similar window-level behaviors share states, whose sequence describes how communication evolves.

To learn states that capture how traffic evolves and what behavior each window exhibits, we design two self-supervised pretraining objectives: State Transition Prediction (STP) and Statistical Feature Alignment (SFA). STP predicts subsequent sequence structure and packet features from observed context, encouraging the learned states to preserve information about future communication behavior. SFA aligns each quantized state with packet-length, direction, and inter-arrival-time statistics from the same window, grounding the state in observable behavioral characteristics. Together, our objectives shape the traffic lexicon through temporal prediction and statistical alignment, enabling it to capture recurring behaviors and their evolution.

We pretrain NetLexicon on backbone and QUIC/HTTP3 application traffic [6, 12] and evaluate it on four tasks. Website fingerprinting on CSTNET [20] and encrypted application fingerprinting on CipherSpectrum [43] assess its ability to distinguish Web-related communication behaviors. Service type identification on ISCXVPN [9] and malware detection on USTC-TFC [41] assess its broader applicability. We further examine interpretability through associations between representations and behavioral statistics, codebook utilization, and codeword cases, alongside training and inference overhead.

We make the following contributions:

  • Reframing traffic pretraining. We connect packet lengths, inter-arrival times, and directions to interaction patterns, organizing encrypted traffic representations through shared behavioral states and their evolution.

  • Learning a discrete traffic lexicon. We introduce NetLexicon, which combines vector quantization with our STP and SFA objectives to learn predictive and behaviorally grounded discrete states from unlabeled traffic.

  • Effectiveness, efficiency, and interpretability. Across four Web-related and broader traffic classification tasks, NetLexicon

improves Macro-F1 by up to 25.5 percentage points, reduces fine-tuning time per epoch by up to 23.6Γ—23.6 \times, and learns interpretable states aligned with meaningful communication behaviors.

References (56)