Pointing at the Bad Bits: Dense Localization on Bit-Aligned Packet Images

Neural traffic analyzers built on "traffic images" (packets laid out as rows of a grid, header and payload bytes as pixels) are now very good at one question: what is this flow? They can name the application, the device, or the malware family. They cannot answer the question an operator asks next: which packet, and which field inside it, made this flow suspicious? The reason is architectural. These models compress the grid into a single label, and the compression discards exactly the coordinates that would answer the second question. We propose to keep those coordinates. We would train a model that outputs a mask the same size as the traffic image, marking the individual header fields and payload bytes that are anomalous. Two things make this work: a layout in which every field always sits in the same column, and a decoder that rebuilds full resolution rather than being thrown away after pretraining.

The bet is specific and falsifiable. Many packet anomalies are only visible across packets. Examples are a Time-to-Live that jumps mid-flow, a sequence number that breaks monotonicity, or a source field that should be constant but is not. In a bit-aligned grid, such an anomaly is a vertical break in a column. We claim that a model with explicit column-wise context, plus a full-resolution decoder with skip connections, localizes these breaks far better than three cheaper options. The first is a saliency map read off a flow classifier. The second is a one-dimensional tagger over the flattened byte sequence. The third is simply thresholding the reconstruction error of a pretrained masked autoencoder. If the third option matches us, that is itself a useful finding, and the experiments are designed so we would learn it.

What exists and where this sits

Three pieces of prior work supply the method. nPrint and New Directions in Automated Traffic Analysis show that naive byte dumps drift when header lengths vary, so the same field lands in different columns. nPrint fixes this by giving every header bit a fixed position and zero-filling absent headers. We adopt that layout because a dense output is only meaningful if "column 64" means the same field in every packet.

YaTC pretrains a masked autoencoder, meaning a model that hides 90% of the grid's patches and learns to reconstruct them, on a multi-level flow matrix. Like the methods below, it motivates our proposal. It then discards the decoder and pools each packet row into one vector before classifying. It reports F1 of 99.72% on ISCXTor2016, which shows that flow-level labels are close to saturated on these benchmarks. We keep YaTC's pretraining recipe but not its pooling.

gen2seg supplies the central architectural argument. Discriminative models learn to ignore where things are, while dense tasks need features that move when the input moves. Keeping the full generative decoder preserved thin structures: 51.4 mIoU on the iShape wire and branch benchmark versus 16.8 for SAM. A one-bit-wide column break in a packet grid is the traffic analogue of a wire. Work on U-Net skip connections carries the same lesson for thin geometry. Examples are Hao Chen et al. on root gaps and Xinyu Li et al. on eyelashes.

The existing crossover work is instructive mainly in what it does not do. The Traffic4cast U-Nets (Traffic4cast 2019, Xu et al.) and ZipNet-GAN preserve spatial detail in geographic grids, where neighbouring cells really are neighbours. None of them touches packet semantics. NetDiffusion runs a skip-connected diffusion U-Net over nPrint bitmaps. It still produces packets with broken checksums and sequence numbers, and it needs a hand-built dependency-tree repair stage afterwards. That failure acts as a constraint on our design. Pixel-level fidelity by itself does not capture logical dependencies between fields, so our model must have an explicit path for context along columns rather than relying on local convolution alone. No work in the file produces a field- or byte-level anomaly mask on packet grids.

Core Claim

On bit-aligned flow grids, two ingredients together yield much better field-level anomaly localization than either ingredient alone, and better than saliency- or sequence-based alternatives. The first ingredient is a pretrained reconstruction decoder that is retained and fine-tuned for dense output. The second is attention along both the packet axis and the field axis. The gain should be concentrated on cross-packet anomalies, and it should vanish if the nPrint alignment is replaced by raw byte offsets.

Research Program

Representation. The input is a flow of the first $M$ packets in nPrint format, one row per packet. Header bits sit at fixed columns, followed by a fixed budget of payload bytes, as in YaTC's layout. Patches are deliberately thin: one packet row by a small field-sized width. This keeps the patch grid close to field resolution.

Model. The encoder is a factorized-attention transformer. Row attention mixes fields within a packet. Column attention mixes the same field across packets, so a single field's history across the flow is one hop away. We pretrain it YaTC-style with 90% masking on unlabeled flows. We then keep the decoder. We add skip connections from the patch embeddings to the decoder's output head, which predicts an anomaly probability per bit (header) or per byte (payload). Fine-tuning trains the output head on the mask labels described below, together with a light flow-level head. The flow-level head lets us check that dense training does not cost detection accuracy.

Labels. No benchmark in the file has byte-level masks, so we must build one, and we will state its limits plainly. We take real flows from ISCXVPN2016, USTC-TFC2016, CICIoT2022, and the NetDiffusion ten-application corpus. We then inject controlled perturbations with exact ground-truth masks. These fall into four families. Single-packet field corruption covers illegal flag combinations and bad checksums. Cross-packet inconsistency covers TTL jumps, sequence breaks, and a spoofed source mid-flow. Payload splicing inserts byte runs from a different application or from known exploit samples. Header covert channels encode data in normally-constant fields.

A second, naturally occurring label source is NetDiffusion-style synthetic traffic. For these packets a protocol parser identifies exactly which bits violate the RFCs, which gives real, non-injected errors with exact masks. A third source is attack traffic in CICIoT2022 and CICIDS 2017, which gives coarser row-level (packet-level) masks from attack windows. All splits are temporal, following the drift warnings of Kolcun et al..

Baselines

The naive reference point needs no model at all. For each column we compute the per-field value frequency on training flows and flag bits whose value has low empirical probability given the flow's first packet. This is a field-wise novelty score. It is what a rigorous nPrint user could write in an afternoon, and any learned method must clearly beat it on cross-packet anomalies to justify itself.

The strongest existing method is YaTC used as a flow-level detector, with localization read off by gradient-times-input and attention rollout mapped back to grid positions. It is the strongest competitor because it is the best-reported image-based flow classifier in the file (F1 99.72% on ISCXTor2016). Saliency from a strong classifier is also the default way practitioners would try to localize. We will train it on the same flows, with flow-level labels derived from the masks (anomalous if any bit is flagged), using the same pretraining corpus and an equal hyperparameter-search budget in GPU hours. No reported result was found on Lacuna for field-level localization by YaTC or any traffic classifier, so the comparison is new. Beating it means higher area under the precision-recall curve over bit positions, and higher field-level IoU, at matched flow-level F1.

The second strong competitor is the same MAE with no fine-tuning. We score each bit by its reconstruction error when that patch is masked out, averaging over several random masks. This baseline is cheap, unsupervised, and uses exactly our key ingredient, the retained decoder. We treat it as a serious rival rather than a strawman.

The third competitor is a one-dimensional token-tagging transformer over the flattened flow, with learned absolute positions and the same parameter count and pretraining. It tests whether the two-dimensional layout matters or whether positions alone suffice.

Four ablations isolate the proposal's ingredients. The first uses a randomly initialized decoder in place of the pretrained one. The second removes the skip connections. The third drops column attention, so that each packet is processed alone. The fourth replaces nPrint alignment with raw byte offsets. Our claim predicts large drops from the column-attention and alignment ablations on the cross-packet family, and small drops on single-packet corruption.

Why not just…?

Why not just take saliency maps from a strong flow classifier? Saliency explains what a classifier used, not where the anomaly is. A classifier trained to invariance, as gen2seg argues, has little reason to keep single-bit coordinates. YaTC's row pooling removes within-packet position before the final layers. The comparison at matched flow-level F1 settles this directly. If saliency reaches comparable field IoU, the dense decoder is unnecessary, and we will say so.

Why not just threshold the MAE's reconstruction error? This is the real threat, because it uses the same retained decoder with no labels. Its known weakness is that reconstruction error is high wherever fields are inherently unpredictable, such as payload bytes of encrypted traffic, random IDs, and checksums. That weakness should produce many false alarms exactly where anomalies are rare. We expect supervised dense fine-tuning to win mainly on precision. We also expect the gap to be largest on payload splicing inside encrypted flows. If the gap is small everywhere, the contribution shrinks to "keep the decoder," which is still a finding YaTC-style pipelines currently miss.

Why not just flatten to a sequence and tag tokens? Once nPrint fixes positions, a sequence model with absolute position embeddings can in principle represent column identity. The two-dimensional claim is therefore not about images as such. It is about making "same field, previous packet" a direct neighbour instead of a distance of hundreds of tokens. The matched-parameter 1D tagger will show whether that inductive bias pays off on cross-packet anomalies. The row-only ablation shows the complementary case. If the 1D tagger ties, we will report the result as evidence that alignment, not layout, carries the benefit.

Why not just use a protocol parser or rule engine? For header RFC violations, a parser is exact, and we use it to generate labels. Rules do not exist for payload splicing, covert channels in legal-but-unusual fields, or novel exploits. nPrint documents that rigid signature tools such as p0f miss variants they were not written for. We test this directly by training on some perturbation families and evaluating on held-out ones, where no rule would fire.

Proposed Experiments and Decisive Checks

The main metrics are area under the precision-recall curve over bit and byte positions, IoU at the level of whole header fields, and packet-level localization accuracy. We also report flow-level F1, to confirm that dense output costs nothing on the task existing systems already solve.

The decisive check is a two-by-two split. One axis is single-packet versus cross-packet anomaly families. The other is aligned versus unaligned layout. The proposal is supported only if the full model's margin over the 1D tagger and the reconstruction-error baseline is concentrated in the aligned, cross-packet cell.

The second check is transfer to anomalies that were never injected. We train only on injected perturbations and then evaluate on two things. The first is parser-labelled RFC violations in NetDiffusion-generated flows. Success there would suggest the model could replace part of that paper's hand-built repair stage as a learned checker. The second is packet-level attack windows in CICIoT2022. Failure there would mean the model has learned the injection artifacts rather than anomalies, which is the main risk of synthetic labels.

The third check reuses the SEIS subspace scores from SEIS to measure whether the encoder's features shift consistently when we cyclically shift packet order or move fields within the payload budget. This tests whether the fine-tuned model is actually coordinate-tracking in the way the gen2seg argument requires.