def analyze(): if request.method == 'POST': f = request.files.get('file', None) if f: fp = os.path.join(app.config['UPLOAD_FOLDER'], f.filename) f.save(fp) features = extract_features(fp) feature_vector = create_vector_single(features) arr = [] arr.append(feature_vector) mod1 = pickle.load(open("feature_model.p", "rb")) mod2 = pickle.load(open("kfold_train_data.p", "rb")) mod3 = pickle.load(open("decision.p", "rb")) mod4 = pickle.load(open("random_forest.p", "rb")) mod5 = pickle.load(open("xgb.p", "rb")) mod6 = pickle.load(open("pca_decision.p", "rb")) mod7 = pickle.load(open("pca_ran.p", "rb")) feature_vector_new = mod1.transform(arr) feature_vector_dec = mod6.transform(feature_vector_new) feature_vector_ran = mod7.transform(feature_vector_new) label = {} result = mod2.predict(feature_vector_new) if int(result[0]) == 1: label["svm"] = "Malware" else: label["svm"] = "Goodware" result = mod5.predict(feature_vector_new) if int(result[0]) == 1: label["xgb"] = "Malware" else: label["xgb"] = "Goodware" result = mod4.predict(feature_vector_ran) if int(result[0]) == 1: label["random_forest"] = "Malware" else: label["random_forest"] = "Goodware" result = mod3.predict(feature_vector_dec) if int(result[0]) == 1: label["Decision_tree"] = "Malware" else: label["Decision_tree"] = "Goodware" else: label = None return render_template("index.html", label=label)
def analyze(): if request.method == 'POST': f = request.files.get('file', None) if f: fp = os.path.join(app.config['UPLOAD_FOLDER'], f.filename) f.save(fp) features = extract_features(fp) feature_vector = create_vector_single(features) arr = [] arr.append(feature_vector) model = pickle.load(open("xgb.p", "rb")) mod = pickle.load(open("feature_model.p", "rb")) arr = mod.transform(arr) result = model.predict(arr) label = {} if int(result[0]) == 1: label["svm"] = "Malware" else: label["svm"] = "Goodware" else: label = None return render_template("index.html", label=label)
import pickle from feature_Extraction import extract_features, create_vector_single file_path = "C:/Users/MY PC/PycharmProjects/antivirus/uploads/com.phonepe.app.apk" features = extract_features(file_path) feature_vector = create_vector_single(features) print(len(feature_vector)) arr = [] arr.append(feature_vector) #model=pickle.load(open("xgb.p", "rb")) model = pickle.load(open("kfold_train_data.p", "rb")) mod = pickle.load(open("feature_model.p", "rb")) arr = mod.transform(arr) result = model.predict(arr) if int(result[0]) == 1: print("Malware") else: print("Goodware")
#Get intents with open('intents.txt', 'r') as fp3: for line in fp3: intents.append(line.strip().replace(",", "").replace("'", "")) features = permissions + apis + intents features.append('com.metasploit.stage.PayloadTrustManager') features.append('entropy_rate') features.append('db') features.append('class') #creating a .csv file with open('data.csv', 'w+') as op: header = "" for f in features: header += f.strip().replace('"', '') + ',' header = header[:-1] op.write(header + '\n') for apk in db.apk.find(): feature_vector = create_vector_single(apk) str_to_write = "" for i, feature in enumerate(feature_vector): if i < len(feature_vector) - 1: str_to_write += str(feature) + ',' else: class_label = 1 if apk['data_type'] == 'malware' else 0 str_to_write += str(feature) + ',' + str(class_label) op.write(str_to_write + '\n')