使用神經網路演算法檢測JAVA代碼溢出攻擊

來源:互聯網
上載者:User

標籤:使用神經網路演算法檢測JAVA代碼溢出攻擊

# -*- coding:utf-8 -*-import reimport matplotlib.pyplot as pltimport osfrom sklearn.feature_extraction.text import CountVectorizerfrom sklearn import cross_validationimport osimport numpy as npfrom sklearn.neural_network import MLPClassifierdef load_one_flle(filename): x=[] with open(filename) as f: line=f.readline() line=line.strip(‘\n‘) return linedef load_adfa_training_files(rootdir): x=[] y=[] list = os.listdir(rootdir) for i in range(0, len(list)): path = os.path.join(rootdir, list[i]) if os.path.isfile(path): x.append(load_one_flle(path)) print("Load file(%s)" % path) y.append(0) return x,ydef dirlist(path, allfile): filelist = os.listdir(path) for filename in filelist: filepath = os.path.join(path, filename) if os.path.isdir(filepath): dirlist(filepath, allfile) else: allfile.append(filepath) return allfiledef load_adfa_java_files(rootdir): x=[] y=[] allfile=dirlist(rootdir,[]) for file in allfile: if re.match(r"ADFA-LD/Attack_Data_Master/Java_Meterpreter_\d+/UAD-Java-Meterpreter*",file): print("Load file(%s)" % file) x.append(load_one_flle(file)) y.append(1) return x,yif __name__ == ‘__main__‘: x1,y1=load_adfa_training_files("ADFA-LD/Training_Data_Master/") x2,y2=load_adfa_java_files("ADFA-LD/Attack_Data_Master/") x=x1+x2 y=y1+y2 #print x vectorizer = CountVectorizer(min_df=1) x=vectorizer.fit_transform(x) x=x.toarray() mlp = MLPClassifier(hidden_layer_sizes=(150,50), max_iter=10, alpha=1e-4, solver=‘sgd‘, verbose=10, tol=1e-4, random_state=1, learning_rate_init=.1) score=cross_validation.cross_val_score(mlp, x, y, n_jobs=-1, cv=10) print(np.mean(score))

使用神經網路演算法檢測JAVA代碼溢出攻擊

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.