Skip to content

About

An MLOps solution for phishing website detection using machine learning. Features a complete pipeline from data ingestion to model deployment with FastAPI, containerized for AWS. Includes data validation, automated training, and an intuitive interface for analyzing network data with confidence scores and feature visualization.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

Β 

History

23 Commits

Folders and files

Repository files navigation

MLOps - Network Security Project: Phishing Detection System πŸ›‘οΈ

Python FastAPI MLOps AWS

πŸš€ Live Demo

Try out the live demo of the project: Network Security Project Demo

(Please note that the application may take a few minutes to start up on first access)

image

πŸ“‹ Table of Contents

πŸ” Project Overview

This Network Security Project is designed to detect phishing websites using machine learning techniques. The primary goal is to create a robust MLOps (Machine Learning Operations) solution with a clear and modular structure that can:

  1. Ingest data from MongoDB
  2. Validate data against a predefined schema
  3. Transform and preprocess the data
  4. Train machine learning models
  5. Deploy the best model via a FastAPI application
  6. Make batch predictions on new data
  7. Provide an easy-to-use interface for predictions

The project follows industry best practices for MLOps, ensuring reproducibility, scalability, and maintainability.

πŸ“ Project Structure

The project follows a modular architecture with separate components for each step in the ML lifecycle:

Network-Security-Project/
β”œβ”€β”€ app.py                     # FastAPI application
β”œβ”€β”€ Dockerfile                 # Docker configuration for containerization
β”œβ”€β”€ main.py                    # Main pipeline execution script
β”œβ”€β”€ push_data.py               # Script to push data to MongoDB
β”œβ”€β”€ requirements.txt           # Project dependencies
β”œβ”€β”€ setup.py                   # Package setup configuration
β”œβ”€β”€ training_status.json       # Training process status tracking
β”œβ”€β”€ test_mongodb.py            # MongoDB connection test script
β”œβ”€β”€ Artifacts/                 # Saved data artifacts by timestamp
β”‚   └── 05_18_2025_21_05_00/  # Example artifact directory
β”‚       β”œβ”€β”€ data_ingestion/    # Data fetching artifacts
β”‚       β”œβ”€β”€ data_transformation/ # Preprocessing artifacts
β”‚       β”œβ”€β”€ data_validation/   # Validation reports
β”‚       └── model_trainer/     # Model artifacts
β”œβ”€β”€ daily_logs/                # Daily operation logs
β”œβ”€β”€ logs/                      # Detailed timestamped log files
β”œβ”€β”€ data_schema/               # Data validation schemas
β”‚   └── schema.yaml            # Schema definition file
β”œβ”€β”€ final_model/               # Production-ready model
β”‚   β”œβ”€β”€ model.pkl              # Trained model
β”‚   └── preprocessor.pkl       # Data preprocessor
β”œβ”€β”€ Network_Data/              # Raw dataset directory
β”‚   └── phisingData.csv        # Phishing website dataset
β”œβ”€β”€ prediction_output/         # Directory for prediction results
β”‚   └── output.csv             # Example prediction output
β”œβ”€β”€ valid_data/                # Validated data for testing
β”‚   └── test.csv               # Test dataset
β”œβ”€β”€ templates/                 # HTML templates for the web interface
β”‚   β”œβ”€β”€ index.html             # Landing page
β”‚   β”œβ”€β”€ prediction.html        # Prediction interface
β”‚   β”œβ”€β”€ train_model.html       # Model training interface
β”‚   β”œβ”€β”€ training_complete.html # Training success page
β”‚   └── table.html             # Results display page
β”œβ”€β”€ static/                    # Static assets for the frontend
β”‚   β”œβ”€β”€ css/                   # CSS stylesheets
β”‚   β”œβ”€β”€ js/                    # JavaScript files
β”‚   └── img/                   # Images and icons
└── networksecurity/           # Core package
    β”œβ”€β”€ __init__.py            # Package initialization
    β”œβ”€β”€ components/            # Pipeline components
    β”‚   β”œβ”€β”€ __init__.py        # Component initialization
    β”‚   β”œβ”€β”€ data_ingestion.py  # Data loading from MongoDB
    β”‚   β”œβ”€β”€ data_validation.py # Schema validation
    β”‚   β”œβ”€β”€ data_transformation.py # Feature engineering
    β”‚   └── model_trainer.py   # Model training and evaluation
    β”œβ”€β”€ cloud/                 # Cloud integration (AWS S3)
    β”‚   β”œβ”€β”€ __init__.py        # Cloud module initialization
    β”‚   └── s3_syncer.py       # AWS S3 synchronization
    β”œβ”€β”€ constant/              # Project constants and configurations
    β”œβ”€β”€ entity/                # Data classes and entities
    β”œβ”€β”€ exception/             # Custom exception handling
    β”œβ”€β”€ logging/               # Logging configuration
    β”œβ”€β”€ pipeline/              # ML pipelines
    └── utils/                 # Utility functions

✨ Features

  • πŸ”„ End-to-end MLOps pipeline
  • πŸ“Š Data validation with schema enforcement
  • 🧠 Machine learning model training with hyperparameter tuning
  • πŸš€ FastAPI-based REST API for real-time predictions
  • 🎨 Modern, responsive web interface with cybersecurity aesthetics
  • πŸ“± User-friendly UI for model training and predictions
  • πŸ“¦ Containerization with Docker
  • ☁️ AWS deployment ready
  • πŸ” CI/CD with GitHub Actions for automated testing and deployment
  • πŸ“ˆ Experiment tracking with MLflow
  • πŸ”’ Security-focused for phishing detection

πŸ› οΈ Local Installation

  1. Clone the repository:

    git clone https://github.com/cmatiass/Network-Security-Project.git
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Set up environment variables:

    # Create a .env file with:
    MONGODB_URL_KEY=your_mongodb_connection_string
    
  4. Install the package in development mode:

    pip install -e .
    

πŸš€ Usage

Running the Application

  1. After installation, start the FastAPI application:

    python app.py
    
  2. The application will start on http://localhost:8000

  3. Open your web browser and navigate to this address

  4. You'll see the main dashboard with options to:

    • Learn about the project
    • Train a new model
    • Make predictions on network data

Training a Model

  1. Navigate to the "Train Model" page
  2. Click the "Start Training" button
  3. The system will display real-time progress of the training pipeline
  4. Once complete, you'll see performance metrics and can proceed to making predictions

Making Predictions

  1. Navigate to the "Make Prediction" page
  2. Upload your network data in CSV format, or use the provided sample data
  3. Click "Analyze Network Data"
  4. View the detailed results showing:
    • Classification results (safe or malicious)
    • Confidence scores
    • Feature importance
    • Summary statistics

Sample Data

The project includes a test.csv file in the valid_data directory that can be used to test the prediction functionality. This sample data contains various network security features like:

  • IP address characteristics
  • URL properties
  • Domain registration information
  • SSL certificate status
  • HTTP/HTTPS token information

πŸ”„ MLOps Pipeline

The project implements a comprehensive MLOps pipeline:

1. Data Ingestion πŸ“₯

  • Connects to MongoDB to fetch phishing data
  • Splits data into training and testing sets
  • Stores the split data as artifacts

2. Data Validation βœ…

  • Validates the dataset against a predefined schema (schema.yaml)
  • Checks for missing values, data types, and column names
  • Generates validation reports

3. Data Transformation πŸ”„

  • Preprocesses the data with appropriate scaling and encoding
  • Handles categorical features
  • Creates preprocessor pipeline artifacts

4. Model Training πŸ§ͺ

  • Trains multiple classification algorithms
  • Performs hyperparameter tuning
  • Evaluates models using appropriate metrics
  • Selects the best performing model

5. Model Deployment πŸš€

  • Packages the model with a FastAPI application
  • Exposes REST API endpoints for predictions
  • Containerizes the application with Docker

🌐 API Endpoints

The application provides several API endpoints for both frontend functionality and direct programmatic access:

Frontend Pages

  • GET /: Main landing page with project overview
  • GET /train-model: Model training interface
  • GET /prediction: Prediction interface for data uploads
  • GET /training-complete: Training completion confirmation page

API Functionality

  • POST /train-status: Initiates model training process
  • POST /finalize-training: Finalizes and persists the trained model
  • GET /check-model: Checks if a trained model exists and its status
  • POST /predict: Makes predictions on uploaded data
  • GET /predict-sample: Makes predictions using the sample test dataset

Example API Usage:

Check if model exists:

import requests
response = requests.get("http://localhost:8000/check-model")
print(response.json())
# {"trained": true, "status": "completed"}

Upload data for prediction:

import requests
files = {"file": open("network_data.csv", "rb")}
response = requests.post("http://localhost:8000/predict", files=files)
# Returns HTML with prediction results

Use sample data for prediction:

import requests
response = requests.get("http://localhost:8000/predict-sample")
# Returns HTML with prediction results using test.csv

☁️ Deployment on AWS

The project is designed to be deployed on AWS following these steps:

  1. Build Docker Image:

    docker build -t network-security-project .
    
  2. Push to Amazon ECR:

    aws ecr get-login-password --region <region> | docker login --username AWS --password-stdin <account-id>.dkr.ecr.<region>.amazonaws.com
    docker tag network-security-project:latest <account-id>.dkr.ecr.<region>.amazonaws.com/network-security-project:latest
    docker push <account-id>.dkr.ecr.<region>.amazonaws.com/network-security-project:latest
    
  3. Deploy on ECS/Fargate:

    • Create an ECS cluster
    • Define a task definition using the ECR image
    • Create a service with desired configurations
    • Set up Application Load Balancer for exposing the API
  4. Model Storage:

    • Models are stored in S3 using the S3 syncer utility
    • This allows for version control of models

πŸ” CI/CD Pipeline

This project implements Continuous Integration and Continuous Deployment using GitHub Actions:

  1. Automated Testing:

    • Every push and pull request to the main branch triggers automated tests
    • Unit tests validate individual components
    • Integration tests verify the entire pipeline functionality
  2. Continuous Deployment:

    • Successful builds on the main branch automatically deploy to AWS
    • The workflow builds the Docker image, pushes it to ECR, and updates the ECS service
    • Environment variables are securely stored as GitHub Secrets

The CI/CD pipeline ensures that the application is always in a deployable state, reducing manual errors and speeding up the development process.

πŸ‘₯ Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License

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


Created with ❀️ for secure networks

About

An MLOps solution for phishing website detection using machine learning. Features a complete pipeline from data ingestion to model deployment with FastAPI, containerized for AWS. Includes data validation, automated training, and an intuitive interface for analyzing network data with confidence scores and feature visualization.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages