Skip to content

suhasdk18/phish-guard

Repository files navigation

πŸ›‘οΈ Phishing Detection System

A comprehensive email security system that automatically detects, quarantines, and responds to phishing attempts using machine learning and rule-based detection.

πŸ“‹ Features

πŸ” Detection Engine

  • Machine Learning Classifier: Trained on phishing datasets using scikit-learn
  • Rule-Based Engine: Pattern matching for suspicious keywords, URLs, and domains
  • Attachment Analysis: OCR text extraction and VirusTotal scanning
  • Multi-layered Detection: Combines ML predictions with rule-based analysis

πŸ“§ Email Processing

  • MailHog Integration: For testing environments
  • Postfix Support: For production mail servers
  • Real-time Processing: Continuous email monitoring
  • Attachment Handling: Safe analysis of email attachments

πŸ—„οΈ Quarantine System

  • Secure Storage: SQLite database for quarantined emails
  • Risk Scoring: Detailed threat assessment
  • Safe Preview: Read-only email viewing with disabled links
  • Bulk Management: Release, delete, or mark false positives

🚨 Incident Response

  • Automated Blacklisting: Domain and IP blocking
  • Smart Notifications: User and SOC team alerts
  • Response Tracking: Detailed incident logging
  • Escalation Rules: Risk-based alert prioritization

πŸŽ“ User Training

  • Interactive Quizzes: Security awareness testing
  • Progress Tracking: Individual performance metrics
  • Gamification: Leaderboards and achievements
  • Personalized Training: Recommendations based on exposure

πŸ“Š Monitoring & Analytics

  • Web Dashboard: Real-time security overview
  • Detailed Reports: Threat statistics and trends
  • Performance Metrics: System health monitoring
  • Export Capabilities: Data export for analysis

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Email Server  │───▢│  Detection      │───▢│   Quarantine    β”‚
β”‚  MailHog/Postfixβ”‚    β”‚  ML + Rules     β”‚    β”‚   SQLite DB     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Web Dashboard β”‚    β”‚  Incident       β”‚    β”‚  User Training  β”‚
β”‚   Flask App     β”‚    β”‚  Response       β”‚    β”‚  Quiz System    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β–Ό
                       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                       β”‚   Monitoring    β”‚
                       β”‚  ELK + Grafana  β”‚
                       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Prerequisites

  • Python 3.8+
  • Docker & Docker Compose (optional)
  • SQLite3

1. Installation

git clone https://github.com/suhasdk18/phishing-detection-system.git
cd phishing-detection-system

python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install -r requirements.txt

2. Configuration

cp config.yml.example config.yml
# Edit config.yml with your settings

3. Initialize Database

python main.py --init-db

4. Start Services

Option A: Using Docker Compose (Recommended)

docker-compose up -d

Option B: Manual Setup

# Start MailHog for testing
docker run -d -p 1025:1025 -p 8025:8025 mailhog/mailhog

# Start Detection System
python main.py

# In another terminal, start Web Dashboard
python app.py

5. Access Services

πŸ“Š Usage

Web Dashboard

Navigate to http://localhost:5000 to access the main dashboard featuring:

  • Real-time threat overview
  • Quarantined email management
  • User training portal
  • System statistics

Command Line Interface

# Start monitoring
python main.py --mode monitor --interval 30

# Train ML model
python main.py --mode train --dataset data/phishing_dataset.csv

# Test single batch
python main.py --mode test

# Initialize databases
python main.py --init-db

API Endpoints

  • GET /api/stats - System statistics
  • GET /api/quarantine - List quarantined emails
  • POST /api/quarantine/{id}/release - Release email
  • POST /api/quarantine/{id}/delete - Delete email
  • GET /api/training/quiz - Get quiz questions
  • POST /api/training/submit - Submit quiz answers

πŸ“ Project Structure

phishing-detection-system/
β”œβ”€β”€ main.py                 # Main application entry point
β”œβ”€β”€ app.py                  # Web dashboard application
β”œβ”€β”€ requirements.txt        # Python dependencies
β”œβ”€β”€ config.yml             # Configuration file
β”œβ”€β”€ docker-compose.yml     # Docker services setup
β”œβ”€β”€ Dockerfile            # Container image definition
β”œβ”€β”€ README.md            # This file
β”œβ”€β”€ .env.example         # Environment variables template
β”œβ”€β”€ .gitignore          # Git ignore rules
β”œβ”€β”€ src/                # Source code modules
β”‚   β”œβ”€β”€ detection/      # ML and rule-based detection
β”‚   β”œβ”€β”€ quarantine/     # Email quarantine system
β”‚   β”œβ”€β”€ response/       # Incident response automation
β”‚   β”œβ”€β”€ training/       # User training system
β”‚   └── utils/          # Utility functions
β”œβ”€β”€ templates/          # HTML templates for web UI
β”œβ”€β”€ static/            # CSS, JS, and image assets
β”œβ”€β”€ data/              # Data storage directory
β”‚   β”œβ”€β”€ models/        # ML models
β”‚   β”œβ”€β”€ datasets/      # Training datasets
β”‚   └── quarantine/    # Quarantined emails
β”œβ”€β”€ logs/              # Application logs
β”œβ”€β”€ tests/             # Unit and integration tests
└── docs/              # Additional documentation

πŸ”§ Configuration

Edit config.yml to customize the system:

# Email server settings
email:
  mode: "mailhog"  # or "postfix"
  host: "localhost"
  port: 8025

# Detection thresholds
detection:
  ml_threshold: 0.7
  rule_threshold: 50
  combined_threshold: 0.6

# External APIs
apis:
  virustotal_key: "your_api_key"
  abuseipdb_key: "your_api_key"

# Notifications
notifications:
  smtp_host: "localhost"
  smtp_port: 1025
  from_address: "[email protected]"
  soc_email: "[email protected]"

πŸ§ͺ Testing

Unit Tests

python -m pytest tests/unit/

Integration Tests

python -m pytest tests/integration/

Send Test Phishing Email

curl -X POST http://localhost:8025/api/v1/messages \
  -H "Content-Type: application/json" \
  -d '{
    "from": "[email protected]",
    "to": ["[email protected]"],
    "subject": "URGENT: Verify your account immediately",
    "body": "Click here to verify: http://malicious-link.com"
  }'

πŸ“ˆ Monitoring

Grafana Dashboards

Access Grafana at http://localhost:3000 with:

  • Username: admin
  • Password: admin

Pre-configured dashboards include:

  • Email Processing Overview
  • Threat Detection Statistics
  • System Performance Metrics
  • User Training Progress

ELK Stack

Kibana available at http://localhost:5601 for:

  • Log analysis and searching
  • Custom visualizations
  • Alert management
  • Data exploration

πŸ”’ Security Features

  • Sandboxed Email Preview: Safe viewing without executing malicious content
  • Automated Quarantine: Immediate isolation of suspicious emails
  • Blacklist Management: Dynamic blocking of malicious senders/domains
  • Audit Trail: Comprehensive logging of all security events
  • Access Controls: Role-based permissions for dashboard access

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

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

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

suhasdk18

πŸ™ Acknowledgments

  • PhishTank for phishing URL datasets
  • VirusTotal for malware detection API
  • scikit-learn for machine learning capabilities
  • Flask for web framework
  • The cybersecurity community for threat intelligence

πŸ“ž Support

If you encounter any issues or have questions:

  1. Check the Issues page
  2. Review the documentation in the docs/ directory
  3. Contact the maintainer at [email protected]

πŸ”„ Version History

  • v1.0.0 - Initial release with basic detection and quarantine
  • v1.1.0 - Added user training system and web dashboard
  • v1.2.0 - Integrated ELK stack and Grafana monitoring
  • v1.3.0 - Enhanced ML models and attachment analysis

⭐ Star this repo if you find it helpful!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published