A production-style, real-time Intrusion Detection System that combines machine learning with threat intelligence to detect network attacks and suspicious activities.
- Real-time Packet Capture: Live network traffic monitoring using PyShark/Scapy
- Machine Learning Detection: Trained RandomForest model for anomaly detection
- Threat Intelligence Integration: Multiple API sources (VirusTotal, AbuseIPDB, URLScan, OTX)
- Risk Assessment: Combined ML and threat intel scoring for accurate risk levels
- Database Storage: Supabase for logs, alerts, and statistics
- REST API: Complete FastAPI backend for frontend integration
- Real-time Updates: WebSocket support for live monitoring
- Blacklist Management: Dynamic IP blacklist system
- Feature Engineering: Sophisticated packet-to-ML-feature conversion
- Rate Limiting: Built-in API protection
- Health Monitoring: System health checks and statistics
- Data Export: CSV export for analysis
- Modular Architecture: Clean, maintainable codebase
- Python 3.8+
- Administrative privileges (for packet capture)
- Network interface access
- Supabase account (for database)
- API keys for threat intelligence (optional but recommended)
git clone <repository-url>
cd SecureNet-IDS
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install -r requirements.txtcp .env.example .env
# Edit .env with your API keys and configuration# Train with synthetic data (for testing)
python train_model.py --synthetic --samples 10000
# Or train with NSL-KDD dataset
python train_model.py --data-path data/NSL-KDD/KDDTrain+.txtCreate the following tables in your Supabase database:
-- Alerts table
CREATE TABLE ids_alerts (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
source_ip TEXT NOT NULL,
destination_ip TEXT NOT NULL,
protocol TEXT NOT NULL,
timestamp TIMESTAMPTZ NOT NULL,
attack_type TEXT NOT NULL,
risk_level TEXT NOT NULL,
confidence FLOAT NOT NULL,
description TEXT,
threat_intel_data JSONB,
packet_data JSONB,
prediction_result JSONB,
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- Logs table
CREATE TABLE ids_logs (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
timestamp TIMESTAMPTZ NOT NULL,
level TEXT NOT NULL,
message TEXT NOT NULL,
source TEXT NOT NULL,
packet_data JSONB,
alert_id UUID,
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- Stats table
CREATE TABLE ids_stats (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
timestamp TIMESTAMPTZ NOT NULL,
total_packets INTEGER DEFAULT 0,
malicious_packets INTEGER DEFAULT 0,
normal_packets INTEGER DEFAULT 0,
alerts_generated INTEGER DEFAULT 0,
top_source_ips JSONB,
top_destination_ips JSONB,
protocol_distribution JSONB,
attack_type_distribution JSONB,
created_at TIMESTAMPTZ DEFAULT NOW()
);
-- Blacklist table
CREATE TABLE ids_blacklist (
id UUID DEFAULT gen_random_uuid() PRIMARY KEY,
ip_address TEXT NOT NULL UNIQUE,
reason TEXT NOT NULL,
added_at TIMESTAMPTZ NOT NULL,
risk_level TEXT NOT NULL,
source TEXT NOT NULL,
is_active BOOLEAN DEFAULT TRUE,
created_at TIMESTAMPTZ DEFAULT NOW()
);cd backend
python main.pyThe server will start on http://localhost:8000
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
POST /start-monitoring- Start network monitoringPOST /stop-monitoring- Stop network monitoringGET /status- Get current monitoring statusGET /health- System health check
GET /alerts- Get alerts with filteringGET /logs- Get system logsGET /stats- Get system statisticsGET /blacklist- Get IP blacklist
POST /blacklist- Add IP to blacklistDELETE /blacklist/{ip}- Remove IP from blacklistPOST /check-ip/{ip}- Check IP reputationGET /export/alerts- Export alerts to CSV
WebSocket /ws- Real-time updates
# Supabase Configuration
SUPABASE_URL=your_supabase_project_url
SUPABASE_KEY=your_supabase_anon_key
# Threat Intelligence API Keys
VIRUSTOTAL_API_KEY=your_virustotal_api_key
ABUSEIPDB_API_KEY=your_abuseipdb_api_key
URLSCAN_API_KEY=your_urlscan_api_key
OTX_API_KEY=your_otx_api_key
# Application Settings
DEBUG=false
HOST=0.0.0.0
PORT=8000
NETWORK_INTERFACE=Wi-Fi
# Logging
LOG_LEVEL=INFO
LOG_FILE=ids.logUpdate NETWORK_INTERFACE in your .env file to match your system:
- Windows:
Wi-Fi,Ethernet, etc. - Linux:
eth0,wlan0, etc. - macOS:
en0,en1, etc.
python train_model.py --synthetic --samples 10000- Download NSL-KDD dataset
- Place in
data/NSL-KDD/directory - Run training:
python train_model.py --data-path data/NSL-KDD/KDDTrain+.txtpython train_model.py --evaluatecurl -X POST "http://localhost:8000/start-monitoring"curl "http://localhost:8000/alerts?limit=10&risk_level=high"curl -X POST "http://localhost:8000/check-ip/192.168.1.1"curl "http://localhost:8000/status"- LOW: Normal activity, low confidence
- MEDIUM: Suspicious activity, moderate confidence
- HIGH: Likely attack, high confidence
- CRITICAL: Confirmed malicious activity
- Normal: Legitimate network traffic
- Probe: Network reconnaissance (port scans, etc.)
- DoS: Denial of Service attacks
- U2R: User to Root privilege escalation
- R2L: Remote to Local attacks
- Machine Learning: Pattern recognition on packet features
- Threat Intelligence: Cross-referencing with known malicious sources
- Behavioral Analysis: Anomaly detection in traffic patterns
- API endpoints protected with rate limiting
- Configurable limits per endpoint
- Protection against abuse
- IP address validation
- Port number validation
- SQL injection protection
- XSS protection
- API key support
- Role-based access control ready
- Packets processed per second
- Alert generation rate
- Protocol distribution
- Top source/destination IPs
- Time-based alert trends
- Attack type distribution
- Geographic analysis (with threat intel)
- CSV export for alerts and logs
- Configurable time ranges
- Filtered data export
- Live packet processing updates
- Instant alert notifications
- System status changes
- Statistics updates
const ws = new WebSocket('ws://localhost:8000/ws');
ws.onmessage = function(event) {
const data = JSON.parse(event.data);
console.log('Real-time update:', data);
};- Cause: Insufficient permissions
- Solution: Run with administrative privileges
- Check: Verify network interface name
- Cause: Model file missing or corrupted
- Solution: Train the model first
- Command:
python train_model.py --synthetic
- Cause: Incorrect Supabase configuration
- Solution: Verify URL and API keys
- Check: Network connectivity
- Cause: Missing API keys or rate limits
- Solution: Add API keys to .env file
- Check: API key validity
Enable debug logging:
DEBUG=true
LOG_LEVEL=DEBUGFROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "backend/main.py"][Unit]
Description=SecureNet IDS
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/opt/securenet-ids
ExecStart=/opt/securenet-ids/venv/bin/python backend/main.py
Restart=always
[Install]
WantedBy=multi-user.targetserver {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://localhost:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
location /ws {
proxy_pass http://localhost:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}- INFO: General system information
- WARNING: Suspicious activities
- ERROR: System errors
- CRITICAL: Critical failures
- File:
ids.log(configurable) - Console: Real-time output
- Database: Stored in
ids_logstable
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For issues and questions:
- Check the troubleshooting section
- Review the logs
- Create an issue with detailed information
- Include system specs and error messages
- Web dashboard frontend
- Advanced ML models (LSTM, Autoencoders)
- Distributed deployment support
- Integration with SIEM systems
- Mobile app for alerts
- Machine learning pipeline automation
- Advanced threat hunting features
- Cloud deployment templates
SecureNet IDS - Protecting networks with AI-powered detection ๐ก๏ธ