A high-performance, asynchronous, multi-processed Network Intrusion Detection System (IDS) written in Python using Scapy, XGBoost, and PyTorch.
This system uses a cooperative, tiered defense-in-depth architecture to process packets at sub-millisecond speeds. High-volume packet capture and time-series feature extraction happen on an asynchronous event loop, while heavy Machine Learning and Deep Learning inference are safely offloaded to an isolated CPU process pool to completely bypass Python's Global Interpreter Lock (GIL).
Traffic moves down a conditional cascade to maximize throughput and minimize computational overhead:
- Tier 1: Deterministic Engine (O(1) Signature Matching)
- Catches known malicious threats instantly inside the main async thread using fast hash-set lookups for blocklisted IPs and prohibited ports. Skips advanced evaluation if a match is found.
- Tier 2: Supervised ML Core (XGBoost Classifier)
- Evaluates rolling time-series features (packets/sec, unique destination counts, average lengths) using a pre-trained XGBoost model to classify known attack footprints like volumetric DDoS or Port Scans.
- Tier 3: Unsupervised Deep Learning Core (PyTorch Autoencoder)
- If Tier 2 marks traffic as "Normal," it falls back to a Neural Network Autoencoder. It evaluates reconstruction loss to flag never-before-seen anomalies and structural Zero-Day threats.
IDS/
├── Dockerfile
├── docker-compose.yml
├── requirements.txt
├── logs/ # Automatically created on host to store alerts
│ └── ids_alerts.jsonl
└── src/
├── monitor.py # Main async ingestion pipeline & IDS engine
└── data/
└── xgboost_ids.pkl # Pre-trained Tier 2 ML model
This IDS is optimized for native deployment on Linux-based production servers or within network probes attached to Windows Active Directory domains.
Ensure you have Docker and Docker Compose installed on your server.
From your root ~/IDS directory, launch the entire containerized pipeline in the background:
sudo docker compose up -d --buildMonitor real-time detections and multi-tier triggers as they hit your interfaces:
sudo docker compose logs -fAll triggered anomalies are written as non-blocking JSON Lines straight to your host machine's directory for simple downstream ingestion (SIEM/ELK):
cat logs/ids_alerts.jsonlsudo docker compose down
⚠️ Important Node for Windows Testing: Docker Desktop on Windows routes networking inside a virtual abstraction layer (WSL2/Hyper-V). As a result, Docker's nativenetwork_mode: "host"flag cannot capture your host hardware's raw network traffic inside a container on Windows.
If running or testing on a physical Windows host machine (such as a workspace laptop), deploy the script natively instead:
- Install Python 3.11+ and Npcap (the standard Windows packet capture driver, typically bundled with Wireshark).
- Open an Administrator PowerShell / Command Prompt.
- Navigate to your project directory and run:
pip install -r requirements.txt python src/monitor.py
You can modify configurations directly inside the code or setup files:
- Change Sniffing Interface: Update the
IDS_INTERFACEenvironment variable insidedocker-compose.ymlto match your active target adapter (e.g.,eth0,wlan0,en0). - Update Signature Rules: Add known malicious endpoints or restricted system endpoints directly to
self.blocklisted_ipsandself.restricted_portsinsrc/monitor.pyfor immediate O(1) dropping.