
détection des attaques sql/xss sur API web avec IA
This project aims to detect SQL and XSS injections in API requests/params using machine learning.
This project aims to detect SQL and XSS injections in API requests and parameters using Machine Learning techniques.
The goal is to create a simple pipeline enabling:
benign, sql_injection or xss,Prepare the dataset
The file generated_payloads.csv in the data/ folder contains examples of labeled API requests (sql_injection, xss, benign) from external sources such as Kaggle or generated locally.
Dataset cleaning and splitting
python scripts/clean_and_split.py
The script:
python scripts/train_model.py
The model uses an ML pipeline:
TF-IDF Vectorizer (TfidfVectorizer): transforms text requests into numerical vectors, capturing the importance of words or suspicious symbols.
Logistic Regression (LogisticRegression): supervised classifier that learns to associate TF-IDF vectors with the classes sql_injection, xss or benign.
After training, the model is saved in the models folder; it can then be used to predict the class of a new request.
pytest -v -s tests/test_pipeline.py
The test verifies that:
pip3 install -r requirements.txt
Libraries