Detecting Java code Overflow attacks using neural network algorithms

Source: Internet
Author: User

#-*-Coding:utf-8-*-import reimport matplotlib.pyplot as Pltimport osfrom sklearn.feature_extraction.text import Countv Ectorizerfrom 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.PA Th.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 (PA th, 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))

Detecting Java Code Overflow attacks using neural network algorithms

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.