Skip to main content
Back

DNS-GT Beats Word2Vec by Catching Malicious Domains in Context

A new Transformer with graph attention learns domain name embeddings from raw DNS traffic, beating Word2Vec baselines on malicious domain classification.

Pro

  • DNS-GT combines a Transformer with graph attention to learn context-aware domain embeddings from raw DNS traffic (paper).
  • Pre-trained self-supervised with masked language modeling on 13M queries from the TI-2016 campus DNS dataset.
  • Reaches 0.848 AUC on malicious domain classification, beating Word2Vec-CBOW (0.779) and SkipGram (0.656).
  • Ablation shows attention is critical: removing it drops AUC by 0.438; host embeddings add another 0.086.
  • Requires end-to-end fine-tuning; external classifiers like SVM cannot exploit the contextual embeddings.
  • Code and appendix released at github.com/m-altieri/DNS-GT; cannot detect multi-host attacks like fast-flux.

Network intrusion detection has quietly been shifting from hand-crafted signatures to learned representations, and DNS traffic keeps showing up as the most attractive substrate: it is abundant, protocol-simple, and touches almost every application on a network. A team from the European Commission's Joint Research Centre, American University, and the University of Bari has now proposed DNS-GT, a Transformer that borrows the masked language modeling recipe from BERT and fuses it with a graph attention network to learn context-aware domain embeddings from raw DNS logs.

Why Word2Vec was never quite enough

Existing DNS embedding approaches based on Word2Vec variants aggregate local co-occurrence patterns and lack a deep understanding of context and semantics. That is a real problem in security, where the same domain (say a legitimate Mozilla CDN) can be benign in one traffic pattern and a spoofing signal in another. Supervised methods, meanwhile, run into the usual wall: labeling DNS data is costly and often incomplete, and privacy concerns further restrict labeled corpora.

DNS-GT tries to fix both issues at once. It pre-trains on unlabeled traffic using masked language modeling, then fine-tunes on small labeled sets for downstream tasks like malicious domain classification or botnet detection.

How the model is put together

The architecture keeps the Transformer encoder skeleton but makes three security-specific changes:

  • The self-attention is generalized with a permutation-equivariant graph attention network, so token position inside a sequence does not matter and the model becomes robust to small network timing perturbations.
  • Each query is represented as a pair of tokens, a host and a domain, whose embeddings are combined with a weighting coefficient. Setting the coefficient to 1 lets operators drop host information entirely when privacy is a concern.
  • External knowledge can be injected as an adjacency matrix, restricting which tokens attend to which and cleanly excluding padding tokens from attention.

Because DNS queries within a sequence do not have a natural order (they often arrive in bursts), positional encodings are dropped. Sequences are built from queries of the same host, with three tested strategies: fixed-length sliding windows, a greedy time-based grouper, and DBSCAN clustering along the temporal axis.

Cosine similarity between domains in the same sequence versus random pairs

The dataset and training setup

Experiments run on the TI-2016 dataset: ten days of real DNS traffic from a campus network of 4,000 hosts, totaling around 296 million DNS packets and 85 GB of PCAPs. Seven days feed pre-training (about 13 million queries), three days go to evaluation. Ground truth for malicious domains comes from a public blacklist that flagged roughly 169,000 domains in the corpus.

Key hyperparameters: 256-dimensional embeddings, 8 multi-head GAT blocks, 8 attention heads, sequences of length 32, a vocabulary trimmed to the 30,000 most frequent domains, and 1 million training steps on two NVIDIA RTX A6000 GPUs. The masking scheme mirrors BERT: mostly replace with a mask token, sometimes with a random domain, sometimes leave unchanged.

What the numbers say

On malicious domain classification with density-based sequencing, DNS-GT fine-tuned end-to-end reaches an AUC of 0.848 and F1 of 0.654 at the best threshold, versus 0.779 AUC and 0.596 F1 for Word2Vec-CBOW and 0.656 for SkipGram in the same setup. The gap widens once you look at F1 rather than AUC alone.

There is a caveat worth flagging. When DNS-GT embeddings are handed off to a simple external classifier like SVM or AdaBoost, they perform poorly, likely because those classifiers cannot leverage the contextual information encoded in the embeddings. This model wants to be used end-to-end. The ablation confirms it: removing the attention mechanism drops AUC by 0.438, and removing host embeddings drops it by another 0.086.

On botnet detection, results are more modest. DNS-GT matches Word2Vec-SkipGram at 0.970 AUC and 0.877 F1, outperforming CBOW but not decisively better. The authors argue that botnet labels are host-level, so contextual signals from other queries offer less lift than in domain classification.

t-SNE visualization of learned domain embeddings with benign domains clustered centrally and blacklisted domains scattered

Context sensitivity, in practice

The paper's most convincing qualitative result is a case study on download.cdn.mozilla.net. Alone or surrounded by benign queries, the model scores it near zero (benign). But when the same domain appears alongside ad-tracking and audience segmentation domains that were labeled malicious during training, the score jumps toward 1, flagging a possibly spoofed or anomalous use. This is the kind of behavior signature-based systems structurally cannot reproduce.

Trade-offs and limits

DNS-GT is not free. It has 24M parameters versus 15M for the Word2Vec baselines, and pre-training with fixed or time-based sequencing takes roughly 1,900 to 2,100 minutes versus 200 to 500 for Word2Vec on the same hardware. The density-based sequencing is dramatically faster (116 minutes to pre-train), which makes it the practical default.

The authors are explicit about scope limitations too: the method detects behaviors involving suspicious domains such as botnets, DNS tunneling, or risky sites, but generally only at the level of individual users, limiting its ability to detect multi-host attacks like fast-flux.

Where this could plug in

The stated deployment target is inside a DNS resolver, where the fine-tuned model would score queries in real time and flag or block behavior patterns that look wrong given surrounding queries. Because pre-training is self-supervised, an organization sitting on a large private DNS archive can build the foundation model without labeling anything. Fine-tuning heads can then be added for specific tasks: phishing detection, domain impersonation, session classification, or behavior profiling.

Code, an appendix with additional analyses, and the training pipeline are released at the DNS-GT GitHub repository. For teams already running DNS analytics with Word2Vec-style embeddings, the honest question this paper raises is whether the contextual lift is worth roughly 4x to 10x more compute, and whether your downstream classifier is actually equipped to consume contextual embeddings rather than static per-domain vectors.