GitHunt
SY

SyedShaheerHussain/Web-Application-Firewall-WAF-Simulation-GUI

Monitors, Detects, and Blocks SQL Injection and XSS attacks in real time.

๐Ÿ›ก๏ธ Web Application Firewall (WAF) Simulation

Monitors, Detects, and Blocks SQL Injection and XSS attacks in real time.

Developed By: ยฉ Syed Shaheer Hussain

๐Ÿ“˜ Description

This project is a fully functional Web Application Firewall (WAF) Simulation built using Python and FastAPI, designed for educational, demonstration, and learning purposes. It simulates how a real-world WAF protects web applications from common web attacks such as SQL Injection (SQLi) and Cross-Site Scripting (XSS).

The system acts as a middleware layer between users and a protected web application, inspecting every incoming request, detecting malicious payloads, blocking attacks, and visualizing traffic statistics through a modern web dashboard.

๐Ÿ“ท Screenshots

Screenshot 1

Screenshot 2

Screenshot 3

Screenshot 4

Screenshot 5

Screenshot 6

๐ŸŽฏ Objectives

  1. Understand how a WAF works internally
  2. Detect and block SQL Injection & XSS attacks
  3. Visualize allowed vs blocked traffic
  4. Learn middleware-based security enforcement
  5. Simulate real-world web security behavior
  6. Provide an FYP / cybersecurity demo-ready project

๐Ÿง  Concepts Covered

  • Web Security
  • Web Application Firewall (WAF)
  • SQL Injection (SQLi)
  • Cross-Site Scripting (XSS)
  • HTTP Middleware
  • Pattern Matching (Regex)
  • Traffic Monitoring
  • Secure Coding Practices
  • Cybersecurity Defense Simulation

โ“ What is a WAF?

A Web Application Firewall (WAF) is a security layer that:

  • Monitors HTTP/HTTPS traffic
  • Filters malicious requests
  • Blocks web-based attacks
  • Protects backend applications and databases

๐Ÿ” WAF sits between the client (browser) and the server (application).

๐Ÿ’ก Value of This Project

  • Helps students understand real-world web security
  • Demonstrates attack detection logic
  • Ideal for Final Year Projects (FYP)
  • Practical cybersecurity learning
  • Extendable to ML-based detection

๐Ÿ—๏ธ Architecture

๐Ÿ”„ Request Flow

  1. User sends request from browser
  2. Request passes through WAF middleware
  3. Payload extracted (query + body)
  4. SQLi/XSS rules applied
  5. Decision made (Allow / Block)
  6. Stats updated
  7. Dashboard updated

๐Ÿ“Š Flow Chart (Textual)

Browser Request
      โ†“
WAF Middleware
      โ†“
Payload Normalization
      โ†“
Rule Engine (SQLi / XSS)
      โ†“
Decision
  โ†“        โ†“
Allow     Block
  โ†“        โ†“
App     Error Page

๐Ÿ“‚ Folder Structure

WAF-Project/
โ”‚
โ”œโ”€โ”€ main.py              # FastAPI app & middleware
โ”œโ”€โ”€ waf_engine.py        # Detection logic
โ”œโ”€โ”€ rules.py             # SQLi & XSS regex patterns
โ”œโ”€โ”€ logger.py            # Attack logging
โ”œโ”€โ”€ templates/
โ”‚   โ”œโ”€โ”€ login.html
โ”‚   โ””โ”€โ”€ dashboard.html
โ”œโ”€โ”€ static/
โ”‚   โ””โ”€โ”€ style.css
โ”œโ”€โ”€ logs/
โ”‚   โ””โ”€โ”€ attacks.log
โ”œโ”€โ”€ requirements.txt
โ””โ”€โ”€ README.md

๐Ÿ› ๏ธ Technologies Used

  • ๐Ÿ Python 3.10+
  • โšก FastAPI
  • ๐ŸŒ HTML5, CSS3, JavaScript
  • ๐Ÿ“Š Chart.js
  • ๐Ÿ” Regex-based Detection
  • ๐Ÿงช REST APIs

๐Ÿงช Features

  1. โœ… SQL Injection detection
  2. โœ… XSS attack detection
  3. ๐Ÿ“Š Live traffic visualization
  4. ๐Ÿšซ Automatic request blocking
  5. ๐Ÿ“ˆ Allowed vs Blocked graph
  6. ๐Ÿงพ Attack logging
  7. ๐Ÿงช Manual payload testing
  8. ๐ŸŽ“ Educational dashboard

โš™๏ธ Functions & Modules

๐Ÿ”น detect_attack(payload)

  • Scans payload for SQLi/XSS
  • Uses regex rules
  • Returns verdict

๐Ÿ”น Middleware

  • Intercepts every HTTP request
  • Applies WAF logic
  • Blocks malicious traffic

๐Ÿ”น /test Endpoint

  • Manual testing of payloads
  • Simulates attacks

๐Ÿ”น /stats Endpoint

  • Returns allowed/blocked counts

๐Ÿง‘โ€๐Ÿ’ป Installation (Step-by-Step)

1๏ธโƒฃ Install Python

Download Python from:
https://www.python.org

โœ” Make sure Add Python to PATH is checked

2๏ธโƒฃ Install Dependencies

pip install fastapi uvicorn jinja2

3๏ธโƒฃ Project Setup

cd waf_simulation

โ–ถ๏ธ How to Run

uvicorn main:app --reload

Expected output:

Running on http://127.0.0.1:8000

๐ŸŒ How to Open (Chrome)

  1. Open Google Chrome
  2. Go to:
http://127.0.0.1:8000

๐Ÿ” Login Details

Username: admin
Password: admin123

๐Ÿงช How to Use

  1. Login to dashboard
  2. Enter payload in text box
  3. Click Detect
  4. View result (Allowed / Blocked)
  5. Watch graph update automatically

๐Ÿ’ฅ Example Payloads

โŒ SQL Injection

' OR 1=1 --

โŒ XSS

<script>alert(1)</script>

โœ… Normal Input

hello world

โš ๏ธ Cautions

Caution

  • This is a simulation, not a production WAF
  • Regex-based detection has limitations
  • Do not deploy on live servers

๐Ÿ“Œ Important Notes

  • Designed for learning & demo purposes
  • Easily extendable
  • Clean & modular code

๐Ÿ“ข Disclaimer

Note

This project is intended strictly for educational and research purposes. The developer is not responsible for misuse of this system.

๐Ÿš€ Future Enhancements

  1. ๐Ÿค– Machine Learning-based detection
  2. ๐Ÿ” Role-based access control
  3. ๐ŸŒ IP reputation system
  4. ๐Ÿ“„ PDF attack reports
  5. โฑ๏ธ Time-series traffic graphs
  6. ๐Ÿงช Automated attack generator

๐Ÿ Conclusion

This WAF Simulation provides a clear, realistic, and interactive understanding of how modern web security systems defend against common attacks. It bridges the gap between theory and practical cybersecurity implementation.

โญ Support & Engagement

If you find this repository useful or insightful, please consider:

  • โญ Starring the repository
  • ๐Ÿ” Sharing it within your network
  • ๐Ÿ‘ค Following my GitHub profile for future projects and updates

Your support helps drive continued innovation and open-source contributions.

โ€” Syed Shaheer Hussain

GitHub followers

Followers

Stars

ยฉ 2026 Syed Shaheer Hussain

All rights reserved.