Downloads · 30 days
18
21% of all-time downloads
ebrasha/abdal-xss-ai-engine
abdal-xss-ai-engine is a text classification model from ebrasha. Use it when you need a label for a piece of text. It is set up for keras.
Downloads · 30 days
18
21% of all-time downloads
All-time downloads
85
Public
Repo size
82.8 MB
Likes
0
Public
Click a slice to open those files.
.keras33.1 MB · 39%
From the Hugging Face model README
The Abdal XSS AI Engine was developed to provide a free and advanced solution for combating XSS attacks, particularly in Iran, where there is a lack of local cybersecurity models. This AI-based model addresses the crucial need for enhanced cybersecurity and aims to protect users by preventing XSS attacks more effectively.
You can use the model as an API for detecting XSS attacks by using the following code:
from flask import Flask, request, jsonify
import tensorflow as tf
import pickle
import numpy as np
app = Flask(__name__)
# Load the model and vectorizer
model = tf.keras.models.load_model('Abdal_XSS_AI_Engine.h5')
with open('vectorizer.pkl', 'rb') as f:
vectorizer = pickle.load(f)
@app.route('/predict', methods=['POST'])
def predict():
data = request.json
sentences = data['sentences']
# Preprocess the input data using the vectorizer
X_new = vectorizer.transform(sentences).toarray()
# Make predictions
predictions = (model.predict(X_new) > 0.5).astype(int)
# Prepare and return the response
response = {
'predictions': ['XSS Detected' if pred == 1 else 'No XSS Detected' for pred in predictions.flatten()]
}
return jsonify(response)
if __name__ == '__main__':
app.run(debug=True)
In addition to the API, you can also use the model to read data from a text file and detect attacks. The following code is an example of this use case:
import os
import tensorflow as tf
import pickle
# Disable oneDNN custom operations
os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'
# Set TensorFlow logging level to 'ERROR' to suppress the info and warning messages
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
# Check if model and vectorizer files exist
model_path = 'Abdal_XSS_AI_Engine.keras'
vectorizer_path = 'vectorizer.pkl'
if not os.path.exists(model_path):
raise FileNotFoundError(f"Model file not found: {model_path}")
if not os.path.exists(vectorizer_path):
raise FileNotFoundError(f"Vectorizer file not found: {vectorizer_path}")
# Load the model from the Keras format
model_name = "Abdal XSS AI Engine"
model = tf.keras.models.load_model(model_path)
# Load the vectorizer
with open(vectorizer_path, 'rb') as f:
vectorizer = pickle.load(f)
# Read new data (sentences) from a file (e.g., 'attack-xss-payload.txt')
input_file = 'attack-xss-payload.txt'
if not os.path.exists(input_file):
raise FileNotFoundError(f"Input file not found: {input_file}")
with open(input_file, 'r', encoding='utf-8') as file:
new_sentences = [line.strip() for line in file if line.strip()] # Reading each line from file
# Check if any sentence exists for prediction
if not new_sentences:
raise ValueError("No data available for prediction.")
# Preprocess the new data using the loaded TF-IDF vectorizer
X_new = vectorizer.transform(new_sentences).toarray()
# Predict using the loaded model
predictions = (model.predict(X_new) > 0.5).astype(int)
# Print predictions
for i, sentence in enumerate(new_sentences):
print(f"Sentence: {sentence}")
print(f"Prediction: {'XSS Detected' if predictions[i] == 1 else 'No XSS Detected'}\n")
To use the trained model in your TensorFlow project, simply run the following Python code:
import tensorflow as tf
# Load the saved model
model = tf.keras.models.load_model('Abdal_XSS_AI_Engine')
print("✅ Model loaded successfully!")
https://ebrasha.com/abdal-donation
Handcrafted with Passion by Ebrahim Shafiei (EbraSha)
E-Mail = [email protected]
Telegram: https://t.me/ProfShafiei
If you are facing a configuration issue or something is not working as you expected to be, please use the [email protected] . Issues on GitLab or Github are also welcomed.