|
|
|
|
|
|
|
|
import os
|
|
|
import tensorflow as tf
|
|
|
import pickle
|
|
|
|
|
|
|
|
|
os.environ['TF_ENABLE_ONEDNN_OPTS'] = '0'
|
|
|
|
|
|
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
|
|
|
|
|
|
|
|
|
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}")
|
|
|
|
|
|
|
|
|
model_name = "Abdal XSS AI Engine"
|
|
|
model = tf.keras.models.load_model(model_path)
|
|
|
|
|
|
|
|
|
with open(vectorizer_path, 'rb') as f:
|
|
|
vectorizer = pickle.load(f)
|
|
|
|
|
|
|
|
|
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()]
|
|
|
|
|
|
|
|
|
if not new_sentences:
|
|
|
raise ValueError("No data available for prediction.")
|
|
|
|
|
|
|
|
|
X_new = vectorizer.transform(new_sentences).toarray()
|
|
|
|
|
|
|
|
|
predictions = (model.predict(X_new) > 0.5).astype(int)
|
|
|
|
|
|
|
|
|
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")
|
|
|
|