學習筆記(三):使用K近鄰演算法檢測Rootkit
阿新 • • 發佈:2018-11-10
Rootkit是一種特殊的惡意軟體,它的功能是在安裝目標上隱藏自身以及指定的檔案,程序和網路連結等資訊。
1.資料蒐集
KDD 99 TCP連線內容特徵包括hot ,num_faild_logins ,logged_in ,num_compromised ,root_shell ,su_attempted ,num_root ,num_file_creations ,num_shells ,num_access_files ,num_outbound_cmds ,is_hot_login ,is_guest_login
載入KDD99資料集中的資料:
def load_kdd99(filename):
x=[]
with open(filename) asf:
for line in f:
line=line.strip('\n')
line=line.split(',')
x.append(line)
return x
篩選標記為Rootkit和normal且是telnet協議的資料:
if (x1[41] in ['rootkit.','normal.']) and (x1[2]=='telnet'): if x1[41]=='rootkit.': y.append(1) else: y.append(0)
2.特徵化:挑選Rootkit有關的特徵作為樣本特徵
x1 = x1[9:21]
v.append(x1)
for x1 in v:
v1 =[]
for x2 in x1:
v1.append(float(x2))
w.append(v1)
3.訓練樣本
clf = KNeighborsClassifier(n_neighbors = 3)
4.效果驗證
print cross_validation.cross_val_score(clf, x, y, n_jobs=-1, cv=10)