-
大小: 10.83MB文件类型: .zip金币: 1下载: 0 次发布日期: 2023-11-18
- 语言: Python
- 标签:
资源简介
机器学习驱动的Web应用程序防火墙以高精度检测恶意查询
代码片段和文件信息
‘‘‘
FWAF - Machine Learning driven Web Application Firewall
Author: Faizan Ahmad
Performance improvements: Timo Mechsner
Website: http://fsecurify.com
‘‘‘
from sklearn.feature_extraction.text import TfidfVectorizer
import os
from sklearn.cross_validation import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn import metrics
import urllib.parse
import matplotlib.pyplot as plt
def loadFile(name):
directory = str(os.getcwd())
filepath = os.path.join(directory name)
with open(filepath‘r‘) as f:
data = f.readlines()
data = list(set(data))
result = []
for d in data:
d = str(urllib.parse.unquote(d)) #converting url encoded data to simple string
result.append(d)
return result
badQueries = loadFile(‘badqueries.txt‘)
validQueries = loadFile(‘goodqueries.txt‘)
badQueries = list(set(badQueries))
validQueries = list(set(validQueries))
allQueries = badQueries + validQueries
yBad = [1 for i in range(0 len(badQueries))] #labels 1 for malicious and 0 for clean
yGood = [0 for i in range(0 len(validQueries))]
y = yBad + yGood
queries = allQueries
vectorizer = TfidfVectorizer(min_df = 0.0 analyzer=“char“ sublinear_tf=True ngram_range=(13)) #converting data to vectors
X = vectorizer.fit_transform(queries)
X_train X_test y_train y_test = train_test_split(X y test_size=0.2 random_state=42) #splitting data
badCount = len(badQueries)
validCount = len(validQueries)
lgs = LogisticRegression(class_weight={1: 2 * validCount / badCount 0: 1.0}) # class_weight=‘balanced‘)
lgs.fit(X_train y_train) #training our model
##############
# Evaluation #
##############
predicted = lgs.predict(X_test)
fpr tpr _ = metrics.roc_curve(y_test (lgs.predict_proba(X_test)[: 1]))
auc = metrics.auc(fpr tpr)
print(“Bad samples: %d“ % badCount)
print(“Good samples: %d“ % validCount)
print(“baseline Constant negative: %.6f“ % (validCount / (validCount + badCount)))
print(“------------“)
print(“Accuracy: %f“ % lgs.score(X_test y_test)) #checking the accuracy
print(“Precision: %f“ % metrics.precision_score(y_test predicted))
print(“Recall: %f“ % metrics.recall_score(y_test predicted))
print(“F1-Score: %f“ % metrics.f1_score(y_test predicted))
print(“AUC: %f“ % auc)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-05-15 00:24 Fwaf-Machine-Learning-driven-Web-Application-Firewall-master\
文件 65 2017-05-15 00:24 Fwaf-Machine-Learning-driven-Web-Application-Firewall-master\.gitignore
文件 294 2017-05-15 00:24 Fwaf-Machine-Learning-driven-Web-Application-Firewall-master\README.md
文件 3374922 2017-05-15 00:24 Fwaf-Machine-Learning-driven-Web-Application-Firewall-master\badqueries.txt
文件 296126 2017-05-15 00:24 Fwaf-Machine-Learning-driven-Web-Application-Firewall-master\firewall_fsecurify.jpg
文件 24063954 2017-05-15 00:24 Fwaf-Machine-Learning-driven-Web-Application-Firewall-master\goodqueries.txt
文件 2276 2017-05-15 00:24 Fwaf-Machine-Learning-driven-Web-Application-Firewall-master\sc
相关资源
- Python-使用MovieLens数据集训练的电影推
- Python-subpixel利用Tensorflow的一个子像素
-
Python-汉字的神经风格转移Neuralst
y - Python-神经网络模型能够从音频演讲中
- Python-深度增强学习算法的PyTorch实现策
- Python-基于深度学习的语音增强使用
- Python-基于知识图谱的红楼梦人物关系
- Python-STGAN用于图像合成的空间变换生
- Python-利用GAN进行图片填充
- Python-基于50W携程出行攻略的顺承事件
- Python-在TensorFlow中实现实现图像卷积网
- Python-60DaysRLChallenge中文版强化学习6
- Python-一个非常简单的BiLSTMCRF模型用于
- Python-Tensorflow仿AlphaGo框架实现的AI围棋
- Python-我是小诗姬全唐诗作为训练数据
- Python-用于物体跟踪的全卷积连体网络
- Python-数学建模竞赛中所使用的相关算
- Python-MonoDepthPyTorchPyTorch无监督单目深
- Python-用Tensorflowjs实现的可回收非可回
- Python-利用TensorFlow中的深度学习进行图
- Python-TensorFlow快速入门与实战课件与参
- Python-FCN完全卷积网络中最简单最容易
- Python-匈牙利算法卡尔曼滤波器多目标
- Python-mathAI一个拍照做题程序输入一张
- Python-Tensorflow实现SpatialAsDeepSpatialCNN
- Python-图像分类目标检测姿态估计分割
- Python-用python3opencv3做的中国车牌识别
- Python-各种对抗神经网络GAN大合集
- Python-Intel开源增强学习框架Coach
- Python-CENet用于2D医学图像分割的上下文
评论
共有 条评论