Skip to content

Repository files navigation

πŸ›‘οΈ Intelligent Network Intrusion Detection & Risk Analysis System

Machine Learning-Based Intrusion Detection using Random Forest & NFStream Flow Analysis

A modern cybersecurity dashboard that combines Machine Learning and Flow-Based Network Analysis to detect suspicious network activities from CSV datasets and PCAP files.

Python Streamlit Scikit-Learn NFStream License


πŸ“Œ Overview

The Intelligent Network Intrusion Detection & Risk Analysis System is a cybersecurity analysis platform developed during the Microsoft AI Innovators Internship Program.

The system combines machine learning and flow-based traffic analysis to identify suspicious network activities and assess potential security risks.

It provides two complementary analysis modules:

  • πŸ€– Machine Learning-Based CSV Analysis using a trained Random Forest model on the CICIDS2017 dataset.
  • 🌐 Flow-Based PCAP Analysis using NFStream to extract network flows and perform explainable rule-based security assessment.

The dashboard provides attack predictions, model probability scores, interactive visualizations and downloadable reports through an intuitive Streamlit interface.


✨ Features

Note: The PCAP module performs rule-based traffic assessment and does not use machine learning classification.

πŸ€– Machine Learning Analysis

  • Random Forest attack classification
  • CICIDS2017 dataset support
  • 77 network traffic features
  • 15 attack classes
  • Model Probability Score
  • Second Most Probable Class
  • Risk Level Assessment
  • Interactive charts
  • CSV report export
  • Missing / NaN / Infinite value validation

🌐 PCAP Flow Analysis

  • NFStream flow extraction
  • Protocol statistics
  • Traffic visualization
  • Top Talkers analysis
  • Port analysis
  • Rule-based security assessment
  • Search & filtering
  • Sortable flow table
  • CSV report export

πŸ–ΌοΈ Screenshots

Dashboard


CSV Analysis


CSV Visual Analytics


PCAP Flow Analysis


πŸ› οΈ Technologies

Category Technologies
Programming Language Python
User Interface Streamlit
Machine Learning Scikit-learn
Classification Model Random Forest
Network Flow Analysis NFStream
Data Processing Pandas
Visualization Matplotlib

πŸ—οΈ System Architecture

                    CSV FILE
                       β”‚
                       β–Ό
             Feature Validation
                       β”‚
                       β–Ό
               Random Forest Model
                       β”‚
                       β–Ό
      Attack Classification & Risk Analysis
                       β”‚
                       β–Ό
                  Streamlit Dashboard


                 PCAP / PCAPNG FILE
                       β”‚
                       β–Ό
                    NFStream
                       β”‚
                       β–Ό
               Flow Extraction
                       β”‚
                       β–Ό
      Rule-Based Security Assessment
                       β”‚
                       β–Ό
                  Streamlit Dashboard

πŸ“Š Model Performance

The Random Forest model was evaluated on a stratified test set containing 462,762 network flows.

Overall Performance

Metric Score
Accuracy 99.85%
Macro Precision 92.50%
Macro Recall 83.83%
Macro F1-Score 86.39%
Weighted F1-Score 99.85%

Model Characteristics

Property Value
Algorithm Random Forest
Dataset CICIDS2017
Features 77
Attack Classes 15
Test Samples 462,762
Evaluation Strategy Stratified Train/Test Split

Dataset Class Distribution

The CICIDS2017 dataset is highly imbalanced. Benign traffic dominates the dataset, while several attack classes contain only a limited number of samples.

Therefore, Macro F1 and class-wise metrics are reported together with Accuracy.


Evaluation Evidence

The evaluation was performed on 462,762 test samples using:

  • Accuracy
  • Macro Precision
  • Macro Recall
  • Macro F1-Score
  • Weighted F1-Score
  • Class-wise Precision
  • Class-wise Recall
  • Class-wise F1-Score

The noticeable difference between Macro F1 (86.39%) and Weighted F1 (99.85%) indicates that the model performs exceptionally well on majority classes while minority attack categories remain significantly more challenging.

Class-wise Performance

Attack Type Precision Recall F1-Score
Benign 99.91% 99.96% 99.93%
Bot 83.61% 69.10% 75.67%
DDoS 99.98% 99.94% 99.96%
DoS Hulk 99.82% 99.54% 99.68%
DoS Slowhttptest 94.94% 98.76% 96.81%
DoS Slowloris 99.63% 99.07% 99.35%
FTP-Patator 99.92% 99.33% 99.62%
PortScan 92.39% 90.03% 91.19%
SSH-Patator 100.00% 97.83% 98.90%
Web Attack Brute Force 74.67% 77.21% 75.92%
Web Attack XSS 43.01% 30.77% 35.87%

Note: Rare attack classes such as Heartbleed, SQL Injection, and Infiltration contain very few samples. Their reported metrics should therefore be interpreted with caution.

Normalized Confusion Matrix

The normalized confusion matrix provides a class-wise visualization of the model's predictive performance. It highlights that common attack categories are classified with high accuracy, whereas minority classes exhibit lower recall because of the severe class imbalance.

⚠️ Dataset Limitations

The model was trained using the CICIDS2017 dataset, which is highly imbalanced. While common attack categories contain hundreds of thousands of samples, several attack classes contain only a handful of instances.

Consequently:

  • Accuracy alone is not sufficient to evaluate the model.
  • Macro F1-Score is reported alongside Accuracy and Weighted F1-Score.
  • Minority attack classes may exhibit lower Recall despite the high overall Accuracy.

The PCAP module performs rule-based traffic assessment rather than machine learning classification.

Instead of predicting attack categories, it detects suspicious behaviors such as:

  • Port Scanning
  • High TCP Activity
  • Abnormal Flow Statistics

using heuristic rules extracted from NFStream flow statistics.

The reported evaluation metrics were obtained using the CICIDS2017 benchmark dataset. Although the model achieved high performance under this experimental setup, results may differ in real-world network environments due to variations in traffic patterns, attack diversity, and deployment conditions.

πŸ”¬ Data Leakage Considerations

The model was evaluated using a stratified train-test split to preserve the original class distribution.

Although this strategy prevents label imbalance, the CICIDS2017 dataset contains network flows collected during the same capture days. Therefore, highly similar network flows may appear in both training and testing subsets.

As a result, the reported evaluation metrics should be interpreted as benchmark results for the selected experimental setup rather than absolute real-world deployment performance.

Future work may include:

  • Day-based splitting
  • Time-based validation
  • Cross-day evaluation
  • External dataset validation

πŸ“‚ Project Structure

intelligent-network-intrusion-detection-risk-analysis-system
β”‚
β”œβ”€β”€ app.py
β”œβ”€β”€ csv_analyzer.py
β”œβ”€β”€ pcap_analyzer.py
β”œβ”€β”€ ui.py
β”œβ”€β”€ helpers.py
β”œβ”€β”€ constants.py
β”œβ”€β”€ network_attack_detector.pkl
β”œβ”€β”€ label_encoder.pkl
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ LICENSE
β”œβ”€β”€ notebooks/
β”‚   └── Network_Attack_Detection_Training.ipynb
└── screenshots/
    dashboard.png
    csv-analysis.png
    csv-visualization.png
    pcap-analysis.png
    class-distribution.png
    confusion-matrix-normalized.png

πŸš€ Installation

git clone https://github.com/efloq/Intelligent-Network-Intrusion-Detection-Risk-Analysis-System.git

cd intelligent-network-intrusion-detection-risk-analysis-system

python -m venv venv

# macOS / Linux
source venv/bin/activate

# Windows
venv\Scripts\activate

pip install -r requirements.txt

streamlit run app.py

πŸ“Š Supported File Formats

Module Supported Format
Machine Learning Analysis .csv
Flow-Based Analysis .pcap, .pcapng

Recommended maximum file sizes

  • CSV: 100 MB
  • PCAP / PCAPNG: 500 MB

πŸ“¦ Upload Limits

To reduce excessive memory usage and improve application stability, upload limits are applied before analysis.

File Type Maximum Size
CSV 100 MB
PCAP / PCAPNG 500 MB

Files exceeding these limits are rejected before processing.


πŸš€ Future Improvements

  • Real-time packet capture
  • Threat intelligence integration (AbuseIPDB / VirusTotal)
  • Automatic model calibration
  • Unit and integration tests
  • Live network monitoring
  • Docker deployment
  • REST API support
  • User authentication
  • Explainable AI (XAI) support

πŸ‘©β€πŸ’» Developer

Elifnur Sertkaya

Computer Engineering Student

Microsoft AI Innovators Internship Project


πŸ“š Dataset

This project uses the CICIDS2017 dataset developed by the Canadian Institute for Cybersecurity (CIC).

Reference

Sharafaldin, I., Lashkari, A. H., & Ghorbani, A. A.

Toward Generating a New Intrusion Detection Dataset and Intrusion Traffic Characterization.

International Conference on Information Systems Security and Privacy (ICISSP), 2018.

πŸ“„ License

This project is licensed under the MIT License.

πŸ“ˆ Project Statistics

Property Value
Language Python
Dataset CICIDS2017
ML Model Random Forest
Features 77
Attack Classes 15
Evaluation Samples 462,762
PCAP Engine NFStream
UI Framework Streamlit
Flow Analysis NFStream

About

Machine Learning based Network Attack Detection Dashboard using Random Forest, Streamlit and NFStream.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages