Upload folder using huggingface_hub
Browse files- .gitattributes +2 -0
- Abdal_XSS_AI_Engine.h5 +3 -0
- Abdal_XSS_AI_Engine.keras +3 -0
- Abdal_XSS_AI_Engine.onnx +3 -0
- Abdal_XSS_AI_Engine_TensorFlow/fingerprint.pb +3 -0
- Abdal_XSS_AI_Engine_TensorFlow/saved_model.pb +3 -0
- Abdal_XSS_AI_Engine_TensorFlow/variables/variables.data-00000-of-00001 +3 -0
- Abdal_XSS_AI_Engine_TensorFlow/variables/variables.index +0 -0
- LICENSE +21 -0
- README.fa.md +168 -0
- README.md +168 -3
- Use-Model-With-File.py +50 -0
- Use-Model-api.py +33 -0
- csv-dataset/XSS_dataset.csv +0 -0
- requirements.txt +6 -0
- scr.jpg +0 -0
- vectorizer.pkl +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
Abdal_XSS_AI_Engine.keras filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
Abdal_XSS_AI_Engine_TensorFlow/variables/variables.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
|
Abdal_XSS_AI_Engine.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:78893d9542278d1fff7e3ff98a6b8b8085f1666b651bc33b5dd627dd96f0d8b0
|
| 3 |
+
size 16394184
|
Abdal_XSS_AI_Engine.keras
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:52a6c47d9112a1e3dfbd1b01572d9559c25c8feb53acaa4339839163bb412a54
|
| 3 |
+
size 33065249
|
Abdal_XSS_AI_Engine.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e4b21d69f18aedbf27dde4fcde95ad356fab2f7bfac2dfafca51bd465dbb6261
|
| 3 |
+
size 11014434
|
Abdal_XSS_AI_Engine_TensorFlow/fingerprint.pb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4631581042493220a7c199c1dbbe20e30a93792d280c54c586290bcbdc19eb44
|
| 3 |
+
size 56
|
Abdal_XSS_AI_Engine_TensorFlow/saved_model.pb
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:34e1b7b6b64fd17d0a896a5c9acf1f3db3c290cc6f63876eea2642f30dd422e5
|
| 3 |
+
size 62469
|
Abdal_XSS_AI_Engine_TensorFlow/variables/variables.data-00000-of-00001
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c1483b41b7fc2e06cd9156b6457c52b5c75b7fa5e6158f42c7687a74d159fc75
|
| 3 |
+
size 22024431
|
Abdal_XSS_AI_Engine_TensorFlow/variables/variables.index
ADDED
|
Binary file (1.22 kB). View file
|
|
|
LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2024 Ebrahim Shafiei
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
README.fa.md
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Abdal XSS AI Engine
|
| 2 |
+
|
| 3 |
+
## 🎤 ترجمه اطلاعات نرم افزار
|
| 4 |
+
- [English](README.md)
|
| 5 |
+
- [فارسی](README.fa.md)
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
<p align="center"><img src="scr.jpg?raw=true"></p>
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
## 💎 هدف اصلی
|
| 12 |
+
مدل هوش مصنوعی Abdal XSS AI Engine با هدف ارائه یک راهکار پیشرفته و رایگان برای مقابله با حملات XSS در ایران توسعه داده شده است. با توجه به نبود ابزارهای مناسب سایبری داخلی، این مدل به عنوان یک نیاز ضروری برای افزایش امنیت در فضای سایبری ایران طراحی شده تا از حملات XSS جلوگیری کند و کاربران ایرانی بتوانند از حفاظت بهتری برخوردار شوند.
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
## 🛠️ پیش نیاز برای برنامه نویسان
|
| 16 |
+
- **Python 3.7 یا بالاتر**
|
| 17 |
+
- **Flask** (برای ساخت RESTful API)
|
| 18 |
+
- **TensorFlow** (مدلهای یادگیری عمیق)
|
| 19 |
+
- **Scikit-learn** (برای پیشپردازش دادههای متنی و بردار سازی TF-IDF)
|
| 20 |
+
- **Pandas** (برای مدیریت دادهها در مقیاس بزرگ)
|
| 21 |
+
- **درک عمیق از امنیت وب و حملات XSS**
|
| 22 |
+
- **Git** (کنترل نسخه و مدیریت مخازن)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
### 🔥 پیشنیازها
|
| 26 |
+
|
| 27 |
+
- **Python 3.7 یا بالاتر**
|
| 28 |
+
- **Flask**
|
| 29 |
+
- **TensorFlow**
|
| 30 |
+
- **Scikit-learn**
|
| 31 |
+
- **Pandas**
|
| 32 |
+
- **Pickle**
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
## ✨ قابلیت ها
|
| 36 |
+
|
| 37 |
+
- قابلیت پردازش صدها هزار الگوی XSS و شناسایی حملات جدید.
|
| 38 |
+
- استفاده از مدل یادگیری عمیق با چند لایه Dense و Dropout.
|
| 39 |
+
- آموزش مدل با استفاده از مجموعه داده ترکیبی از فایلهای CSV.
|
| 40 |
+
- استفاده از تکنیک TF-IDF برای استخراج ویژگیهای متنی از حملات XSS.
|
| 41 |
+
- قابلیت افزایش دقت مدل با دادههای جدید و بهروز رسانی مداوم.
|
| 42 |
+
- پشتیبانی از بهینهسازی مدل با استفاده از روش Adam و معیار دقت (accuracy).
|
| 43 |
+
- ذخیره مدل نهایی و وکتورایزر برای استفاده در آینده و استقرار در محیطهای مختلف.
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
## 📝️ چگونه کار می کند ؟
|
| 47 |
+
|
| 48 |
+
با استفاده از کد زیر میتوانید از مدل به صورت یک API برای شناسایی حملات XSS استفاده کنید
|
| 49 |
+
|
| 50 |
+
```python
|
| 51 |
+
from flask import Flask, request, jsonify
|
| 52 |
+
import tensorflow as tf
|
| 53 |
+
import pickle
|
| 54 |
+
import numpy as np
|
| 55 |
+
|
| 56 |
+
app = Flask(__name__)
|
| 57 |
+
|
| 58 |
+
# Load the model and vectorizer
|
| 59 |
+
model = tf.keras.models.load_model('Abdal_XSS_AI_Engine.h5')
|
| 60 |
+
with open('vectorizer.pkl', 'rb') as f:
|
| 61 |
+
vectorizer = pickle.load(f)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
@app.route('/predict', methods=['POST'])
|
| 65 |
+
def predict():
|
| 66 |
+
data = request.json
|
| 67 |
+
sentences = data['sentences']
|
| 68 |
+
|
| 69 |
+
# Preprocess the input data using the vectorizer
|
| 70 |
+
X_new = vectorizer.transform(sentences).toarray()
|
| 71 |
+
|
| 72 |
+
# Make predictions
|
| 73 |
+
predictions = (model.predict(X_new) > 0.5).astype(int)
|
| 74 |
+
|
| 75 |
+
# Prepare and return the response
|
| 76 |
+
response = {
|
| 77 |
+
'predictions': ['XSS Detected' if pred == 1 else 'No XSS Detected' for pred in predictions.flatten()]
|
| 78 |
+
}
|
| 79 |
+
return jsonify(response)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
if __name__ == '__main__':
|
| 83 |
+
app.run(debug=True)
|
| 84 |
+
|
| 85 |
+
```
|
| 86 |
+
علاوه بر API، میتوانید از مدل برای خواندن دادهها از یک فایل متنی و شناسایی حملات استفاده کنید. کد زیر نمونهای از این استفاده است:
|
| 87 |
+
|
| 88 |
+
```python
|
| 89 |
+
import os
|
| 90 |
+
import tensorflow as tf
|
| 91 |
+
import pickle
|
| 92 |
+
|
| 93 |
+
# Disable oneDNN custom operations
|
| 94 |
+
os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'
|
| 95 |
+
# Set TensorFlow logging level to 'ERROR' to suppress the info and warning messages
|
| 96 |
+
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
|
| 97 |
+
|
| 98 |
+
# Check if model and vectorizer files exist
|
| 99 |
+
model_path = 'Abdal_XSS_AI_Engine.keras'
|
| 100 |
+
vectorizer_path = 'vectorizer.pkl'
|
| 101 |
+
|
| 102 |
+
if not os.path.exists(model_path):
|
| 103 |
+
raise FileNotFoundError(f"Model file not found: {model_path}")
|
| 104 |
+
if not os.path.exists(vectorizer_path):
|
| 105 |
+
raise FileNotFoundError(f"Vectorizer file not found: {vectorizer_path}")
|
| 106 |
+
|
| 107 |
+
# Load the model from the Keras format
|
| 108 |
+
model_name = "Abdal XSS AI Engine"
|
| 109 |
+
model = tf.keras.models.load_model(model_path)
|
| 110 |
+
|
| 111 |
+
# Load the vectorizer
|
| 112 |
+
with open(vectorizer_path, 'rb') as f:
|
| 113 |
+
vectorizer = pickle.load(f)
|
| 114 |
+
|
| 115 |
+
# Read new data (sentences) from a file (e.g., 'attack-xss-payload.txt')
|
| 116 |
+
input_file = 'attack-xss-payload.txt'
|
| 117 |
+
if not os.path.exists(input_file):
|
| 118 |
+
raise FileNotFoundError(f"Input file not found: {input_file}")
|
| 119 |
+
|
| 120 |
+
with open(input_file, 'r', encoding='utf-8') as file:
|
| 121 |
+
new_sentences = [line.strip() for line in file if line.strip()] # Reading each line from file
|
| 122 |
+
|
| 123 |
+
# Check if any sentence exists for prediction
|
| 124 |
+
if not new_sentences:
|
| 125 |
+
raise ValueError("No data available for prediction.")
|
| 126 |
+
|
| 127 |
+
# Preprocess the new data using the loaded TF-IDF vectorizer
|
| 128 |
+
X_new = vectorizer.transform(new_sentences).toarray()
|
| 129 |
+
|
| 130 |
+
# Predict using the loaded model
|
| 131 |
+
predictions = (model.predict(X_new) > 0.5).astype(int)
|
| 132 |
+
|
| 133 |
+
# Print predictions
|
| 134 |
+
for i, sentence in enumerate(new_sentences):
|
| 135 |
+
print(f"Sentence: {sentence}")
|
| 136 |
+
print(f"Prediction: {'XSS Detected' if predictions[i] == 1 else 'No XSS Detected'}\n")
|
| 137 |
+
|
| 138 |
+
```
|
| 139 |
+
### نحوهی بارگذاری مدل برای TensorFlow
|
| 140 |
+
|
| 141 |
+
برای استفاده از این مدل در پروژهی TensorFlow، کافی است کد زیر را اجرا کنید:
|
| 142 |
+
|
| 143 |
+
```python
|
| 144 |
+
import tensorflow as tf
|
| 145 |
+
|
| 146 |
+
# Load the saved model
|
| 147 |
+
model = tf.keras.models.load_model('Abdal_XSS_AI_Engine')
|
| 148 |
+
|
| 149 |
+
print("✅ Model loaded successfully!")
|
| 150 |
+
```
|
| 151 |
+
|
| 152 |
+
## ❤️ کمک به پروژه
|
| 153 |
+
|
| 154 |
+
https://alphajet.ir/abdal-donation
|
| 155 |
+
|
| 156 |
+
## 🤵 برنامه نویس
|
| 157 |
+
دست ساز با عشق توسط ابراهیم شفیعی (ابراشا)
|
| 158 |
+
|
| 159 |
+
E-Mail = [email protected]
|
| 160 |
+
|
| 161 |
+
Telegram: https://t.me/ProfShafiei
|
| 162 |
+
|
| 163 |
+
## ☠️ گزارش خطا
|
| 164 |
+
|
| 165 |
+
اگر با مشکلی در پیکربندی مواجه هستید یا چیزی آنطور که انتظار دارید کار نمیکند، لطفا از [email protected] استفاده کنید.طرح مشکلات بر روی GitLab یا Github نیز پذیرفته میشوند.
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
|
README.md
CHANGED
|
@@ -1,3 +1,168 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Abdal XSS AI Engine
|
| 2 |
+
|
| 3 |
+
## 🎤 README Translation
|
| 4 |
+
- [English](README.md)
|
| 5 |
+
- [فارسی](README.fa.md)
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
<p align="center"><img src="scr.jpg?raw=true"></p>
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
## 💎 General purpose
|
| 13 |
+
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.
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
## 🛠️ Development Environment Setup
|
| 17 |
+
- **Python 3.7 or higher**
|
| 18 |
+
- **Flask** (for building RESTful APIs)
|
| 19 |
+
- **TensorFlow** (Deep Learning models)
|
| 20 |
+
- **Scikit-learn** (for text preprocessing and TF-IDF vectorization)
|
| 21 |
+
- **Pandas** (for large-scale data management)
|
| 22 |
+
- **Deep understanding of web security and XSS attacks**
|
| 23 |
+
- **Git** (version control and repository management)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
### 🔥 Requirements
|
| 28 |
+
|
| 29 |
+
- **Python 3.7 or higher**
|
| 30 |
+
- **Flask**
|
| 31 |
+
- **TensorFlow**
|
| 32 |
+
- **Scikit-learn**
|
| 33 |
+
- **Pandas**
|
| 34 |
+
- **Pickle**
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
## ✨ Features
|
| 38 |
+
|
| 39 |
+
- Ability to process and detect hundreds of thousands of XSS patterns, including new emerging threats.
|
| 40 |
+
- Utilizes a deep learning model with multiple Dense and Dropout layers.
|
| 41 |
+
- Trained using a combined dataset from multiple CSV files.
|
| 42 |
+
- Employs TF-IDF technique for text feature extraction from XSS attacks.
|
| 43 |
+
- Capability to improve model accuracy with new data and continuous updates.
|
| 44 |
+
- Supports model optimization using the Adam optimizer and accuracy metrics.
|
| 45 |
+
- Saves the final model and vectorizer for future use and deployment in various environments.
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
## 📝️ How it Works?
|
| 49 |
+
|
| 50 |
+
You can use the model as an API for detecting XSS attacks by using the following code:
|
| 51 |
+
```python
|
| 52 |
+
from flask import Flask, request, jsonify
|
| 53 |
+
import tensorflow as tf
|
| 54 |
+
import pickle
|
| 55 |
+
import numpy as np
|
| 56 |
+
|
| 57 |
+
app = Flask(__name__)
|
| 58 |
+
|
| 59 |
+
# Load the model and vectorizer
|
| 60 |
+
model = tf.keras.models.load_model('Abdal_XSS_AI_Engine.h5')
|
| 61 |
+
with open('vectorizer.pkl', 'rb') as f:
|
| 62 |
+
vectorizer = pickle.load(f)
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
@app.route('/predict', methods=['POST'])
|
| 66 |
+
def predict():
|
| 67 |
+
data = request.json
|
| 68 |
+
sentences = data['sentences']
|
| 69 |
+
|
| 70 |
+
# Preprocess the input data using the vectorizer
|
| 71 |
+
X_new = vectorizer.transform(sentences).toarray()
|
| 72 |
+
|
| 73 |
+
# Make predictions
|
| 74 |
+
predictions = (model.predict(X_new) > 0.5).astype(int)
|
| 75 |
+
|
| 76 |
+
# Prepare and return the response
|
| 77 |
+
response = {
|
| 78 |
+
'predictions': ['XSS Detected' if pred == 1 else 'No XSS Detected' for pred in predictions.flatten()]
|
| 79 |
+
}
|
| 80 |
+
return jsonify(response)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
if __name__ == '__main__':
|
| 84 |
+
app.run(debug=True)
|
| 85 |
+
|
| 86 |
+
```
|
| 87 |
+
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:
|
| 88 |
+
|
| 89 |
+
```python
|
| 90 |
+
import os
|
| 91 |
+
import tensorflow as tf
|
| 92 |
+
import pickle
|
| 93 |
+
|
| 94 |
+
# Disable oneDNN custom operations
|
| 95 |
+
os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'
|
| 96 |
+
# Set TensorFlow logging level to 'ERROR' to suppress the info and warning messages
|
| 97 |
+
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
|
| 98 |
+
|
| 99 |
+
# Check if model and vectorizer files exist
|
| 100 |
+
model_path = 'Abdal_XSS_AI_Engine.keras'
|
| 101 |
+
vectorizer_path = 'vectorizer.pkl'
|
| 102 |
+
|
| 103 |
+
if not os.path.exists(model_path):
|
| 104 |
+
raise FileNotFoundError(f"Model file not found: {model_path}")
|
| 105 |
+
if not os.path.exists(vectorizer_path):
|
| 106 |
+
raise FileNotFoundError(f"Vectorizer file not found: {vectorizer_path}")
|
| 107 |
+
|
| 108 |
+
# Load the model from the Keras format
|
| 109 |
+
model_name = "Abdal XSS AI Engine"
|
| 110 |
+
model = tf.keras.models.load_model(model_path)
|
| 111 |
+
|
| 112 |
+
# Load the vectorizer
|
| 113 |
+
with open(vectorizer_path, 'rb') as f:
|
| 114 |
+
vectorizer = pickle.load(f)
|
| 115 |
+
|
| 116 |
+
# Read new data (sentences) from a file (e.g., 'attack-xss-payload.txt')
|
| 117 |
+
input_file = 'attack-xss-payload.txt'
|
| 118 |
+
if not os.path.exists(input_file):
|
| 119 |
+
raise FileNotFoundError(f"Input file not found: {input_file}")
|
| 120 |
+
|
| 121 |
+
with open(input_file, 'r', encoding='utf-8') as file:
|
| 122 |
+
new_sentences = [line.strip() for line in file if line.strip()] # Reading each line from file
|
| 123 |
+
|
| 124 |
+
# Check if any sentence exists for prediction
|
| 125 |
+
if not new_sentences:
|
| 126 |
+
raise ValueError("No data available for prediction.")
|
| 127 |
+
|
| 128 |
+
# Preprocess the new data using the loaded TF-IDF vectorizer
|
| 129 |
+
X_new = vectorizer.transform(new_sentences).toarray()
|
| 130 |
+
|
| 131 |
+
# Predict using the loaded model
|
| 132 |
+
predictions = (model.predict(X_new) > 0.5).astype(int)
|
| 133 |
+
|
| 134 |
+
# Print predictions
|
| 135 |
+
for i, sentence in enumerate(new_sentences):
|
| 136 |
+
print(f"Sentence: {sentence}")
|
| 137 |
+
print(f"Prediction: {'XSS Detected' if predictions[i] == 1 else 'No XSS Detected'}\n")
|
| 138 |
+
|
| 139 |
+
```
|
| 140 |
+
### Abdal XSS AI Engine - TensorFlow Model
|
| 141 |
+
|
| 142 |
+
To use the trained model in your TensorFlow project, simply run the following Python code:
|
| 143 |
+
|
| 144 |
+
```python
|
| 145 |
+
import tensorflow as tf
|
| 146 |
+
|
| 147 |
+
# Load the saved model
|
| 148 |
+
model = tf.keras.models.load_model('Abdal_XSS_AI_Engine')
|
| 149 |
+
|
| 150 |
+
print("✅ Model loaded successfully!")
|
| 151 |
+
```
|
| 152 |
+
|
| 153 |
+
## ❤️ Donation
|
| 154 |
+
|
| 155 |
+
https://ebrasha.com/abdal-donation
|
| 156 |
+
|
| 157 |
+
## 🤵 Programmer
|
| 158 |
+
Handcrafted with Passion by Ebrahim Shafiei (EbraSha)
|
| 159 |
+
|
| 160 |
+
E-Mail = [email protected]
|
| 161 |
+
|
| 162 |
+
Telegram: https://t.me/ProfShafiei
|
| 163 |
+
|
| 164 |
+
## ☠️ Reporting Issues
|
| 165 |
+
|
| 166 |
+
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.
|
| 167 |
+
|
| 168 |
+
|
Use-Model-With-File.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Author: Ebrahim Shafiei (EbraSha)
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
import tensorflow as tf
|
| 5 |
+
import pickle
|
| 6 |
+
|
| 7 |
+
# Disable oneDNN custom operations
|
| 8 |
+
os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'
|
| 9 |
+
# Set TensorFlow logging level to 'ERROR' to suppress the info and warning messages
|
| 10 |
+
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
|
| 11 |
+
|
| 12 |
+
# Check if model and vectorizer files exist
|
| 13 |
+
model_path = 'Abdal_XSS_AI_Engine.keras'
|
| 14 |
+
vectorizer_path = 'vectorizer.pkl'
|
| 15 |
+
|
| 16 |
+
if not os.path.exists(model_path):
|
| 17 |
+
raise FileNotFoundError(f"Model file not found: {model_path}")
|
| 18 |
+
if not os.path.exists(vectorizer_path):
|
| 19 |
+
raise FileNotFoundError(f"Vectorizer file not found: {vectorizer_path}")
|
| 20 |
+
|
| 21 |
+
# Load the model from the Keras format
|
| 22 |
+
model_name = "Abdal XSS AI Engine"
|
| 23 |
+
model = tf.keras.models.load_model(model_path)
|
| 24 |
+
|
| 25 |
+
# Load the vectorizer
|
| 26 |
+
with open(vectorizer_path, 'rb') as f:
|
| 27 |
+
vectorizer = pickle.load(f)
|
| 28 |
+
|
| 29 |
+
# Read new data (sentences) from a file (e.g., 'attack-xss-payload.txt')
|
| 30 |
+
input_file = 'attack-xss-payload.txt'
|
| 31 |
+
if not os.path.exists(input_file):
|
| 32 |
+
raise FileNotFoundError(f"Input file not found: {input_file}")
|
| 33 |
+
|
| 34 |
+
with open(input_file, 'r', encoding='utf-8') as file:
|
| 35 |
+
new_sentences = [line.strip() for line in file if line.strip()] # Reading each line from file
|
| 36 |
+
|
| 37 |
+
# Check if any sentence exists for prediction
|
| 38 |
+
if not new_sentences:
|
| 39 |
+
raise ValueError("No data available for prediction.")
|
| 40 |
+
|
| 41 |
+
# Preprocess the new data using the loaded TF-IDF vectorizer
|
| 42 |
+
X_new = vectorizer.transform(new_sentences).toarray()
|
| 43 |
+
|
| 44 |
+
# Predict using the loaded model
|
| 45 |
+
predictions = (model.predict(X_new) > 0.5).astype(int)
|
| 46 |
+
|
| 47 |
+
# Print predictions
|
| 48 |
+
for i, sentence in enumerate(new_sentences):
|
| 49 |
+
print(f"Sentence: {sentence}")
|
| 50 |
+
print(f"Prediction: {'XSS Detected' if predictions[i] == 1 else 'No XSS Detected'}\n")
|
Use-Model-api.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import pickle
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
app = Flask(__name__)
|
| 7 |
+
|
| 8 |
+
# Load the model and vectorizer
|
| 9 |
+
model = tf.keras.models.load_model('Abdal_XSS_AI_Engine.h5')
|
| 10 |
+
with open('vectorizer.pkl', 'rb') as f:
|
| 11 |
+
vectorizer = pickle.load(f)
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
@app.route('/predict', methods=['POST'])
|
| 15 |
+
def predict():
|
| 16 |
+
data = request.json
|
| 17 |
+
sentences = data['sentences']
|
| 18 |
+
|
| 19 |
+
# Preprocess the input data using the vectorizer
|
| 20 |
+
X_new = vectorizer.transform(sentences).toarray()
|
| 21 |
+
|
| 22 |
+
# Make predictions
|
| 23 |
+
predictions = (model.predict(X_new) > 0.5).astype(int)
|
| 24 |
+
|
| 25 |
+
# Prepare and return the response
|
| 26 |
+
response = {
|
| 27 |
+
'predictions': ['XSS Detected' if pred == 1 else 'No XSS Detected' for pred in predictions.flatten()]
|
| 28 |
+
}
|
| 29 |
+
return jsonify(response)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
if __name__ == '__main__':
|
| 33 |
+
app.run(debug=True)
|
csv-dataset/XSS_dataset.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Flask
|
| 2 |
+
tensorflow
|
| 3 |
+
scikit-learn
|
| 4 |
+
pandas
|
| 5 |
+
numpy
|
| 6 |
+
pickle-mixin
|
scr.jpg
ADDED
|
vectorizer.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1025f0154ae4099f9220a20c5bf72d0a6ab3228d578af3ed3b55d5740958a270
|
| 3 |
+
size 247300
|