Real-time network intrusion detection system combining supervised and unsupervised machine learning with automated nftables-based threat mitigation.
sentryflow/
├── src/
│ ├── main.py # Daemon orchestrator
│ ├── ingestion/ # Packet capture & dataset loading
│ │ ├── sniffer.py # Scapy AsyncSniffer wrapper
│ │ └── dataset_manager.py # PCAP/CSV chunked loader
│ ├── features/ # Feature engineering pipeline
│ │ ├── pipeline.py # sklearn ColumnTransformer pipeline
│ │ └── aggregator.py # Flow-level aggregation (idle/hard timeout)
│ ├── models/ # Dual-engine detection
│ │ ├── supervised_engine.py # LightGBM classifier
│ │ ├── unsupervised_engine.py # Isolation Forest
│ │ └── evaluator.py # Metrics & visualization
│ ├── prevention/ # Automated response
│ │ └── firewall.py # nftables rule management
│ ├── dashboard/ # Streamlit real-time UI
│ │ └── app.py # Live telemetry & XAI dashboard
│ └── utils/
│ ├── config_loader.py # YAML config (type-safe dataclasses)
│ ├── logger.py # Rotating file + console logger
│ └── telemetry.py # JSON-persisted singleton store
├── config/settings.yaml # Application configuration
├── scripts/
│ ├── capture.py # Live packet capture to PCAP
│ └── train_pipeline.py # Model training pipeline
└── tests/
pip install -r requirements.txt
# Train models from PCAP data
python scripts/train_pipeline.py
# Run detection daemon
python -m src.main
# Launch explainability dashboard (separate terminal)
streamlit run src/dashboard/app.py- Capture — Live packets are ingested via Scapy sniffer or loaded from PCAP/CSV sources
- Aggregate — Raw packets are grouped into flows with idle/hard timeout boundaries
- Engineer — 20+ network features extracted (payload entropy, flow rates, window size, TTL, etc.)
- Detect — LightGBM (supervised) and Isolation Forest (unsupervised) run in parallel; an alert fires if either model flags a flow
- Block — Offending source IPs are automatically added to nftables drop rules
- Monitor — Streamlit dashboard displays live telemetry, detection events, and feature importance
Edit config/settings.yaml to control capture interface, ML hyperparameters, simulation mode, flow timeouts, and feature selection.
Python 3.12+, scikit-learn, LightGBM, Scapy, pandas, Streamlit, nftables (Linux).