Flask-based web server that uses AI to detect SQL injection attacks within queries
1.4K
Tested on Fedora Silverblue
This webserver is designed to detect SQL injection attempts in provided queries. It uses a trained Random Forest model to classify queries as malicious or not. The server is built with Quart, a Python ASGI web microframework, and Hypercorn, an ASGI server. Sample data is based on SQL Injection Dataset by SAJID576 on Kaggle.
This endpoint accepts a JSON object with a query field. It returns a JSON object with a is_malicious field indicating whether the provided query is considered malicious.
Request:
{
"query": "SELECT * FROM users"
}
Response:
{
"is_malicious": false
}
This endpoint accepts a CSV file for retraining the model. The CSV file should be included in the file field of the form data. A password field should also be included in the form data for authentication. The server will return a message indicating whether the file was saved successfully and the model training has started.
Form Data:
file: The CSV filepassword: The password for authenticationResponse:
{
"message": "File saved and model training started"
}
This endpoint returns the status of the server and the training process. It returns a JSON object with a status field indicating the status of the server and a training field indicating the status of the training process.
Response:
{
"message": "System is operational. Please POST to /detect with 'query' to use the service.",
"status": "ok",
"training": "idle"
}
MODEL_URL: Specify a URL to a model file to load. If not specified, the server will train a new model.VECTORIZER_URL: Specify a URL to a vectorizer file to load. If not specified, the server will create vectorizer when training a new model.ALLOW_TRAINING: Specify whether to allow training via the /upload_csv endpoint. If not specified, the default is False.SECRET_TRAIN_PASSKEY: Specify a password for the training endpoint. If not specified, the default password is 1234.docker run due to the need for volume mount and port mapping.Make sure you have Docker installed
docker-compose.yaml file from this project to your local machine..env file based on the contents in the .env.example file.:sudo docker-compose up, or add -d to run in background.Make sure you have Docker installed
git clone https://github.com/PhysCorp/SQL-Detect.git and navigate to the project directory with cd SQL-Detect..env file based on the contents in the .env.example file.:sudo docker-compose build.sudo docker-compose up, or add -d to run in background.choco install anaconda3.conda create --name SQL-Detect python=3.8.conda activate SQL-Detect.python3 -m pip install -r requirements.txt.python3 -m pip install --force-reinstall charset-normalizergit clone https://github.com/PhysCorp/SQL-Detect.git and navigate to the project directory with cd SQL-Detect.conda activate SQL-Detect..env file based on the contents in the .env.example file.python3 main.py to start the application.Create a new virtualenv with python3 -m venv .venv.
Activate the virtualenv with source .venv/bin/activate.
Install the requirements with python3 -m pip install -r requirements.txt.
conda deactivate.conda remove --name SQL-Detect --all.Copyright 2024 | This project is licensed under the MIT License. The full license can be found in the GitHub repository.
Content type
Image
Digest
sha256:280e5ec4f…
Size
140.6 MB
Last updated
over 2 years ago
docker pull mwcurtis20/sql-detect