Skip to content

About

A machine learning–powered SQL Injection Detection system using TF-IDF and Logistic Regression. Includes a modern Flask web interface, real-time prediction, interactive threshold tuning, and a custom SQL injection dataset.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

18 Commits

Folders and files

Repository files navigation

SQL Injection Detection – ML-Based Web Application

Overview

A Flask-based machine-learning web application that classifies SQL payloads as SQL Injection or Benign using a TF-IDF vectorizer and Logistic Regression model. The app provides a stylish Bootstrap UI, real-time probability scoring, and an adjustable threshold slider for fine-grained detection.

Technologies Used

  • Python 3
  • Flask
  • scikit-learn
  • pandas
  • Bootstrap 5
  • HTML + CSS

Directory Structure

SQL-Injection-ML-Detector/
├── app.py
├── SQL_Dataset.csv
├── Payloads.txt
├── requirements.txt
└── README.md

Requirements

  • Python 3.9+
  • pip installed
  • Any IDE (VS Code recommended)
  • Dataset file: SQL_Dataset.csv
  • Columns required:
    • Query (payload)
    • Label (0 or 1)

Dependencies

  • flask
  • pandas
  • scikit-learn

How It Works

Model Workflow

  • Loads dataset
  • Vectorizes text using TF-IDF (1–2 n-grams)
  • Trains Logistic Regression classifier
  • Predicts SQL Injection probability for user inputs

Application Flow

  • User enters a payload in the UI
  • App vectorizes input → ML model
  • Model returns:
    • SQL Injection (if probability ≥ threshold)
    • Benign (otherwise)
  • Threshold controlled by slider(0.50–0.99)

UI Features

  • Dark theme
  • Modern card layout
  • Resizable text area
  • Gradient badges for SQLi/Benign
  • Smooth user experience

Setup Instructions

  1. Clone the repository:
git clone https://github.com/rahul07890-dev/SQL-Injection-Detector-ML.git
  1. Install the dependencies:
pip install -r requirements.txt
  1. Ensure dataset is in the same directory as app.py
  2. Start the Flask server:
python app.py
  1. Open the application:
http://localhost:5000

Screenshots

  • Home Page
image
  • Prediction Result Page

    • Benign payload

      image
    • Malicious Payload

      image

Video Demonstration

  • Video Demo
SQLi.mp4

Features

  • Machine Learning–powered SQL Injection detection
  • Real-time probability scoring
  • Adjustable threshold slider
  • Clean modern Bootstrap UI
  • Fully offline and local
  • Easy to customize and extend

Improvements

  • Save trained model using joblib
  • Add REST API endpoint (/predict)
  • Add Docker support
  • Deploy on Render / Railway
  • Add logs for prediction activity
  • Expand dataset with more SQL payloads

Contribution

  • Pull requests are welcome.
  • For major changes, open an issue first.

Acknowledgments

  • scikit-learn documentation
  • Bootstrap 5
  • Open-source SQL injection datasets

About

A machine learning–powered SQL Injection Detection system using TF-IDF and Logistic Regression. Includes a modern Flask web interface, real-time prediction, interactive threshold tuning, and a custom SQL injection dataset.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages