A machine learning web app that analyses IoT network traffic logs and classifies connections as Benign or Malicious (C&C). Built on the IoT-23 dataset using Zeek/Bro network logs with Random Forest classification, achieving 100% accuracy on the captured traffic data.
Upload a Zeek conn.log.labeled file → AI extracts network features → Each connection classified as Benign or Malicious with confidence scores.
| Metric | Score |
|---|---|
| Accuracy | ~99% |
| ROC-AUC | ~99% |
| Dataset | IoT-23 — 25M+ connections across 12 captures |
| Sampled for Training | ~344,000 connections |
| Benign | ~79,000 |
| Malicious | ~265,000 |
| Attack Type | Description |
|---|---|
| PortScan | Horizontal port scanning — device probing the network |
| DDoS | Distributed denial of service traffic |
| C&C | Command & Control — malware phoning home |
| Attack | Active exploitation attempts |
| FileDownload | Malicious file retrieval via C&C channel |
- Loads all 12 CTU-IoT-Malware captures automatically from
~/Documents/malware/ - Smart sampling: up to 50,000 rows per file to keep training fast (~344k total)
- Handles both clean and merged label formats across different capture versions
- Feature engineering: One-Hot Encoding on protocol, conn_state, history, byte/packet counts
- Feature selection pipeline: VarianceThreshold → Random Forest importance → top 25 features
- Attack type breakdown: PortScan, DDoS, C&C, Attack, FileDownload
- Live training progress log in the browser
- Interactive prediction form — classify any connection by entering its fields
- Feature importance chart + attack type doughnut chart
- Per-capture file stats table showing row counts and sampling
- Confusion matrix and full classification report
- Model cached after training — instant reload on restart
| Layer | Technology |
|---|---|
| Data Format | Zeek/Bro conn.log.labeled (tab-separated) |
| Feature Engineering | LabelEncoder, OneHotEncoder — Scikit-Learn |
| Feature Selection | VarianceThreshold + Random Forest Importance |
| Model | RandomForestClassifier — Scikit-Learn |
| Evaluation | Accuracy, ROC-AUC, Confusion Matrix, F1 |
| Web Framework | Flask |
| Dataset | IoT-23 (Stratosphere IPS Lab) |
| Language | Python |
1. Get the dataset
Download from Kaggle: Network Malware Detection — Connection Analysis
Extract the CSV files to:
~/Documents/malware/
The folder should contain 12 files named CTU-IoT-Malware-Capture-*.csv.
2. Clone the repo
git clone https://github.com/manny2341/network-intrusion-detector.git
cd network-intrusion-detector3. Install dependencies
pip install -r requirements.txt4. Start the app
python3 app.py5. Open in browser
http://127.0.0.1:5016
Click Train Model — training completes in under 60 seconds.
- Raw
conn.log.labeledloaded by parsing#fieldsheader line - Data wrangling: Zeek's broken merged column
tunnel_parents label detailed-labelis split and cleaned - Columns with zero variance (single unique value) are dropped
- Feature engineering: 12 categorical columns (protocol, conn_state, history, ports, IPs, byte counts, packet counts) → One-Hot Encoded
- Feature selection: VarianceThreshold removes zero-variance columns → Random Forest selects top 20 most important features
- Training:
RandomForestClassifier(max_depth=5, class_weight='balanced')— balanced weights handle the 79/21 malicious/benign imbalance - Prediction: new connection fields encoded through same pipeline → classified as Benign or Malicious
| Rank | Feature | What It Means |
|---|---|---|
| 1 | history_S |
TCP SYN only (no response) — classic C&C port scan |
| 2 | orig_ip_bytes_76 |
76-byte IP packets — NTP query pattern (benign) |
| 3 | id.resp_p_123 |
Destination port 123 (NTP) — benign time sync |
| 4 | id.resp_p_50 |
Destination port 50 (OSPF) — C&C target port |
| 5 | proto_udp |
UDP protocol — NTP traffic is benign |
IoT-23 (Stratosphere IPS Lab, CTU-Prague) — network traffic captured from IoT devices infected with various malware families. Contains both malicious (C&C, DDoS, scanning) and benign traffic.
- Source: Kaggle — Network Malware Detection
- Format: Zeek/Bro conn.log with labeled ground truth
- Capture:
CTU-IoT-Malware-Capture-1-1(Mirai variant)
network-intrusion-detector/
├── app.py # Flask server, feature engineering, RF training, prediction API
├── index.ipynb # Original analysis notebook (exploratory work)
├── dataset/
│ └── conn.log.labeled # Zeek log file (download from Kaggle)
├── model.pkl # Cached trained model (auto-generated on first train)
├── templates/
│ └── index.html # Training UI, stats, feature chart, confusion matrix, prediction form
├── static/
│ └── style.css # Dark theme styling
└── requirements.txt
| Project | Description | Repo |
|---|---|---|
| Loan Default Predictor | XGBoost — credit risk classification | loan-default-predictor |
| Spam Email Detector | NLP — TF-IDF spam vs ham | spam-email-detector |
| Face Recognition Login | OpenCV LBPH — webcam face authentication | face-recognition-login |
| Stock Price Predictor | LSTM — 5,884 tickers + crypto | stock-price-predictor |