Skip to content

sovandas089/WAF-IDS

Repository files navigation

WAFGuardian - SOC-Level Web Application Firewall

πŸš€ Project Overview

WAFGuardian is a production-ready, SOC-level Web Application Firewall (WAF) built entirely in Python. It serves as a reverse proxy that sits between internet clients and protected backend servers, intercepting and analyzing all HTTP traffic in real-time. The system employs a sophisticated rule-based scoring engine to detect and block malicious actors, featuring automated IP blocking via Windows Firewall integration.

Key Features

  • πŸ” Real-Time Threat Detection: Advanced scoring engine detecting SQL Injection, XSS, and brute force attacks
  • πŸ›‘οΈ Automated IP Blocking: Integrates with Windows Firewall for automatic threat mitigation
  • πŸ“Š SOC Dashboard: Live WebSocket-based dashboard with real-time alerts and analytics
  • πŸ“§ Email Alerting: SMTP-based notifications for critical security events
  • πŸ’Ύ Persistent Logging: SQLite database for comprehensive threat history
  • πŸ”¬ Forensic Analysis: Offline PCAP file analysis for incident response
  • ⏰ Auto-Unblocking: Temporary blocks with automatic expiration (15 minutes)
  • 🌐 Reverse Proxy Architecture: Inline inspection without backend modifications

πŸ“Έ Quick Visual Overview

SOC Dashboard Real-Time Alerts Threat Analytics
Dashboard Alerts Analytics

System Architecture & Workflow: WAF Workflow

πŸ—οΈ System Architecture

Internet Client
      β”‚
      β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  WAFGuardian WAF    β”‚  ← Port 8085
β”‚  (Reverse Proxy)    β”‚
β”‚  FastAPI + httpx    β”‚
β”‚                     β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚ Scoring Engine  β”‚ β”‚  ← analyzer.py
β”‚ β”‚ +5 SQLi         β”‚ β”‚
β”‚ β”‚ +5 XSS          β”‚ β”‚
β”‚ β”‚ +10 Brute Force β”‚ β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚         β”‚ Score β‰₯ 10β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚   IP Blocker    β”‚ β”‚  ← blocker.py (netsh)
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚   SQLite DB     β”‚ β”‚  ← database.py
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚
β”‚ β”‚  SMTP Mailer    β”‚ β”‚  ← mailer.py
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚ (Clean traffic only)
          β–Ό
  Protected Backend Server
  (localhost:9000)

For a detailed visual workflow, see the WAF Architecture Diagram below.

πŸ“Έ Screenshots & Visual Documentation

SOC Dashboard - Main Interface

The primary dashboard showing real-time threat monitoring, system status, and analytics overview.

SOC Dashboard

Real-Time Alerts Panel

Live WebSocket-powered alerts display showing active threats, blocked IPs, and security events as they occur.

Real-Time Alerts

Real-Time Alert Email

Live Email Alerts On Suspecious Activities.

Real-Tie Mail Alert

Threat Analytics Dashboard

Comprehensive analytics view with charts, statistics, and historical threat data for SOC analysis.

Threat Analytics

System Status Overview

General system monitoring view showing WAF operational status and key metrics.

System View

WAF Architecture Diagram

Visual representation of the WAFGuardian system architecture and data flow.

WAF Workflow

πŸ› οΈ Technology Stack

  • Backend: Python 3.8+, FastAPI, SQLAlchemy, SQLite
  • Network Analysis: Scapy for packet capture and PCAP analysis
  • Frontend: Vanilla HTML5, CSS3, JavaScript (ES6+)
  • Real-Time Communication: WebSockets
  • Firewall Integration: Windows netsh commands
  • Email: SMTP (Gmail)
  • Configuration: YAML-based rule engine

πŸ“ Project Structure

WAFGuardian/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app.py              # Main FastAPI application & reverse proxy
β”‚   β”œβ”€β”€ analyzer.py         # Threat scoring engine
β”‚   β”œβ”€β”€ blocker.py          # Windows Firewall integration
β”‚   β”œβ”€β”€ database.py         # SQLite database operations
β”‚   β”œβ”€β”€ mailer.py           # SMTP email alerting
β”‚   β”œβ”€β”€ models.py           # SQLAlchemy ORM models
β”‚   β”œβ”€β”€ rules.yaml          # Detection rules configuration
β”‚   └── sniffer.py          # Network packet capture
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ index.html          # SOC dashboard UI
β”‚   β”œβ”€β”€ css/
β”‚   β”‚   └── style.css       # Dark cyberpunk styling
β”‚   └── js/
β”‚       └── main.js         # WebSocket client & dashboard logic
β”œβ”€β”€ tests/
β”‚   └── test_attacks.py     # Automated security tests
β”œβ”€β”€ Pics/                   # Project screenshots & diagrams
β”œβ”€β”€ requirements.txt        # Python dependencies
β”œβ”€β”€ implementation_plan.md  # Development roadmap
└── README.md              # This file

πŸš€ Quick Start

Prerequisites

  • Python 3.8 or higher
  • Windows 10/11 (for netsh firewall integration)
  • Administrator privileges (required for IP blocking)
  • Npcap or WinPcap (for live packet capture)

Installation

  1. Clone the repository

    git clone https://github.com/sovandas089/WAF-IDS.git
    cd WAF-IDS
  2. Create virtual environment

    python -m venv .venv
    .\.venv\Scripts\activate
  3. Install dependencies

    pip install -r requirements.txt
  4. Configure email alerting (optional)

    • Edit backend/mailer.py with your Gmail credentials
    • Enable "Less secure app access" or use App Passwords

Running the Application

  1. Start the WAF server

    # Run as Administrator for firewall blocking capabilities
    .\.venv\Scripts\python.exe -m backend.app
  2. Access the SOC Dashboard

    • Open browser: http://localhost:8085/dashboard
    • View real-time alerts and analytics
    • Upload PCAP files for forensic analysis
  3. Configure protected backend

    • Ensure your web application runs on localhost:9000
    • All traffic will be routed through WAFGuardian on port 8085

πŸ”§ Configuration

Detection Rules

Edit backend/rules.yaml to customize threat detection:

rules:
  sqli:
    - '(?i)(SELECT|UPDATE|INSERT|DELETE|DROP|UNION).*?(FROM|INTO)'
    - '(?i)(%27)|('')|(--)|(%23)|(#)'
  xss:
    - '(?i)<script>.*?</script>'
    - '(?i)onerror\s*='
thresholds:
  brute_force:
    max_requests: 20
    time_window_seconds: 10

Scoring System

Attack Type Score Block Threshold
SQL Injection +5 β‰₯ 10 total
XSS +5 β‰₯ 10 total
Brute Force +10 β‰₯ 10 total

πŸ§ͺ Testing

Run the automated test suite:

.\.venv\Scripts\python.exe tests\test_attacks.py

Tests include:

  • SQL Injection detection
  • XSS payload blocking
  • Brute force rate limiting

πŸ“Š API Endpoints

Endpoint Method Description
/dashboard GET SOC dashboard UI
/dashboard/api/rules GET Current detection rules
/dashboard/api/stats GET Threat analytics data
/dashboard/api/analyze_pcap POST PCAP forensic analysis
/dashboard/ws/alerts WS Real-time alert stream

πŸ”’ Security Features

  • Multi-Factor Threat Scoring: Prevents false positives
  • Temporary IP Blocks: 15-minute auto-expiration
  • Comprehensive Logging: Full audit trail in SQLite
  • Email Notifications: SOC team alerting
  • Offline Analysis: PCAP file processing
  • WebSocket Security: Real-time dashboard updates

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new features
  5. Submit a pull request

πŸ“ License

This project is developed as part of academic coursework at OP Jindal University.

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

Sovan Das - BTL23CS08

⚠️ Important Notes

  • Administrator Privileges: Required for Windows Firewall integration
  • Network Capture: May require Npcap/WinPcap installation
  • Port Usage: WAF runs on port 8085, backend should use 9000
  • Email Configuration: Update SMTP settings in mailer.py for alerts

Built with ❀️ for cybersecurity education and SOC operations

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors