XSS Payload Detector
DistilBERT-based machine learning model for detecting XSS payloads.
This project can be used either as a standalone CLI classifier or as a log-monitoring system that automatically analyzes web server requests and detects potential XSS attacks.
Labels
Label Description NORMAL Benign input XSS Potential XSS payload
Requirements
1 pip install torch
2 pip install transformers
3 pip install flask
Features
This project supports two different usage modes.
1. CLI Mode
Run:
python inference_bert_url.py
Enter a string or URL directly from the command line.
The model will classify the input as:
and display a confidence score.
Example:
1 Input:
2 <script>alert(1)</script>
3
4 Result:
5 XSS
6 Confidence:
7 0.9998
2. Log Monitoring Mode
Run the monitoring service:
The monitor automatically reads web server access logs and analyzes incoming requests.
Detected XSS payloads are logged for further inspection.
This allows the model to be integrated into a web application environment without manually entering payloads.
Test Environment
Run the example Flask server:
Demo
Then open:
http://127.0.0.1:8080/?q=abcde
Example XSS payload:
http://127.0.0.1:8080/?q=<img src='x' onerror='alert("xss")'>
Demo
Demo
The request will be reflected by the test page and analyzed by the monitoring service.
Components
inference_bert_url.py
Standalone CLI tool for testing XSS detection.
moniter.py
Log monitoring service that reads web server logs and analyzes incoming requests.
test_server.py
Flask-based demonstration server for testing reflected XSS scenarios.
templates/
HTML templates used by the Flask demonstration server.
static/
Static assets (images, CSS, etc.) used by the Flask demonstration server.
Model Files
config.json
model.safetensors
tokenizer.json
tokenizer_config.json
vocab.txt
Download Repository
To download the entire repository, including the trained model, example server, monitoring utility, templates, and static files:
pip install huggingface_hub
1 from huggingface_hub import snapshot_download
2
3 snapshot_download (
4 repo_id = "kd7979148/XSS_Payload_Detector"
5 )
This will download all files contained in the repository.
Framework