BinFlip/innospect

GitHub: BinFlip/innospect

纯 Rust 实现的 Inno Setup 安装程序解析与语义分析库,支持多版本文件提取和加密解密,专为恶意软件分析与逆向工程场景设计。

Stars: 0 | Forks: 0

# innospect 一个纯 Rust 编写的 [Inno Setup](https://jrsoftware.org/isinfo.php) 安装程序二进制文件解析器。提供了对 loader stub overlay、安装程序头、各种类型记录流的类型化访问,并支持从 Inno Setup 5.0 到 7.x 预览版系列的按需文件提取——包括现代的 XChaCha20 / `euFiles` / `euFull` 加密模式,以及传统的 ARC4 + SHA-1 / MD5 密码验证路径。 专为**恶意软件分析**和**逆向工程**而构建。该 crate 对对抗性输入是安全的:在库的根目录中,`unsafe_code`、引发 panic 的 unwrap、切片索引和带有副作用的算术运算均被禁止。 [![Crates.io](https://img.shields.io/crates/v/innospect.svg)](https://crates.io/crates/innospect) [![Docs.rs](https://img.shields.io/docsrs/innospect)](https://docs.rs/innospect) [![License: Apache-2.0](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE) ## 功能 - **PE 定位器** —— 包含现代的签名扫描路径 (5.1.5+) 和 5.1.5 之前版本安装程序使用的传统 `0x30` 文件偏移指针;兼容 BlackBox / GOG 重新打包器。 - **Setup-0 解压缩** —— 涵盖所有已记录版本切换点的 Stored / Zlib / LZMA1 / LZMA2,包含 6.5+ 的独立加密头路径和 6.4.x 的内联验证器路径。 - **Setup-1 文件提取** —— 支持 solid-LZMA 数据块及逐文件的 BCJ 反向过滤 (4108 / 5200 / 5.3.9-flip 变体),并在 EOF 处进行 SHA-256 / SHA-1 / MD5 / CRC-32 / Adler-32 校验和验证。 - **版本对应的 `TSetupHeader`** —— 覆盖 1.x..7.x 历史中的每个 `String` / `AnsiString` / count / tail 字段,并将 `[Files]` / `[Run]` / `[Icons]` / `[Registry]` / `[INI]` / `[Components]` / `[Tasks]` / `[Types]` / `[Languages]` / `[CustomMessages]` / `[Permissions]` 记录单独进行类型化。 - **加密** —— 使用带 PBKDF2-SHA-256 密钥派生的 XChaCha20 (Inno 6.4+);使用带加盐 SHA-1 (5.3.9..6.4) 或 MD5 (4.2..5.3.9) 的 ARC4;CRC32 验证器 (pre-4.2)。可通过 `from_bytes_with_passwords` 进行密码试探。 - **嵌入式 `[Code]` / IFPS** —— 重新导出了 [`pascalscript`](https://crates.io/crates/pascalscript) 容器解析器;`inno_api_description` 表将 Inno 运行时的导入(`RegWriteStringValue`、`Exec`、`ShellExec` 等)映射到用于分类的单行摘要。 - **分析 API** —— `exec_commands()` / `registry_ops()` / `shortcuts()` 会遍历相关的记录流,并使用安装与卸载阶段、注册表写入分类或图标目标解析来标记每个条目。 - **卸载程序重建** —— `extract_uninstaller()` 将 loader stub 的字节还原为规范的 `InUn` 格式。 ## 快速入门 ``` use innospect::{HeaderOption, InnoInstaller, RegistryOpKind}; let bytes = std::fs::read("setup.exe")?; let inst = InnoInstaller::from_bytes(&bytes)?; let v = inst.version(); println!("Inno {}.{}.{}.{} {}", v.a, v.b, v.c, v.d, v.marker_str()); if let Some(h) = inst.header() { println!("AppName: {}", h.app_name().unwrap_or("")); println!("Files: {}", h.counts().files); println!("Encrypted: {}", h.has_option(HeaderOption::Password)); } // Extract every file (skipping the uninstaller-stub entry). for (file, contents) in inst.extract_files().filter_map(Result::ok) { println!("{} -> {} bytes", file.destination, contents.len()); } // Analysis: exec commands, registry writes, resolved shortcut targets. for cmd in inst.exec_commands() { println!("{:?} {} {}", cmd.phase, cmd.filename(), cmd.parameters()); } let writes = inst .registry_ops() .filter(|op| op.kind == RegistryOpKind::Write) .count(); println!("Registry writes: {writes}"); ``` 对于受密码保护的安装程序: ``` use innospect::{Error, InnoInstaller}; let bytes = std::fs::read("encrypted-setup.exe")?; match InnoInstaller::from_bytes_with_passwords(&bytes, &["test123"]) { Ok(inst) => println!("Unlocked with {:?}", inst.password_used()), Err(Error::PasswordRequired) => eprintln!("Installer is encrypted; no password supplied"), Err(Error::WrongPassword) => eprintln!("None of the candidate passwords matched"), Err(e) => eprintln!("Parse failed: {e}"), } ``` 完整的检查工具位于 `examples/dump.rs` 中: ``` cargo run --example dump -- path/to/setup.exe ``` ## 覆盖范围 端到端测试对象包括: - 真实软件:HeidiSQL 12.17 (6.4.0.1),ImageMagick 7.1.2 (6.1.0)。 - 合成的明文矩阵:5.0.8, 5.1.14, 5.2.3, 5.3.11, 5.4.3, 5.5.5, 5.5.7, 6.0.0u, 6.3.0, 6.4.3, 6.5.2, 6.5.2-alt, 6.6.1, 6.7.0, 7.0.0-preview-3。 - 合成的加密矩阵 (密码 `test123`):相同版本序列的 `enc-files-*` (按块加密) 以及适用于 6.5.2+ 的 `enc-full-*` (`euFull` 全流加密)。 已识别但尚未通过公开样本矩阵进行测试的格式路径: 4.x, 3.x / 2.x, 16位的 1.2.x, ISX (My Inno Setup Extensions) 和多分片 (`DiskSpanning=yes`)。 ## 最低 Rust 版本 1.88 (edition 2024)。由 `Cargo.toml` 中的 `rust-version` 指定;CI 矩阵同时测试 `1.88` 和 `stable` 版本。 ## 许可证 Apache-2.0。详见 [`LICENSE`](LICENSE)。
标签:ARC4, DAST, DNS 反向解析, Inno Setup, LZMA, MD5, PBKDF2, PE文件, Rust, SHA-256, VPS部署, XChaCha20, Zlib, 云安全监控, 云资产清单, 加密解密, 可视化界面, 威胁情报, 安装程序, 密码学, 开发者工具, 恶意软件分析, 手动系统调用, 数据展示, 文件提取, 无unsafe代码, 红队, 网络流量审计, 解压缩, 解析器, 软件分析, 逆向工程, 通知系统, 静态分析, 黑盒测试