This project implements a machine learning model to detect SQL injection attempts using TensorFlow and Keras.
InjectionSQL.py
: Main script for training the model and making predictionsgenerate_test_queries.py
: Script to generate test queries for evaluationsqli.csv
: Dataset containing SQL queries labeled as injection or non-injectiontest_queries.sql
: Generated test queries for evaluation
-
Install required dependencies:
pip install tensorflow pandas scikit-learn matplotlib
-
Ensure you have the
sqli.csv
dataset in the project directory.
-
Train the model and evaluate on test queries:
python InjectionSQL.py
-
Generate new test queries:
python generate_test_queries.py
The model uses a sequential architecture with:
- Embedding layer
- Two LSTM layers with dropout
- Dense output layer with sigmoid activation
The model's performance can be evaluated using the accuracy metric and visualized through the generated training_results.png
plot.
The test_from_file
function in InjectionSQL.py
allows testing the model on custom SQL queries. You can modify the test_queries.sql
file or create your own file with SQL queries for testing.
This project is for educational purposes and should not be used as the sole method for preventing SQL injection in production environments. Always use parameterized queries and follow secure coding practices.