Update README.md
Browse files
README.md
CHANGED
|
@@ -1,168 +1,181 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
-
|
| 5 |
-
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
-
|
| 20 |
-
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
- **
|
| 33 |
-
- **
|
| 34 |
-
- **
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
-
|
| 45 |
-
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
model
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
if not os.path.exists(
|
| 119 |
-
raise FileNotFoundError(f"
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
#
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
metrics:
|
| 3 |
+
- accuracy
|
| 4 |
+
- precision
|
| 5 |
+
- recall
|
| 6 |
+
- f1
|
| 7 |
+
pipeline_tag: text-classification
|
| 8 |
+
tags:
|
| 9 |
+
- abdal
|
| 10 |
+
- xss
|
| 11 |
+
- hack
|
| 12 |
+
- ebrasha
|
| 13 |
+
- ai
|
| 14 |
+
- tensorflow
|
| 15 |
+
---
|
| 16 |
+
# Abdal XSS AI Engine
|
| 17 |
+
|
| 18 |
+
## 🎤 README Translation
|
| 19 |
+
- [English](README.md)
|
| 20 |
+
- [فارسی](README.fa.md)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
<p align="center"><img src="scr.jpg?raw=true"></p>
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
## 💎 General purpose
|
| 28 |
+
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.
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
## 🛠️ Development Environment Setup
|
| 32 |
+
- **Python 3.7 or higher**
|
| 33 |
+
- **Flask** (for building RESTful APIs)
|
| 34 |
+
- **TensorFlow** (Deep Learning models)
|
| 35 |
+
- **Scikit-learn** (for text preprocessing and TF-IDF vectorization)
|
| 36 |
+
- **Pandas** (for large-scale data management)
|
| 37 |
+
- **Deep understanding of web security and XSS attacks**
|
| 38 |
+
- **Git** (version control and repository management)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
### 🔥 Requirements
|
| 43 |
+
|
| 44 |
+
- **Python 3.7 or higher**
|
| 45 |
+
- **Flask**
|
| 46 |
+
- **TensorFlow**
|
| 47 |
+
- **Scikit-learn**
|
| 48 |
+
- **Pandas**
|
| 49 |
+
- **Pickle**
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
## ✨ Features
|
| 53 |
+
|
| 54 |
+
- Ability to process and detect hundreds of thousands of XSS patterns, including new emerging threats.
|
| 55 |
+
- Utilizes a deep learning model with multiple Dense and Dropout layers.
|
| 56 |
+
- Trained using a combined dataset from multiple CSV files.
|
| 57 |
+
- Employs TF-IDF technique for text feature extraction from XSS attacks.
|
| 58 |
+
- Capability to improve model accuracy with new data and continuous updates.
|
| 59 |
+
- Supports model optimization using the Adam optimizer and accuracy metrics.
|
| 60 |
+
- Saves the final model and vectorizer for future use and deployment in various environments.
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
## 📝️ How it Works?
|
| 64 |
+
|
| 65 |
+
You can use the model as an API for detecting XSS attacks by using the following code:
|
| 66 |
+
```python
|
| 67 |
+
from flask import Flask, request, jsonify
|
| 68 |
+
import tensorflow as tf
|
| 69 |
+
import pickle
|
| 70 |
+
import numpy as np
|
| 71 |
+
|
| 72 |
+
app = Flask(__name__)
|
| 73 |
+
|
| 74 |
+
# Load the model and vectorizer
|
| 75 |
+
model = tf.keras.models.load_model('Abdal_XSS_AI_Engine.h5')
|
| 76 |
+
with open('vectorizer.pkl', 'rb') as f:
|
| 77 |
+
vectorizer = pickle.load(f)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
@app.route('/predict', methods=['POST'])
|
| 81 |
+
def predict():
|
| 82 |
+
data = request.json
|
| 83 |
+
sentences = data['sentences']
|
| 84 |
+
|
| 85 |
+
# Preprocess the input data using the vectorizer
|
| 86 |
+
X_new = vectorizer.transform(sentences).toarray()
|
| 87 |
+
|
| 88 |
+
# Make predictions
|
| 89 |
+
predictions = (model.predict(X_new) > 0.5).astype(int)
|
| 90 |
+
|
| 91 |
+
# Prepare and return the response
|
| 92 |
+
response = {
|
| 93 |
+
'predictions': ['XSS Detected' if pred == 1 else 'No XSS Detected' for pred in predictions.flatten()]
|
| 94 |
+
}
|
| 95 |
+
return jsonify(response)
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
if __name__ == '__main__':
|
| 99 |
+
app.run(debug=True)
|
| 100 |
+
|
| 101 |
+
```
|
| 102 |
+
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:
|
| 103 |
+
|
| 104 |
+
```python
|
| 105 |
+
import os
|
| 106 |
+
import tensorflow as tf
|
| 107 |
+
import pickle
|
| 108 |
+
|
| 109 |
+
# Disable oneDNN custom operations
|
| 110 |
+
os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'
|
| 111 |
+
# Set TensorFlow logging level to 'ERROR' to suppress the info and warning messages
|
| 112 |
+
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
|
| 113 |
+
|
| 114 |
+
# Check if model and vectorizer files exist
|
| 115 |
+
model_path = 'Abdal_XSS_AI_Engine.keras'
|
| 116 |
+
vectorizer_path = 'vectorizer.pkl'
|
| 117 |
+
|
| 118 |
+
if not os.path.exists(model_path):
|
| 119 |
+
raise FileNotFoundError(f"Model file not found: {model_path}")
|
| 120 |
+
if not os.path.exists(vectorizer_path):
|
| 121 |
+
raise FileNotFoundError(f"Vectorizer file not found: {vectorizer_path}")
|
| 122 |
+
|
| 123 |
+
# Load the model from the Keras format
|
| 124 |
+
model_name = "Abdal XSS AI Engine"
|
| 125 |
+
model = tf.keras.models.load_model(model_path)
|
| 126 |
+
|
| 127 |
+
# Load the vectorizer
|
| 128 |
+
with open(vectorizer_path, 'rb') as f:
|
| 129 |
+
vectorizer = pickle.load(f)
|
| 130 |
+
|
| 131 |
+
# Read new data (sentences) from a file (e.g., 'attack-xss-payload.txt')
|
| 132 |
+
input_file = 'attack-xss-payload.txt'
|
| 133 |
+
if not os.path.exists(input_file):
|
| 134 |
+
raise FileNotFoundError(f"Input file not found: {input_file}")
|
| 135 |
+
|
| 136 |
+
with open(input_file, 'r', encoding='utf-8') as file:
|
| 137 |
+
new_sentences = [line.strip() for line in file if line.strip()] # Reading each line from file
|
| 138 |
+
|
| 139 |
+
# Check if any sentence exists for prediction
|
| 140 |
+
if not new_sentences:
|
| 141 |
+
raise ValueError("No data available for prediction.")
|
| 142 |
+
|
| 143 |
+
# Preprocess the new data using the loaded TF-IDF vectorizer
|
| 144 |
+
X_new = vectorizer.transform(new_sentences).toarray()
|
| 145 |
+
|
| 146 |
+
# Predict using the loaded model
|
| 147 |
+
predictions = (model.predict(X_new) > 0.5).astype(int)
|
| 148 |
+
|
| 149 |
+
# Print predictions
|
| 150 |
+
for i, sentence in enumerate(new_sentences):
|
| 151 |
+
print(f"Sentence: {sentence}")
|
| 152 |
+
print(f"Prediction: {'XSS Detected' if predictions[i] == 1 else 'No XSS Detected'}\n")
|
| 153 |
+
|
| 154 |
+
```
|
| 155 |
+
### Abdal XSS AI Engine - TensorFlow Model
|
| 156 |
+
|
| 157 |
+
To use the trained model in your TensorFlow project, simply run the following Python code:
|
| 158 |
+
|
| 159 |
+
```python
|
| 160 |
+
import tensorflow as tf
|
| 161 |
+
|
| 162 |
+
# Load the saved model
|
| 163 |
+
model = tf.keras.models.load_model('Abdal_XSS_AI_Engine')
|
| 164 |
+
|
| 165 |
+
print("✅ Model loaded successfully!")
|
| 166 |
+
```
|
| 167 |
+
|
| 168 |
+
## ❤️ Donation
|
| 169 |
+
|
| 170 |
+
https://ebrasha.com/abdal-donation
|
| 171 |
+
|
| 172 |
+
## 🤵 Programmer
|
| 173 |
+
Handcrafted with Passion by Ebrahim Shafiei (EbraSha)
|
| 174 |
+
|
| 175 |
+
E-Mail = [email protected]
|
| 176 |
+
|
| 177 |
+
Telegram: https://t.me/ProfShafiei
|
| 178 |
+
|
| 179 |
+
## ☠️ Reporting Issues
|
| 180 |
+
|
| 181 |
+
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.
|