Sploitus

Exploit for -SQLi-Defender

githubexploit ยท 2026-08-22

Exploit Code

README571 lines
## https://sploitus.com/exploit?id=894A03D8-1903-5FA5-B05E-6FA17F6F67C2
# ๐Ÿ›ก๏ธ SQLi Defender

### Real-Time SQL Injection Detection & Prevention System

SQLi Defender is a web security middleware designed to detect, analyze, monitor, and block SQL Injection attempts in real time.

The system inspects incoming HTTP requests, normalizes user-controlled input, detects SQL Injection patterns, calculates a risk score, and takes an automated security decision based on the severity of the request.

---

## ๐Ÿš€ Features

- ๐Ÿ” Real-time SQL Injection detection
- ๐Ÿ›ก๏ธ Automatic malicious request blocking
- ๐Ÿ“Š Risk scoring engine
- ๐Ÿšจ LOW / MEDIUM / HIGH / CRITICAL risk classification
- ๐Ÿ‘๏ธ Monitoring mode for suspicious requests
- ๐Ÿ“ Security event logging
- ๐Ÿ“ˆ Live security dashboard
- ๐Ÿ”„ Automatic dashboard refresh
- ๐ŸŒ Query parameter inspection
- ๐Ÿ“ฆ Request body inspection
- ๐Ÿ” Login request protection
- ๐Ÿงน Input normalization
- ๐Ÿง  Pattern-based SQL Injection detection
- โšก Fast middleware-based request inspection
- ๐Ÿ’พ SQLite-based security event storage
- ๐ŸŽจ Cybersecurity-themed dashboard

---

## ๐ŸŽฏ Problem Statement

SQL Injection is one of the most common web application security vulnerabilities.

Attackers can manipulate application input to alter SQL queries and potentially access, modify, or delete unauthorized database information.

Traditional applications may validate input only at individual endpoints.

SQLi Defender provides a centralized security layer that inspects incoming requests before they reach the application's business logic.

---

## ๐Ÿ’ก Solution

SQLi Defender works as a security middleware between the client and the application.

```text
Client Request
      โ”‚
      โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Request Middleware โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
           โ”‚
           โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Input Normalization โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
           โ”‚
           โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ SQLi Detection      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
           โ”‚
           โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Risk Engine         โ”‚
โ”‚ Score Calculation   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
           โ”‚
           โ–ผ
     Security Decision
       /          \
      /            \
     โ–ผ              โ–ผ
  MONITOR         BLOCK
     โ”‚              โ”‚
     โ–ผ              โ–ผ
 Application      HTTP 403
     โ”‚
     โ–ผ
SQLite Security Logs
     โ”‚
     โ–ผ
Live Dashboard
```

---

# ๐Ÿง  How It Works

## 1. Request Interception

Every incoming HTTP request is inspected by the security middleware.

Example:

```text
GET /products?q=laptop
```

or:

```text
POST /login
username=...
password=...
```

---

## 2. Input Extraction

The system examines user-controlled input from different locations such as:

- Query parameters
- Request body
- Login fields
- Other supported request parameters

---

## 3. Input Normalization

Before detection, input is normalized so that encoded or obfuscated input can be analyzed more effectively.

Examples of transformations include:

- URL decoding
- Case normalization
- Whitespace normalization
- Pattern normalization

---

## 4. SQL Injection Detection

The detection engine looks for suspicious SQL Injection characteristics.

Examples include:

- Boolean SQL expressions
- Multiple quote characters
- SQL comment syntax
- UNION SELECT structures
- Multiple SQL keywords
- Suspicious SQL operators
- Other malicious query patterns

---

## 5. Risk Scoring

Detected indicators contribute to a risk score.

Example:

```text
Suspicious boolean expression
        +
Multiple quote characters
        โ†“
Risk Score = 55
        โ†“
MEDIUM
        โ†“
MONITOR
```

A more severe request can produce:

```text
UNION SELECT
+
SQL comment syntax
+
Multiple SQL keywords
        โ†“
Risk Score = 100
        โ†“
CRITICAL
        โ†“
BLOCK
```

---

# ๐Ÿ›ก๏ธ Detection & Prevention

SQLi Defender uses risk-based decisions.

| Risk Level | Typical Action |
|------------|----------------|
| LOW | ALLOW |
| MEDIUM | MONITOR |
| HIGH | BLOCK |
| CRITICAL | BLOCK |

This allows the system to avoid blindly blocking every request containing SQL-related words.

---

# ๐Ÿ“Š Live Dashboard

The project includes a real-time security dashboard that displays:

- Detected Requests
- Blocked Requests
- Monitored Requests
- High-Risk Events
- Critical Events
- Recent Security Detections
- Risk Score
- Request Method
- Request Path
- Parameter
- Action
- HTTP Response Status
- Detection Reason

The dashboard automatically refreshes to display newly recorded security events.

---

# ๐Ÿงช Example Detection

### Suspicious request

```text
GET /products?q=' OR '1'='1
```

The detector can identify indicators such as:

```text
Boolean SQL expression
Multiple quote characters
```

Example decision:

```text
Risk: MEDIUM
Score: 55
Action: MONITOR
HTTP Status: 200
```

---

### High-risk request

```text
GET /products?q=UNION SELECT 1--
```

Example decision:

```text
Risk: CRITICAL
Score: 100
Action: BLOCK
HTTP Status: 403
```

---

# ๐Ÿ“ Security Logging

Every detected security event can be stored with information such as:

```text
Timestamp
Client IP
HTTP Method
Request Path
Parameter
Location
Risk Level
Risk Score
Action
Detection Reasons
Response Status
```

This allows security events to be reviewed later.

---

# ๐Ÿงฐ Technology Stack

### Backend

- Python
- FastAPI
- Uvicorn

### Security

- Custom SQL Injection Detection Engine
- Request Middleware
- Risk Scoring Engine
- Input Normalization

### Database

- SQLite
- SQLAlchemy

### Frontend

- HTML
- CSS
- JavaScript

### Development

- Python Virtual Environment
- Git
- GitHub

---

# ๐Ÿ“ Project Structure

```text
SQLi-Prevention-System/
โ”‚
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ main.py
โ”‚   โ”œโ”€โ”€ database.py
โ”‚   โ”œโ”€โ”€ models.py
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ security/
โ”‚   โ”‚   โ”œโ”€โ”€ detector.py
โ”‚   โ”‚   โ”œโ”€โ”€ middleware.py
โ”‚   โ”‚   โ”œโ”€โ”€ normalizer.py
โ”‚   โ”‚   โ””โ”€โ”€ risk_engine.py
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ templates/
โ”‚       โ”œโ”€โ”€ index.html
โ”‚       โ”œโ”€โ”€ login.html
โ”‚       โ”œโ”€โ”€ products.html
โ”‚       โ””โ”€โ”€ register.html
โ”‚
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ .gitignore
โ””โ”€โ”€ ...
```

---

# โš™๏ธ Installation

## 1. Clone the repository

```bash
git clone https://github.com/YOUR_USERNAME/SQLi-Defender.git
```

```bash
cd SQLi-Defender
```

---

## 2. Create a virtual environment

### Windows

```bash
python -m venv venv
```

Activate:

```bash
venv\Scripts\activate
```

---

## 3. Install dependencies

```bash
pip install -r requirements.txt
```

---

## 4. Start the application

```bash
uvicorn app.main:app --reload
```

The application should be available at:

```text
http://127.0.0.1:8000
```

---

# ๐Ÿ“Š Dashboard

Open:

```text
http://127.0.0.1:8000/dashboard
```

The dashboard provides real-time visibility into detected and blocked requests.

---

# ๐Ÿ”ฌ Testing

The project can be tested using controlled requests against the local application.

### Health Check

```text
GET /health
```

### Normal Request

```text
GET /products?q=laptop
```

### Suspicious Request

```text
GET /products?q=' OR '1'='1
```

### High-Risk SQL Injection Test

```text
GET /products?q=UNION SELECT 1--
```

Expected high-risk behavior:

```text
Risk: CRITICAL
Score: 100
Action: BLOCK
HTTP Status: 403
```

---

# ๐Ÿ“ˆ Security Monitoring

The dashboard provides visibility into:

```text
Detected Requests
       โ†“
Risk Classification
       โ†“
Monitor / Block
       โ†“
Security Event Logging
       โ†“
Live Dashboard
```

---

# ๐ŸŽ“ Project Objectives

The main objectives of SQLi Defender are:

1. Detect SQL Injection attempts in real time.
2. Identify suspicious request parameters.
3. Calculate a risk score for detected requests.
4. Automatically block high-risk requests.
5. Monitor medium-risk requests.
6. Record security events.
7. Provide a security monitoring dashboard.
8. Demonstrate practical web application security concepts.

---

# ๐Ÿ” Security Note

This project is intended for educational, research, and authorized security testing purposes.

Testing should only be performed against applications and systems for which you have permission.

SQLi Defender is a defensive security project and should be deployed with additional security controls in production environments.

---

# ๐Ÿšง Limitations

SQL Injection detection based on patterns and heuristics cannot guarantee detection of every possible SQL Injection technique.

Production deployments should additionally use:

- Parameterized queries
- Prepared statements
- ORM protections
- Strict input validation
- Least-privilege database accounts
- Secure authentication
- Rate limiting
- Centralized logging
- Web Application Firewall controls
- Security testing

SQLi Defender is designed as an additional defensive layer rather than a replacement for secure application development practices.

---

# ๐Ÿ”ฎ Future Improvements

Possible future enhancements include:

- Machine Learning-based SQLi detection
- Advanced anomaly detection
- IP reputation analysis
- Rate-limit based protection
- Attack frequency analysis
- Geo/IP intelligence
- Email/Telegram security alerts
- Exportable security reports
- Admin authentication
- PostgreSQL/MySQL support
- Docker deployment
- REST API security analytics
- Advanced WAF capabilities
- Automated security test suite

---

# ๐Ÿ‘จโ€๐Ÿ’ป Author

**Ayush Shukla**

Cyber Security Student

Interested in:

- Web Application Security
- Penetration Testing
- VAPT
- Security Automation
- Threat Detection
- Defensive Security

---

# โญ Project

If you find this project useful for learning or security research, consider giving the repository a star.

---

## โš ๏ธ Disclaimer

This project is developed for educational and authorized security testing purposes only.

The author is not responsible for unauthorized use or misuse of this software.