def call_and_add(t, fname): global DATA_TYPE try: print('[*] Feature Extracting: {}'.format(fname)) result = extract_features(fname) print('[*] Adding to db: {}'.format(fname)) client = MongoClient() db = client[DB_NAME] result['data_type'] = t print(result['data_type']) db['apk'].update({'sha256': result['sha256']}, result, upsert=True) except Exception as e: print('[!] Error occured with {}, {}'.format(fname, e))
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")