Skip to content

A lightweight machine-learning system for detecting DNS tunneling by analyzing DNS traffic patterns, extracting statistical features, and identifying abnormal query behavior to distinguish legitimate DNS requests from covert data-exfiltration channels.

License

Notifications You must be signed in to change notification settings

3bdelmoemn/DNS-Tunneling-Detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

DNS Tunneling Detection Using Machine Learning

A lightweight and production-ready machine learning system for detecting DNS tunneling attacks through advanced traffic analysis, feature engineering, and automated classification. The system parses DNS traffic from PCAP/CSV files, extracts behavioral features, and applies a trained ML model to identify covert data‑exfiltration channels.

DNS Detector Screenshot


📌 Overview

The project provides a complete pipeline:

  • DNS traffic parsing (PCAP/PCAPNG/CSV)
  • Feature extraction & preprocessing
  • ML-based classification (normal vs tunneling)
  • FastAPI backend for real-time prediction
  • Research notebook for experimentation

📁 Project Structure

src
 ┣ artifacts
 ┃ ┣ detector.pkl
 ┃ ┗ processor.pkl
 ┣ assets/files
 ┃ ┣ dnsfiltered/dnsfiltered.pcap
 ┃ ┣ dns_testing/dns_testing.csv
 ┃ ┗ malll/malll.pcapng
 ┣ controllers
 ┃ ┗ FeatureExtractorController.py
 ┣ data
 ┃ ┣ info/information.py
 ┃ ┣ processed/dns_train_dataset_processed.csv
 ┃ ┗ raw/dns_testing.csv
 ┃   ┗ dns_tunneling_dataset.csv
 ┣ notebooks/DNS_Tunneling.ipynb
 ┣ routes
 ┃ ┣ data.py
 ┃ ┗ prediction.py
 ┣ services
 ┃ ┣ detector.py
 ┃ ┣ parser.py
 ┃ ┗ processor.py
 ┣ utilities/file.py
 ┣ app.py
 ┗ main.py

⚙️ Installation

git clone https://github.com/USERNAME/DNS-Tunneling-Detection.git
cd DNS-Tunneling-Detection
pip install -r requirements.txt

🚀 Running the Application

$ uvicorn main:app --reload --port 5000
$ straemlit run app.py

Open API Docs:

http://127.0.0.1:5000/docs

📡 How It Works

1. Parsing

Extracts DNS queries from PCAP/CSV using the internal parser.

2. Feature Extraction

Includes:

  • Query length
  • Entropy
  • Subdomain depth
  • Frequency patterns
  • NXDomain ratios
  • Time‑delta features

3. Classification

Uses:

  • detector.pkl (ML model)
  • processor.pkl (scaler/encoder pipeline)

Output:

0 = Normal Traffic
1 = DNS Tunneling

🧪 Notebook

DNS_Tunneling.ipynb contains:

  • Data exploration
  • Feature engineering
  • ML training
  • Visualization

📥 Supported File Formats

Format Description
.pcap Raw DNS packets
.pcapng Modern PCAP
.csv Tabular DNS data

🤝 Contributions

Pull requests are welcome.

About

A lightweight machine-learning system for detecting DNS tunneling by analyzing DNS traffic patterns, extracting statistical features, and identifying abnormal query behavior to distinguish legitimate DNS requests from covert data-exfiltration channels.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published