ebrasha commited on
Commit
2e73f63
·
verified ·
1 Parent(s): bec59b0

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +181 -168
README.md CHANGED
@@ -1,168 +1,181 @@
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
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.