CoolFace
Modelpublic

kd7979148/XSS_Payload_Detector

sourceHugging Faceupdated 4mo agoView on Hugging Face
0likes5downloads
Model Card

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

LabelDescription
NORMALBenign input
XSSPotential XSS payload

Requirements

bash
pip install torch
pip install transformers
pip install flask

Features

This project supports two different usage modes.

1. CLI Mode

Run:

bash
python inference_bert_url.py

Enter a string or URL directly from the command line.

The model will classify the input as:

  • —NORMAL
  • —XSS

and display a confidence score.

Example:

text
Input:
<script>alert(1)</script>

Result:
XSS
Confidence:
0.9998

2. Log Monitoring Mode

Run the monitoring service:

bash
python monitor.py

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:

bash
python test_server.py

[image] Then open:

text
http://127.0.0.1:8080/?q=abcde

Example XSS payload:

text
http://127.0.0.1:8080/?q=<img src='x' onerror='alert("xss")'>

[image]

[image] 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:

bash
pip install huggingface_hub
python
from huggingface_hub import snapshot_download

snapshot_download(
    repo_id="kd7979148/XSS_Payload_Detector"
)

This will download all files contained in the repository.

Framework

  • —PyTorch
  • —Transformers