π‘οΈ ML-Powered Network Security Monitoring & Threat Detection
A sophisticated Machine Learning-powered Intrusion Detection System capable of real-time network traffic analysis using REAL device data, behavioral anomaly detection, and automated threat response.
- NSL-KDD trained models - Industry-standard intrusion detection dataset
- 41 real network features - All features populated from actual device traffic
- Multiple ML algorithms tested - Decision Tree, Random Forest, XGBoost, LightGBM
- Real-time ML inference on live network traffic
- Behavioral analysis to detect unusual user/system activities
- Real-time packet capture with Scapy integration
- Connection monitoring using psutil
- 41 NSL-KDD features extracted from actual network traffic:
- Duration, bytes, protocol type, service, flag
- Error rates (serror, rerror, srv_serror, srv_rerror)
- Host-based features (dst_host_count, srv_count, same_srv_rate)
- Content features (num_failed_logins, num_shells, num_file_creations)
- Port scan detection and suspicious activity identification
- JWT Authentication with user roles (admin, analyst, viewer)
- Login Rate Limiting - Brute force attack protection
- IP Quarantine System - Auto-block attacking IPs
- Login Security Monitoring - Track failed login attempts per IP
- Real-time threat visualization
- Interactive security metrics and KPI monitoring
- Alert management with filtering and search
- Login security view for monitoring brute force attempts
- IP quarantine management interface
Tested on NSL-KDD dataset (22,544 test samples):
| Model | Accuracy | Precision | Recall | F1 Score |
|---|---|---|---|---|
| Decision Tree | 81.22% | 93.72% | 71.83% | 81.33% |
| AdaBoost | 79.87% | 96.61% | 67.00% | 79.12% |
| XGBoost | 79.56% | 96.71% | 66.34% | 78.70% |
| Random Forest | 77.94% | 96.71% | 63.40% | 76.59% |
Decision Tree recommended - Best recall (catches 72% of attacks) and F1 score.
``` backend/ βββ app/ β βββ main.py # FastAPI application & endpoints β βββ ml_models.py # NSL-KDD trained ML models β βββ network_monitor.py # Real network traffic monitoring β βββ real_packet_capture.py # Scapy packet capture β βββ auth.py # JWT authentication β βββ ip_quarantine.py # IP blocking system β βββ attack_detector.py # Attack pattern detection βββ models/ # Trained ML models (.pkl) βββ requirements.txt # Python dependencies βββ compare_models.py # ML model comparison script ```
``` frontend/ βββ src/ β βββ components/ β β βββ MainScreen.jsx # Dashboard layout β β βββ RealTimeMonitor.jsx # Live network monitoring β β βββ AlertsView.jsx # Security alerts β β βββ VisualizerView.jsx # ML visualization β β βββ LoginSecurityView.jsx # Login monitoring β β βββ IPQuarantineView.jsx # IP blocking UI β β βββ LoginPage.jsx # Authentication β βββ context/ β β βββ AuthContext.jsx # Auth state management β βββ App.jsx # Main application βββ package.json ```
``` AttackerMachine/ βββ attacker_panel.html # Web-based attack launcher βββ attacker_cli.py # CLI attack tools βββ attack_standalone.py # Standalone attack scripts βββ NETWORK_ATTACK_GUIDE.md # Attack testing guide ```
- Python 3.11+
- Node.js 16+
- Git
```bash git clone https://github.com/NikitaGithub17/Intrusion_Detection_System.git cd Intrusion_Detection_System ```
```bash cd backend
python -m venv .venv source .venv/bin/activate # Linux/Mac
pip install -r requirements.txt
python -m uvicorn app.main:app --host 0.0.0.0 --port 8000 ```
```bash cd frontend
npm install
npm run dev ```
- Dashboard: http://localhost:5173
- API Docs: http://localhost:8000/docs
- Backend Health: http://localhost:8000
| Username | Password | Role |
|---|---|---|
| admin | admin123 | Admin |
| analyst | analyst123 | Analyst |
| viewer | viewer123 | Viewer |
All features are populated with REAL network data from your device:
| Feature | Source |
|---|---|
| duration | Connection start time tracking |
| protocol_type | psutil connection type |
| service | Port-to-service mapping |
| flag | Connection status |
| src_bytes, dst_bytes | Network I/O monitoring |
| Feature | Source |
|---|---|
| wrong_fragment | Scapy IP fragmentation analysis |
| urgent | Scapy TCP URG flag detection |
| num_compromised | Payload compromise signatures |
| num_failed_logins | Login rate limiter |
| num_shells | Process monitoring |
| num_file_creations | File system monitoring |
| Feature | Source |
|---|---|
| count | Connection history window |
| srv_count | Service access tracking |
| serror_rate | SYN error tracking |
| same_srv_rate | Service pattern analysis |
| Feature | Source |
|---|---|
| dst_host_count | Destination host tracking |
| dst_host_same_src_port_rate | Source port pattern analysis |
| srv_diff_host_rate | Multi-host service tracking |
- `POST /api/auth/login` - User login
- `POST /api/auth/register` - Register new user (admin only)
- `GET /api/auth/me` - Current user info
- `GET /api/detection/alerts` - Security alerts
- `GET /api/detection/statistics` - Detection stats
- `GET /api/realtime/connections` - Live connections
- `GET /api/quarantine/blocked` - Blocked IPs
- `POST /api/quarantine/block` - Block an IP
- `DELETE /api/quarantine/unblock/{ip}` - Unblock IP
- `GET /api/auth/login-stats` - Login attempt statistics
- `GET /api/auth/locked-ips` - Locked out IPs
Use the Attacker Machine tools to test detection:
```bash cd AttackerMachine
open attacker_panel.html
python attacker_cli.py --target http://localhost:8000 ```
Available attacks:
- Port scanning
- Brute force login
- DDoS simulation
- SQL injection attempts
- API endpoint probing
Run the comparison script: ```bash cd backend python compare_models.py ```
This tests 10+ models on NSL-KDD and outputs:
- Accuracy, Precision, Recall, F1 scores
- Training time comparison
- Feature importance analysis
``` Intrusion_detection_system/ βββ backend/ # FastAPI backend βββ frontend/ # React frontend βββ NSL-KDD/ # Training dataset βββ AttackerMachine/ # Attack testing tools βββ ML_MODEL_COMPARISON.md # Model benchmark results βββ README.md ```
- Fork the repository
- Create feature branch (`git checkout -b feature/amazing-feature`)
- Commit changes (`git commit -m 'Add amazing feature'`)
- Push to branch (`git push origin feature/amazing-feature`)
- Open a Pull Request
This project is for educational purposes.
π‘οΈ Real ML-powered intrusion detection with actual network data!
For questions or support, please open an issue in the GitHub repository.