Skip to content

Commit

Permalink
fix: dot env
Browse files Browse the repository at this point in the history
  • Loading branch information
TaeYoon committed May 22, 2024
1 parent 1cf2bba commit c09035b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
16 changes: 10 additions & 6 deletions web/app/libs/string_extractor/feature_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 != ''])


Expand All @@ -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='')
22 changes: 13 additions & 9 deletions web/app/libs/yara/yara_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 = ''
Expand Down

0 comments on commit c09035b

Please sign in to comment.