-
Notifications
You must be signed in to change notification settings - Fork 0
/
luna_grabber_decompiler.py
49 lines (37 loc) · 1.5 KB
/
luna_grabber_decompiler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from os import getcwd, path
from sys import argv
from typing import List
from loguru import logger
from yara_scanner import YaraScanner
from utils.blank import blank_stage3, blank_stage4
from utils.decompile_utils import clean_up_temp_files, extract_pyinstaller_exe, find_payload_files
from utils.webhook_util import validate_webhooks
def luna_grabber_decompiler(exe_path: str) -> List[str]:
logger.info("Extracting PyInstaller package...")
extracted_dir = extract_pyinstaller_exe(exe_path)
final_result = []
logger.info("Locating payload file...")
yara_scanner = YaraScanner()
yara_scanner.track_yara_file("rules/infosteal.yar")
yara_scanner.load_rules()
all_pyc_files = find_payload_files(extracted_dir, ".pyc", "")
target_file = None
for file in all_pyc_files:
yara_scanner.scan(file)
if scan_result := yara_scanner.scan_results:
if "lunagrabber" in [x.get("rule", "").lower() for x in scan_result]:
target_file = file
break
if target_file:
with open(target_file, "rb") as file:
assembly = file.read()
stage3 = blank_stage3(assembly)
stage4 = blank_stage4(stage3)
final_result = validate_webhooks(stage4)
if final_result:
logger.success(final_result)
clean_up_temp_files(extracted_dir)
clean_up_temp_files(path.join(getcwd(), 'dump.bin'))
return final_result
if __name__ == "__main__":
print(luna_grabber_decompiler(argv[1]))