From c09035b1136e5f0f2ec5aecf2c2c355ca901479c Mon Sep 17 00:00:00 2001 From: TaeYoon Date: Wed, 22 May 2024 17:02:26 +0900 Subject: [PATCH] fix: dot env --- .../libs/string_extractor/feature_string.py | 16 +++++++++----- web/app/libs/yara/yara_detect.py | 22 +++++++++++-------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/web/app/libs/string_extractor/feature_string.py b/web/app/libs/string_extractor/feature_string.py index 63aa6fe114..ad4ee95a21 100644 --- a/web/app/libs/string_extractor/feature_string.py +++ b/web/app/libs/string_extractor/feature_string.py @@ -3,23 +3,27 @@ import sys import json import pickle +from dotenv import load_dotenv # 수정 되어 -SIGNATURES = {'trickler'} +SIGNATURES = {} -pickle_file_path = r"web\app\libs\string_extractor\sig_counter.pkl" +load_dotenv() +pkl_sig_path = os.getenv('PKL_SIG_PATH') -with open(pickle_file_path, "rb") as f: +with open(pkl_sig_path, "rb") as f: additional_signatures = pickle.load(f) SIGNATURES.update(additional_signatures) # string feature extract + + def extract_string(path, min_bytes=6): with open(os.path.join(path), 'rb') as f: file_data = f.read() string = set(s.decode().strip().lower() for s in re.findall( b"[\x20-\x7e]{" + bytes(str(min_bytes), 'utf-8') + b",}", file_data)) - + return set([i for i in string if i != '']) @@ -43,10 +47,10 @@ def extract_string(path, min_bytes=6): score += 1 else: normal.append(string) - + respone['score'] = score respone['attack'] = attack respone['normal'] = normal - + json_data = json.dumps(respone) print(json_data, end='') diff --git a/web/app/libs/yara/yara_detect.py b/web/app/libs/yara/yara_detect.py index fe2b2265b0..1a06d32535 100644 --- a/web/app/libs/yara/yara_detect.py +++ b/web/app/libs/yara/yara_detect.py @@ -4,15 +4,17 @@ import os import re import pickle +from dotenv import load_dotenv def extract_string(path, min_bytes=6): - with open(os.path.join(path), 'rb') as f: - file_data = f.read() - string = set(s.decode().strip().lower() for s in re.findall( - b"[\x20-\x7e]{" + bytes(str(min_bytes), 'utf-8') + b",}", file_data)) - - return set([i for i in string if i != '']) + with open(os.path.join(path), 'rb') as f: + file_data = f.read() + string = set(s.decode().strip().lower() for s in re.findall( + b"[\x20-\x7e]{" + bytes(str(min_bytes), 'utf-8') + b",}", file_data)) + + return set([i for i in string if i != '']) + def detect(file_folder_path, yar_file_path): ret = { @@ -30,10 +32,12 @@ def detect(file_folder_path, yar_file_path): # yar_folder_path = yar_folder_path.rstrip('/') # for rule in yar_file_list: # rules = yara.compile(filepath=f'{yar_folder_path}/{rule}') - - with open('./whitelist.pkl', 'rb') as f: + load_dotenv() + whitelist_path = os.getenv('PKL_WHITELIST_PATH') + + with open(whitelist_path, 'rb') as f: whitelist = pickle.load(f) - + rules = yara.compile(filepath=yar_file_path) for i, filename in enumerate(exe_file_list): match_data = ''