Two-Layer Network Defense System โ Combining Intrusion Detection with DNS Threat Analysis, powered by Machine Learning and Claude AI.
Most modern cyberattacks touch DNS first โ C2 beacons, malware callbacks, and data exfiltration all leverage DNS before or alongside network-level attacks. This project fuses two detection layers into a unified threat intelligence pipeline:
| Layer | Engine | Detects |
|---|---|---|
| ๐ด IDS | Isolation Forest + Random Forest | Port scans, DDoS, Brute force, Lateral movement |
| ๐ DNS | Isolation Forest + Random Forest | DNS tunneling, DGA, Typosquatting, Fast-flux, Amplification |
| ๐ Correlator | Rule-based fusion engine | Cross-layer threats with unified severity scoring |
| ๐ค Claude AI | claude-sonnet-4-6 | Natural language explanations + MITRE ATT&CK mapping |
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ NETWORK TRAFFIC CAPTURE โ
โ (Simulated / Live pcap) โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโ
โ โ
โโโโโโโโโผโโโโโโโ โโโโโโโโโผโโโโโโโโโโโ
โ IDS ENGINE โ โ DNS ENGINE โ
โ โ โ โ
โ โข Flow stats โ โ โข Query freq โ
โ โข Packet sizeโ โ โข Domain entropy โ
โ โข Port scan โ โ โข DGA detection โ
โ โข DDoS flags โ โ โข Tunneling โ
โ โข Brute forceโ โ โข Typosquatting โ
โ โ โ โข Fast-flux โ
โ Isolation โ โ Isolation โ
โ Forest + RF โ โ Forest + RF โ
โโโโโโโโโฌโโโโโโโ โโโโโโโโโฌโโโโโโโโโโโ
โ โ
โโโโโโโโโผโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโ
โ CORRELATION ENGINE โ
โ Cross-link IDS alerts โ DNS events โ
โ Assign unified threat score (0-10) โ
โโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโ
โ CLAUDE AI LAYER โ
โ โข Natural language threat reports โ
โ โข MITRE ATT&CK TTP mapping โ
โ โข Prioritised remediation steps โ
โโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโ
โ STREAMLIT DASHBOARD โ
โ โข Real-time threat feed โ
โ โข DNS query heatmap โ
โ โข Traffic anomaly graphs โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
| Attack | Description |
|---|---|
port_scan |
Sequential SYN probing to map open services |
ddos |
High-volume traffic flood exhausting host resources |
brute_force |
Repeated login attempts on SSH / RDP / FTP |
lateral_movement |
Internal host pivoting via SMB / RDP / WMI |
| Attack | Description |
|---|---|
dns_tunneling |
Data exfiltration encoded in DNS subdomains |
dga |
Domain Generation Algorithm โ malware C2 beaconing |
typosquatting |
Look-alike phishing domains |
fast_flux |
Rapid IP rotation to evade blocklists (botnets) |
dns_amplification |
DNS reflection DDoS amplification |
| Combination | Severity | Meaning |
|---|---|---|
lateral_movement + dns_tunneling |
๐ด CRITICAL | Active C2 channel with internal pivoting |
brute_force + dga |
๐ด CRITICAL | Compromised host beaconing to C2 |
ddos + dns_amplification |
๐ด CRITICAL | Coordinated volumetric attack |
port_scan + dga |
๐ HIGH | Malware reconnaissance phase |
brute_force + typosquatting |
๐ HIGH | Credential phishing campaign |
| Metric | IDS Model | DNS Model |
|---|---|---|
| RF Weighted F1 | 1.0 | 1.0 |
| IF Attack Recall | ~93% | ~86% |
| Features | 23 | 24 |
| Algorithms | Isolation Forest + Random Forest | Isolation Forest + Random Forest |
| Component | Technology |
|---|---|
| ML Models | scikit-learn (Isolation Forest, Random Forest) |
| Feature Engineering | pandas, numpy, scipy |
| DNS Analysis | dnslib, dnspython |
| AI Explanations | anthropic (claude-sonnet-4-6) with prompt caching |
| Dashboard | streamlit, plotly |
| Terminal UI | rich |
| Traffic Simulation | Custom Python simulator |
ai_ids_dns_detector/
โโโ data/
โ โโโ simulator.py # Network flow + DNS attack simulator
โ โโโ models/ # Saved ML models (.pkl) โ gitignored
โโโ features/
โ โโโ ids_features.py # 23 network flow features (static + temporal)
โ โโโ dns_features.py # 24 DNS features (entropy, DGA score, freq)
โโโ detection/
โ โโโ ids_model.py # Isolation Forest + RF for IDS
โ โโโ dns_model.py # Isolation Forest + RF for DNS
โ โโโ correlator.py # Cross-engine threat fusion & scoring
โโโ llm/
โ โโโ explainer.py # Claude API + rule-based fallback
โโโ utils/
โ โโโ logger.py # Rich terminal pretty-printing
โโโ app.py # Streamlit dashboard (5 tabs)
โโโ main.py # CLI entry point
โโโ requirements.txt
โโโ .env.example # API key template
โโโ .gitignore
git clone https://github.com/singhananya0043/ai_ids_dns_detector.git
cd ai_ids_dns_detector
pip install -r requirements.txtcp .env.example .env
# Edit .env and add your Anthropic API key:
# ANTHROPIC_API_KEY=sk-ant-...Without an API key the system falls back to rule-based explanations with MITRE ATT&CK mappings โ all detection still works fully.
# CLI โ simulate traffic, train models, detect & correlate threats
python -X utf8 main.py
# CLI with Claude AI explanations for top threats
python -X utf8 main.py --explain
# Larger dataset
python -X utf8 main.py --n 1000 --explain
# Launch Streamlit dashboard
python -X utf8 main.py --dashboard
# OR
streamlit run app.pyThe Streamlit dashboard provides 5 interactive tabs:
| Tab | Contents |
|---|---|
| ๐จ Threats | Ranked threat table, score distribution, severity pie chart, Claude AI analysis |
| ๐ก IDS Analysis | Attack type breakdown, anomaly score histogram, flow timeline |
| ๐ DNS Analysis | DNS attack types, domain length box plots, payload timeline |
| ๐ Correlation | IDS ร DNS co-occurrence heatmap, confidence scatter plot |
| ๐ Model Metrics | F1 scores, recall, feature importance charts |
When ANTHROPIC_API_KEY is set, the system uses claude-sonnet-4-6 with prompt caching to generate:
- ๐ Threat explanation โ context-aware, specific to the IDS + DNS signal combination
- โ๏ธ Attack vector โ how the attack is being carried out
- ๐ผ Business impact โ potential consequences
- ๐ง Remediation steps โ prioritised with time windows (0-15min, 1hr, 24hr, 7 days)
- ๐ฏ MITRE ATT&CK โ full TTP mapping with sub-techniques
๐ Threat Analysis for 10.0.9.8 [Claude API]
Severity : CRITICAL | Score: 10.0/10
IDS Attack : lateral_movement (95.5% confidence)
DNS Attack : dns_tunneling (100% confidence)
Explanation:
Host is actively pivoting through internal network via SMB/RDP while
simultaneously exfiltrating data through a covert DNS tunnel to an
attacker-controlled C2 server...
Remediation:
1. [0-15 min] Isolate host at switch level โ do NOT power off
2. [0-30 min] Capture RAM dump and full disk image for forensics
3. [1-4 hrs] Block outbound DNS; analyse tunneling domain
4. [4-24 hrs] Hunt laterally; reset all credentials from this host
5. [1-7 days] Deploy DNS security solution; implement segmentation
MITRE ATT&CK: T1071.004, T1048.001, T1572, T1021.002, T1550.002
python -X utf8 main.py [OPTIONS]
Options:
--n INT Number of normal traffic samples to simulate (default: 400)
--seed INT Random seed for reproducibility (default: 42)
--explain Generate Claude AI threat explanations for top threats
--dashboard Launch the Streamlit dashboard
--top INT Number of top threats to display (default: 10)
- Live PCAP capture mode (Scapy integration)
- Real DNS resolver integration (dnspython)
- LSTM-based DGA classifier
- Threat intelligence feed integration (VirusTotal, Shodan)
- Slack / email alerting for CRITICAL events
- Docker containerisation
- Export threat reports to PDF
- CICIDS Dataset โ inspiration for IDS feature design
- Majestic Million โ legitimate domain reference
- Anthropic Claude โ AI-powered threat explanations
- MITRE ATT&CK โ threat taxonomy framework
This project is licensed under the MIT License.
Built with ๐ก๏ธ and ๐ค by singhananya0043