| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- # -*- coding: utf-8 -*-
- """
- 固化逆向分析产物:从解包镜像生成全量字符串/URL/SQL/函数入口候选/关键标记索引。
- 可重复运行,产物全部写入本目录。源数据: /tmp/unpacked.bin (由 ../unpack_stub.py 从原始zip静态解出)
- """
- import hashlib
- import re
- import sys
- import zipfile
- import os
- from pathlib import Path
- sys.stdout.reconfigure(encoding='utf-8', errors='replace')
- HERE = Path(__file__).parent
- SRC = Path(os.environ.get('TEMP', r'C:/Users/20175/AppData/Local/Temp')) / 'unpacked.bin'
- d = SRC.read_bytes()
- print(f'源镜像: {SRC} {len(d):,} bytes sha256={hashlib.sha256(d).hexdigest()[:16]}...')
- # ---------- 1. 落盘解包镜像 + zip 备份 ----------
- (HERE / 'unpacked.bin').write_bytes(d)
- with zipfile.ZipFile(HERE / 'unpacked.bin.zip', 'w', zipfile.ZIP_DEFLATED, compresslevel=6) as zf:
- zf.write(HERE / 'unpacked.bin', 'unpacked.bin')
- # ---------- 2. 字符串全量 ----------
- def gbk_strings(b):
- out = []
- for m in re.finditer(rb'(?:[\x20-\x7e\xa1-\xfe]{4,})', b):
- try:
- s = m.group().decode('gbk')
- if any('\u4e00' <= c <= '\u9fff' for c in s):
- out.append((m.start(), s))
- except Exception:
- pass
- return out
- G = gbk_strings(d)
- A = [(m.start(), m.group().decode('ascii', 'replace'))
- for m in re.finditer(rb'[\x20-\x7e]{6,}', d)]
- with open(HERE / 'strings_gbk.txt', 'w', encoding='utf-8') as f:
- for off, s in G:
- f.write(f'{off:#010x} {s}\n')
- with open(HERE / 'strings_ascii.txt', 'w', encoding='utf-8') as f:
- for off, s in A:
- f.write(f'{off:#010x} {s}\n')
- print(f'GBK中文串 {len(G):,} 条 -> strings_gbk.txt')
- print(f'ASCII串 {len(A):,} 条 -> strings_ascii.txt')
- # ---------- 3. URL/域名清单(带偏移) ----------
- urls = []
- for off, s in A + G:
- for m in re.findall(r'https?://[^\s"\'<>]+', s):
- urls.append((off, m[:120]))
- for m in re.findall(r'\b(?:[a-z0-9-]+\.)+(?:com|cn|net|top|xyz|vip|cc|shop|icu|io|me)(?::\d+)?\b', s, re.I):
- urls.append((off, m.lower()))
- urls = sorted(set(urls))
- with open(HERE / 'urls.txt', 'w', encoding='utf-8') as f:
- for off, u in urls:
- f.write(f'{off:#010x} {u}\n')
- print(f'URL/域名 {len(urls)} 条 -> urls.txt')
- # ---------- 4. SQL 语句清单 ----------
- sqls = set()
- for m in re.findall(rb'(?:(?:select|insert|update|delete|create)[\x20-\x7e]{6,})', d, re.I):
- sqls.add(m.decode('ascii', 'replace'))
- with open(HERE / 'sql.txt', 'w', encoding='utf-8') as f:
- f.write('\n'.join(sorted(sqls)))
- print(f'SQL 语句 {len(sqls)} 条 -> sql.txt')
- # ---------- 5. 函数入口候选(EPL特征码) ----------
- # EPL 初始化入口: cld; fninit (ELangPatcher README 证实的特征)
- # EPL 控件事件: call dword[ebp-4]
- # EPL 子程序常见序言: push ebp; mov ebp,esp 且尾部 ret 前有 lib call
- marks = {}
- marks['cld_fninit(FC DB E3)'] = [m.start() for m in re.finditer(rb'\xfc\xdb\xe3', d)]
- marks['call_[ebp-4](FF 55 FC)'] = [m.start() for m in re.finditer(rb'\xff\x55\xfc', d)]
- marks['push_ebp_mov_ebp_esp'] = [m.start() for m in re.finditer(rb'\x55\x8b\xec', d)]
- marks['int3_padding(CC x4)'] = [m.start() for m in re.finditer(rb'\xcc\xcc\xcc\xcc', d)]
- with open(HERE / 'function_candidates.txt', 'w', encoding='utf-8') as f:
- for name, offs in marks.items():
- f.write(f'=== {name}: {len(offs)} 处 ===\n')
- f.write(', '.join(f'{o:#x}' for o in offs[:400]) + '\n\n')
- for name, offs in marks.items():
- print(f'{name}: {len(offs)} 处')
- # ---------- 6. 关键标记索引(下一阶段导航用) ----------
- KEYS = ['122.51.38.41', 'datawuyou', 'doulaoban', 'ksapisrv', 'kuaishouzt', 'kwaixiaodian',
- 'niu.e.kuaishou.com', 'kuaishoupay', 'passToken', 'upload', 'fragment', 'anchor',
- 'publishvideo', 'jihua', 'money', 'ips', 'cookie1', '磁力', '充值', '爆单',
- '上热门', '抖老板', '云推', '挂车', '置顶', '定时', '监控', '投递', '标题',
- 'biaoti', 'download', 'http_', 'POST', 'Content-Type']
- with open(HERE / 'markers_index.txt', 'w', encoding='utf-8') as f:
- for k in KEYS:
- kb = k.encode('gbk', errors='ignore') or k.encode()
- offs = [m.start() for m in re.finditer(re.escape(kb), d)]
- f.write(f'{k}: {len(offs)} 处 {", ".join(hex(o) for o in offs[:12])}\n')
- print('关键标记索引 -> markers_index.txt')
- # ---------- 7. 产物清单与哈希 ----------
- print('\n=== 产物清单 ===')
- for p in sorted(HERE.iterdir()):
- if p.is_file():
- h = hashlib.md5(p.read_bytes()).hexdigest()[:12]
- print(f' {p.name:<28} {p.stat().st_size:>12,} bytes md5:{h}')
|