Sovereign 8s.is mirror of standardgalactic/RepLearningDetectBotnetAttack
  • Jupyter Notebook 100%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
occbuu 78e72c83ec u3
2026-02-07 10:09:27 +07:00
data update structure 2026-02-07 09:59:15 +07:00
32botnet_detection_colab.ipynb first commit 2026-02-07 09:34:48 +07:00
32botnet_detection_colab.pdf update pdf 2026-02-07 09:49:55 +07:00
64botnet_detection_colab.ipynb first commit 2026-02-07 09:34:48 +07:00
64botnet_detection_colab.pdf update pdf 2026-02-07 09:49:55 +07:00
128botnet_detection_colab.ipynb update pdf 2026-02-07 09:49:55 +07:00
128botnet_detection_colab.pdf update pdf 2026-02-07 09:49:55 +07:00
MANUSCRIPT.md u3 2026-02-07 10:09:27 +07:00
README.md update readme 2026-02-07 10:04:23 +07:00
requirements.txt update structure 2026-02-07 09:59:15 +07:00

Botnet Detection Project

A comprehensive machine learning project for detecting botnets using deep neural networks and traffic analysis. This project implements multiple models with different configurations to achieve robust botnet detection and classification.

Project Overview

This project focuses on identifying and classifying botnet traffic using advanced machine learning techniques. It includes three different model configurations with varying parameters to test and optimize detection accuracy.

Project Structure

├── 32botnet_detection_colab.ipynb       # Model with 32-unit configurations
├── 64botnet_detection_colab.ipynb       # Model with 64-unit configurations
├── 128botnet_detection_colab copy.ipynb # Model with 128-unit configurations
└── README.md                             # Project documentation

Models

The project contains three Jupyter notebooks, each implementing a botnet detection model with different neural network configurations:

1. 32botnet_detection_colab.ipynb

  • Uses 32-unit dense layers
  • Lightweight configuration for resource-constrained environments
  • Suitable for rapid prototyping and initial experiments

2. 64botnet_detection_colab.ipynb

  • Uses 64-unit dense layers
  • Balanced between model complexity and computational resources
  • Recommended for production environments

3. 128botnet_detection_colab copy.ipynb

  • Uses 128-unit dense layers
  • More complex model architecture
  • Better for achieving higher accuracy on complex datasets

Features

  • Data Preprocessing: Automatic handling of network traffic data and feature extraction
  • Model Training: Multi-epoch training with validation and loss tracking
  • Visualization: Loss curves and performance metrics plotting
  • Colab Integration: Automatic Google Drive mounting and environment detection
  • Flexible Configuration: Works on both Google Colab and local machines

Technical Stack

  • Python 3.x
  • TensorFlow/Keras - Deep learning framework
  • NumPy - Numerical computing
  • Matplotlib & Seaborn - Data visualization
  • Scikit-learn - Machine learning utilities

Setup & Usage

Running on Google Colab

  1. Upload the notebook to Google Colab
  2. The notebook will automatically detect the Colab environment
  3. Grant access to Google Drive for data storage
  4. Run all cells sequentially

Running Locally

  1. Ensure Python 3.x is installed with required dependencies:
    pip install tensorflow numpy matplotlib seaborn scikit-learn
    
  2. Install Jupyter Notebook or JupyterLab:
    pip install jupyter
    
  3. Launch the notebook:
    jupyter notebook 32botnet_detection_colab.ipynb
    

Usage Examples

Each notebook follows this workflow:

  1. Data Preparation - Load and preprocess network traffic data
  2. Model Definition - Define neural network architecture
  3. Training - Train the model with validation monitoring
  4. Evaluation - Assess model performance
  5. Visualization - Generate loss curves and performance plots
  6. Export - Save visualizations and trained models

Model Architecture

All models follow a similar architecture with varying layer sizes:

Input Layer
    ↓
Dense Layer (32/64/128 units, ReLU activation)
    ↓
Dropout Layer
    ↓
Dense Layer (32/64/128 units, ReLU activation)
    ↓
Dropout Layer
    ↓
Output Layer (Sigmoid activation for binary classification)

Performance Metrics

The models are evaluated using:

  • Training Loss - Cross-entropy loss during training
  • Validation Loss - Cross-entropy loss on validation set
  • Accuracy - Classification accuracy
  • Precision, Recall, F1-Score - Detailed performance metrics

Key Parameters

  • Batch Size: Configurable for memory optimization
  • Epochs: 12 epochs as default (adjustable)
  • Learning Rate: Automatically optimized by Adam optimizer
  • Dropout Rate: 0.2-0.3 for regularization

Output Files

The notebooks generate:

  • loss_plot_12_epochs.pdf - High-quality loss visualization (vector format)
  • loss_plot_12_epochs.png - PNG version of loss plot (300 DPI)
  • Trained model files (.h5 or .keras format)
  • Classification reports and confusion matrices

Configuration

The notebooks include automatic environment detection:

# Auto-detect Colab environment
try:
    import google.colab
    IS_COLAB = True
except ImportError:
    IS_COLAB = False

You can manually override this by setting IS_COLAB = True or IS_COLAB = False as needed.

Data Requirements

  • Network traffic dataset in compatible format (CSV, HDF5, or NumPy)
  • Features should include network flow characteristics
  • Labels should indicate botnet vs. benign traffic
  • Minimum dataset size: ~5000 samples for reliable training

Troubleshooting

Issue Solution
Google Drive not mounting Check Colab authentication and Drive permissions
CUDA out of memory Reduce batch size or use smaller model (32-unit)
Data not found Verify data path and file permissions
Training too slow Enable GPU acceleration in Colab settings

Results Interpretation

  • Training Loss: Should decrease steadily over epochs
  • Validation Loss: Should decrease and stabilize (overfitting if diverges from training loss)
  • Gap between train/val loss: Indicates model generalization quality

Example from the project:

Epoch 1:  Training Loss = 0.0606, Validation Loss = 0.5069
Epoch 12: Training Loss = 0.0000, Validation Loss = 0.0028

Future Improvements

  • Add ensemble methods combining all three models
  • Implement real-time detection capabilities
  • Add explainability features (SHAP, attention mechanisms)
  • Support for multi-class botnet classification
  • Performance optimization for edge devices
  • Integration with network monitoring tools

References

  • Network traffic analysis literature
  • Deep learning best practices for anomaly detection
  • TensorFlow/Keras documentation

License

This project is part of the Paper2026 research initiative.

Contact & Support

For questions or issues related to this project, please refer to the project documentation or contact the development team.


Manuscript Submission

Application of Representation Learning in Detecting Botnet Attacks

Author: Hieu Le Ngoc

Affiliation: Faculty of Information Technology, Van Hien University

Status: Under Revision at Scientific Reports

Abstract Botnet detection remains a perennial and critical challenge in cybersecurity. This paper introduces a robust framework that significantly enhances botnet detection by combining advanced feature engineering—such as octet splitting for IP addresses—with a sophisticated representation learning technique using the Hilbert space-filling curve to transform network flows into 2D images.

We address class imbalance using SMOTE and Focal Loss. Evaluating strictly on a cross-scenario basis (Training on CTU-13 Scenario 8, Testing on unseen Scenario 10), our ResNet-18 based model achieved 98.34% accuracy and a weighted F1-score of 98.38%, outperforming traditional Random Forest baselines which failed to generalize.

Methodology

The Pipeline

  • Preprocessing: Raw NetFlows are cleaned. Background and Normal traffic are merged into a "Benign" class.
  • Feature Engineering:
    • IP Octet Splitting (Source/Dest IP -> 4 features each).
    • Frequency Encoding for Ports/Protocols.
    • Min-Max Scaling.
  • Final Vector Size: N = 19.
  • Hilbert Transformation: The 1D feature vector is mapped to a 2D grid (32×32, 64×64, etc.) using the Hilbert Space-Filling Curve to preserve data locality.
  • Classification: A modified ResNet-18 (1-channel input) trained with Focal Loss to handle class imbalance.

Getting Started

Prerequisites The code is implemented in Python 3.8+ using PyTorch.

Clone the repo:

git clone https://github.com/occbuu/RepLearningDetectBotnetAttack.git
cd RepLearningDetectBotnetAttack

Install dependencies:

pip install -r requirements.txt

Dataset This project uses the CTU-13 Dataset. Due to size constraints, the raw PCAP/NetFlow files are not included in this repo.

  • Training: Scenario 8 (Murlo)
  • Testing: Scenario 10 (Rbot)

Download the dataset from the Stratosphere IPS Repository.

Running the Model

To train the model on Scenario 8 and evaluate on Scenario 10:

python main.py --mode train --image_size 32 --epochs 12

To run inference on a new pcap file:

python main.py --mode predict --input data/my_traffic.csv

Results

Model Configuration Accuracy F1-Score (Weighted) Recall (Botnet)
ResNet-18 (32x32) 98.34% 98.38% 98.34%
ResNet-18 (64x64) 98.07% 98.07% 98.07%
ResNet-18 (128x128) 97.12% 97.12% 97.12%
Random Forest 91.88% 90.99% 0.02% (Fail)

Repository Structure (key files)

  • src/hilbert_curve.py: Implementation of the algorithm to map 1D arrays to 2D Hilbert images.
  • src/model.py: Custom ResNet-18 architecture modified for grayscale (1-channel) input.
  • src/utils.py: Implementation of Focal Loss and metric calculations.

Citation If you use this code or methodology, please cite our paper:

Le Ngoc, H. (2026). Application of Representation Learning in Detecting Botnet Attacks. Scientific Reports (Under Review).

Final Checklist for the Editor

When the editor requests "accessible supplementary files", include the following statement in your response letter:

"The full source code, model architecture, and reproduction scripts have been updated and are publicly available at our GitHub repository: https://github.com/occbuu/RepLearningDetectBotnetAttack. We have ensured all dependencies are listed for easy replication."


Last Updated: February 7, 2026
Project Status: Active Development