druserx/scrutator

GitHub: druserx/scrutator

一款用纯 C 编写、零外部依赖的 PE 静态分析器,通过熵计算与启发式 API 组合检测为恶意软件样本提供快速风险筛查与评分。

Stars: 0 | Forks: 0

# Scrutator **用于恶意软件筛查的 PE 静态分析器**,使用纯 C 编写,无外部依赖。 该名称源于拉丁语 *scrutator* —— “深入检查者”。开发它的初衷是为了满足在隔离环境中对样本进行初步筛查的需求,旨在提供一种快速、便携且不依赖任何外部库(无 OpenSSL,无 libpe,什么都没有)的工具。 ``` __ __ _____________ ___/ /_____ _/ /_____ _____ / ___/ ___/ / / __/ __/ __ `/ __/ __ \/ ___/ (__ ) /__/ /_/ /_/ /_/ /_/ / /_/ /_/ / / /____/\___/\__,_/\__/\__/\__,_/\__/\____/_/ static pe analyzer | v0.4.2 ``` ## 功能 - 从零开始实现的 **SHA-256 Hash**(无需 OpenSSL) - **完整的 PE 格式解析** —— DOS header、COFF、Optional Header(PE32 和 PE32+)、节、导入表、导出表 - **基于节的香农熵** —— 检测加壳工具、加密代码和内嵌 shellcode - **提取字符串** ASCII 和 UTF-16LE,并识别可疑模式 - **启发式分析**,包含 50+ 按攻击类别分类的 API - **攻击技术检测**:代码注入、进程镂空、键盘记录、通过注册表实现持久化、通过 WinInet/WinHTTP 进行 C2、反调试 - **0-100 风险评分**,并按级别分类(INFO / BAIXO / MÉDIO / ALTO / CRÍTICO) - 可在 Linux 和 Windows 上编译(可在任何平台上分析 Windows 样本) ## 编译 ``` # Linux / WSL git clone https://github.com/druserx/scrutator cd scrutator make # Windows (MinGW) mingw32-make ``` 无外部依赖。只需要 `gcc` 和 `make`。 ## 用法 ``` # 基础分析 ./scrutator amostra.exe # 详细输出(包含所有提取的字符串) ./scrutator -v amostra.exe # 将报告保存为文本文件 ./scrutator -o relatorio.txt amostra.exe # 两者结合 ./scrutator -v -o relatorio.txt ransomware.dll ``` ## 输出示例 ``` [ INFORMACOES GERAIS ] ───────────────────────────────────────────────────────────── Arquivo : sample_ransomware.exe Tamanho : 487424 bytes (476.0 KB) SHA-256 : 3a4b2c1d9e8f7a6b5c4d3e2f1a0b9c8d7e6f5a4b3c2d1e0f9a8b7c6d5e4f3a2b Arquitetura : 32-bit (x86 (i386)) Subsystem : Windows GUI Tipo : EXE Entry Point : 0x00012a40 Image Base : 0x0000000000400000 ASLR : nao DEP/NX : nao [ SECOES ] ───────────────────────────────────────────────────────────── .text 0x00001000 0x00062f10 0x00000400 0x00063000 X R H=6.91 .rdata 0x00064000 0x0000e4a8 0x00063400 0x0000e600 . R H=4.23 .data 0x00073000 0x00004210 0x00071a00 0x00003200 . RW H=3.87 UPX0 0x00078000 0x00040000 0x00000000 0x00000000 X RW H=0.00 UPX1 0x000b8000 0x0003e000 0x00075200 0x0003dc00 X RW H=7.94 [ INDICADORES DE COMPORTAMENTO ] ───────────────────────────────────────────────────────────── [CRITICO ] [injecao ] Trifeta classica de injecao de DLL: VirtualAllocEx + WriteProcessMemory + CreateRemoteThread [CRITICO ] [evasao ] Secao UPX1 executavel com entropia 7.94 - shellcode ou codigo cifrado [ALTO ] [rede ] URLDownloadToFileA — Baixa arquivo da internet [ALTO ] [persistencia] Referencia a chave Run do registro - padrao de persistencia [MEDIO ] [evasao ] IsDebuggerPresent — Detecta debugger [MEDIO ] [execucao ] Referencia a PowerShell - comum em loaders e droppers ═════════════════════════════════════════════════════════════ SCORE DE RISCO: 87/100 [########..] CLASSIFICACAO : CRITICO ═════════════════════════════════════════════════════════════ ``` ## 项目结构 ``` scrutator/ ├── src/ │ ├── main.c # ponto de entrada, carregamento do arquivo │ ├── pe_parser.c # parse do formato PE (imports, exports, secoes) │ ├── sha256.c # SHA-256 implementado do zero (RFC 6234) │ ├── extrator.c # extração de strings ASCII e UTF-16LE │ ├── entropia.c # entropia de Shannon por seção │ ├── heuristicas.c # 50+ APIs classificadas + detecção de combos │ └── relatorio.c # output colorido no terminal + exportação txt ├── include/ │ ├── scrutator.h # tipos base, constantes, cores ANSI │ ├── pe_parser.h # estruturas do formato PE (sem windows.h) │ ├── sha256.h │ ├── extrator.h │ ├── entropia.h │ ├── heuristicas.h │ └── relatorio.h └── Makefile ``` ## 工作原理 ### PE 解析器 PE 格式的结构体(`DOSHeader`、`COFFHeader`、`OptionalHeader32/64`、`SectionHeader` 等)在 `pe_parser.h` 中使用 `#pragma pack(push, 1)` 手动定义 —— 这样该工具就可以在 Linux 上编译,而无需 `windows.h` 或 MinGW 来分析样本。 从 RVA 到物理偏移量的转换会手动遍历节表,并带有边界检查,以防止在处理损坏或被篡改的样本时发生崩溃。 ### 熵 使用香农公式:`H = -Σ(p_i × log₂(p_i))`,按节逐字节计算。阈值: - `>= 7.0` —— 几乎可以肯定是加密或压缩的 - 在可执行节中 `>= 6.0` —— 疑似 shellcode 或加壳 ### 启发式分析 除了单独检查 API 外,还能检测表征特定技术的**组合**: - `VirtualAllocEx` + `WriteProcessMemory` + `CreateRemoteThread` → 经典的 DLL 注入 - `NtUnmapViewOfSection` + `VirtualAlloc` + `WriteProcessMemory` → 进程镂空 - `VirtualAlloc` + `VirtualProtect` → 疑似 shellcode loader ## 已知限制 - 仅限静态分析 —— 不会执行样本 - 延迟导入(`DDIR_DELAY_IMPORT`)已被列出,但尚未完全处理 - .NET 样本需要单独分析(CIL bytecode,而非原生代码) - 文件大小限制为 100MB(实际上恶意软件很少超过此大小) ## 参考 - [PE Format Specification — Microsoft PECOFF v0.4](https://learn.microsoft.com/en-us/windows/win32/debug/pe-format) - [RFC 6234 — US Secure Hash Algorithms](https://www.rfc-editor.org/rfc/rfc6234) - [Shannon Entropy in Malware Analysis](https://practicalsecurityanalytics.com/file-entropy/) ## 许可证 MIT
标签:DAST, IP 地址批量处理, PE文件解析, 云安全监控, 云资产清单, 威胁情报, 客户端加密, 开发者工具, 恶意软件分析, 逆向工程, 静态分析