Skip to content

Repository files navigation

πŸ›‘οΈ IDS with AI

AI-Driven Intrusion Detection System for Real-Time Network Threat Detection

Python Scikit-Learn Flask License


πŸ“– Table of Contents


🎯 About

IDS with AI is an intelligent Intrusion Detection System that leverages Machine Learning to detect and alert malicious network activities in real-time.

Built with the renowned UNSW-NB15 dataset, this system employs a Random Forest classifier to achieve high-accuracy detection of network intrusions, distinguishing between Normal and Malicious traffic patterns.

πŸ”₯ Key Highlights

Aspect Details
🧠 AI Model Random Forest Classifier
πŸ“Š Dataset UNSW-NB15 (42 features)
⚑ Processing Real-time packet analysis
🌐 Dashboard Auto-refreshing web UI
πŸ’Ύ Storage SQLite database logging

✨ Features

βœ… AI-Powered Detection     β†’ Random Forest ML model with ~85-90% accuracy
βœ… Real-time Monitoring      β†’ Live network packet capture using Scapy  
βœ… Web Dashboard             β†’ Beautiful, responsive UI with auto-refresh
βœ… Threat Alerts             β†’ Instant visual notifications for malicious activity
βœ… Persistent Logging        β†’ SQLite database for historical analysis
βœ… Binary Classification     β†’ Normal (0) vs Malicious (1) detection
βœ… Modular Design            β†’ Easy to extend with additional models

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         IDS with AI Architecture                        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                         β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚
β”‚   β”‚   Network    │─────▢│   AI Sniffer │─────▢│   SQLite     β”‚         β”‚
β”‚   β”‚   Traffic    β”‚      β”‚  (Scapy+ML)  β”‚      β”‚   Database   β”‚         β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚
β”‚                                                      β”‚                  β”‚
β”‚                                                      β–Ό                  β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚
β”‚   β”‚   Web        │◀─────│    Flask     │◀─────│  Detection   β”‚         β”‚
β”‚   β”‚   Browser    β”‚      β”‚    Server    β”‚      β”‚     Logs     β”‚         β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚
β”‚                                                                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“¦ Installation

Prerequisites

  • Python 3.8 or higher
  • Git
  • pip (Python package manager)

Step 1: Clone Repository

git clone https://github.com/shamanthwick/IDS-With-AI.git
cd IDS-With-AI

Step 2: Install Dependencies

pip install -r requirements.txt

Step 3: Download Dataset

Download the UNSW-NB15 training dataset:

  • Search for UNSW_NB15_training-set.csv online
  • Place it in the project root folder

Step 4: Train AI Model

python train_model.py

This generates:

  • ids_rf_model.pkl β†’ Trained Random Forest model
  • ids_scaler.pkl β†’ Feature scaler

πŸš€ Usage

1️⃣ Start Network Sniffer

python sniffer.py

2️⃣ Launch Web Dashboard

Open a new terminal:

python app.py

3️⃣ Access Dashboard

Open browser and navigate to:

http://127.0.0.1:5000

πŸ“Š Dashboard Features

Feature Description
πŸ“Š Live Statistics Real-time threat counts and totals
πŸ“‹ Detection Logs Recent network activity table
πŸ”„ Auto-Refresh Updates every 3 seconds
🏷️ Status Badges Color-coded Normal/Malicious indicators
🎨 Dark Theme Modern, eye-friendly UI

πŸ“ Dataset

UNSW-NB15 Details

Property Value
Name UNSW-NB15
Type Network Intrusion Detection
Classes Binary (Normal/Malicious)
Features 42 network traffic features
Source University of New South Wales

Attack Categories Covered

  • πŸ–₯️ Fuzzers
  • πŸ” Analysis
  • πŸšͺ Backdoors
  • πŸ’₯ DoS (Denial of Service)
  • 🎯 Exploits
  • πŸ”€ Generic
  • πŸ“‘ Reconnaissance
  • πŸ’‰ Shellcode
  • πŸ› Worms

πŸš€ Additional Datasets & Future Improvements

To enhance the robustness of this IDS, future iterations can incorporate more modern and diverse datasets:

1. CSE-CIC-IDS2018

A large-scale dataset created by the Canadian Institute for Cybersecurity (CIC) representing modern network traffic environments.

  • Key Features:
    • Capture period of 10 days with realistic background traffic.
    • Extensive feature set (80+ network flow features).
    • Large volume of data (terabytes of raw traffic).
  • Types of Attacks: Brute Force, DoS, DDoS, Heartbleed, Botnet, Infiltration, and Web Attacks.
  • Why it's Modern: It captures much newer attack vectors and more complex network topologies compared to UNSW-NB15.

2. ToN-IoT

A heterogeneous dataset collecting data from Telemetry, Operating Systems, and Network (ToN) sensors in an IoT/IIoT environment.

  • Key Features:
    • Multi-layered data including Network traffic, IoT telemetry, and OS logs.
    • Realistic Industrial IoT (IIoT) environment simulation.
    • High-dimensional and diverse feature sets.
  • Types of Attacks: DoS, DDoS, Ransomware, Backdoor, Injection, XSS, Scanning, and MitM.
  • Why it's Modern: Specifically designed for the IoT era, addressing vulnerabilities in smart devices that traditional datasets like UNSW-NB15 overlook.

3. BoT-IoT

A dataset created in a realistic network environment specifically to capture various botnet attack scenarios.

  • Key Features:
    • High-density Botnet-specific traffic patterns.
    • Includes 5% sub-sampled versions for efficient research and training.
    • Detailed per-packet and per-flow statistical metrics.
  • Types of Attacks: DDoS, DoS, OS Fingerprinting, Service Discovery, Keylogging, and Data Exfiltration.
  • Why it's Modern: Provides a much more specialized and deep focus on botnet behaviors, which have evolved significantly since the release of earlier datasets.

πŸ“ˆ Model Performance

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              Model Evaluation Results              β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Metric       β”‚  Score                             β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Accuracy     β”‚  ~85-90%                           β”‚
β”‚  Precision    β”‚  ~85%                              β”‚
β”‚  Recall       β”‚  ~85%                              β”‚
β”‚  F1-Score     β”‚  ~85%                              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

*Results may vary based on training data and network conditions

πŸ“‚ Project Structure

IDS-With-AI/
β”‚
β”œβ”€β”€ πŸ“„ train_model.py          # AI model training script
β”œβ”€β”€ πŸ“„ sniffer.py              # Network packet sniffer
β”œβ”€β”€ πŸ“„ app.py                  # Flask web server
β”œβ”€β”€ πŸ“„ requirements.txt        # Python dependencies
β”œβ”€β”€ πŸ“„ README.md               # Project documentation
β”‚
β”œβ”€β”€ πŸ“ templates/
β”‚   └── πŸ“„ index.html          # Dashboard UI
β”‚
β”œβ”€β”€ πŸ”§ .gitignore              # Git ignore rules
β”‚
└── πŸ“¦ Generated Files (not in repo)
    β”œβ”€β”€ ids_rf_model.pkl       # Trained model
    β”œβ”€β”€ ids_scaler.pkl         # Feature scaler
    └── ids_logs.db            # Detection logs

🀝 Contributing

Contributions are welcome! Here's how you can help:

  1. 🍴 Fork the repository
  2. 🌿 Create a feature branch (git checkout -b feature/AmazingFeature)
  3. πŸ’Ύ Commit your changes (git commit -m 'Add AmazingFeature')
  4. πŸš€ Push to the branch (git push origin feature/AmazingFeature)
  5. πŸ”„ Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ‘¨β€πŸ’» Author

GitHub @shamanthwick
Email shamantharsingh@gmail.com

πŸ™ Acknowledgments

  • πŸŽ“ UNSW-NB15 Dataset creators
  • πŸ”§ Scapy developers
  • πŸ€– Scikit-learn team
  • 🌐 Flask community

πŸ›‘οΈ Made with ❀️ for Network Security

If you find this project useful, please ⭐ star this repository!

⬆ Back to Top

Releases

Packages

Contributors

Languages