kazu11max17/bincheck

GitHub: kazu11max17/bincheck

一款用于快速检查 ELF 和 PE 二进制文件安全加固属性的命令行工具。

Stars: 2 | Forks: 0

# bincheck [![CI](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/466dca4464094516.svg)](https://github.com/kazu11max17/bincheck/actions) [![Crates.io](https://img.shields.io/crates/v/bincheck.svg)](https://crates.io/crates/bincheck) [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE) 用于 ELF 和 PE 文件的快速二进制安全属性检查器。 单条命令即可检查加固特性(RELRO、Stack Canary、NX、PIE、ASLR、DEP、CFG 等)。 ## 安装 ``` cargo install bincheck ``` 或者从源码构建: ``` git clone https://github.com/kazu11max17/bincheck.git cd bincheck cargo build --release ``` ## 快速开始 ``` # 检查二进制文件 bincheck /usr/bin/ls # 检查多个二进制文件 bincheck /usr/bin/ls /usr/bin/cat /usr/bin/grep # JSON 输出(用于脚本编写) bincheck -f json /usr/bin/ls # SARIF 输出(用于 CI 集成) bincheck -f sarif /usr/bin/ls # 如果任何检查失败则使 CI 失败 bincheck --strict /usr/bin/ls ``` ## 示例输出 ``` File: /usr/bin/ls (ELF) ┌────────────────┬────────┬──────────────────────┐ │ Property ┆ Status ┆ Details │ ╞════════════════╪════════╪══════════════════════╡ │ RELRO ┆ ✓ Pass ┆ Full │ ├────────────────┼────────┼──────────────────────┤ │ Stack Canary ┆ ✓ Pass ┆ __stack_chk_fail │ ├────────────────┼────────┼──────────────────────┤ │ NX ┆ ✓ Pass ┆ Stack not executable │ ├────────────────┼────────┼──────────────────────┤ │ PIE ┆ ✓ Pass ┆ ET_DYN │ ├────────────────┼────────┼──────────────────────┤ │ Fortify Source ┆ ✓ Pass ┆ __printf_chk │ ├────────────────┼────────┼──────────────────────┤ │ RPATH ┆ ✓ Pass ┆ Not set │ ├────────────────┼────────┼──────────────────────┤ │ RUNPATH ┆ ✓ Pass ┆ Not set │ └────────────────┴────────┴──────────────────────┘ ``` ## 安全检查 ### ELF 二进制文件 | 检查项 | 检测内容 | |--------|----------| | RELRO | GOT 保护级别(Full / Partial / None) | | Stack Canary | 动态或静态符号中包含 `__stack_chk_fail` | | NX | 不可执行的栈(W^X) | | PIE | 位置无关可执行文件(ASLR 支持) | | Fortify Source | 强化的 libc 函数(`__*_chk`) | | RPATH/RUNPATH | 硬编码的库搜索路径(供应链风险) | ### PE 二进制文件(Windows) | 检查项 | 检测内容 | |--------|----------| | ASLR | 地址空间布局随机化(`DYNAMIC_BASE`) | | High Entropy ASLR | 64 位 ASLR(`HIGH_ENTROPY_VA`) | | DEP/NX | 数据执行保护(`NX_COMPAT`) | | CFG | 控制流防护(`GUARD_CF`) | | SafeSEH | 结构化异常处理保护 | | Authenticode | 代码签名(证书表存在) | ## 输出格式 - **table**(默认)— 带颜色的终端输出 - **json** — 机器可读的 JSON - **sarif** — [SARIF v2.1.0](https://sarifweb.azurewebsites.net/),适用于 GitHub Code Scanning 和 CI 工具 ## GitHub Action ``` - uses: kazu11max17/bincheck@v0.1.0 with: files: target/release/myapp ``` 配合 SARIF 上传到 GitHub Code Scanning: ``` - uses: kazu11max17/bincheck@v0.1.0 with: files: target/release/myapp format: sarif strict: true sarif-upload: true ``` | 输入 | 描述 | 默认值 | |------|------|--------| | `files` | 以空格分隔的二进制路径(必需) | | | `format` | `table`、`json` 或 `sarif` | `table` | | `strict` | 若任一检查失败则退出 1 | `false` | | `version` | 要安装的 bincheck 版本 | latest | | `sarif-upload` | 上传 SARIF 到 Code Scanning | `false` | ## 使用场景 - **CI/CD 流水线**:使用 `--strict --format sarif` 在二进制加固不满足时阻止发布 - **固件审计**:检查嵌入式 Linux 二进制文件是否缺少保护 - **供应链安全**:在部署前验证第三方二进制文件 - **合规性**:记录安全属性以满足监管要求 ## 许可证 Apache-2.0
标签:ASLR, Cargo, CFG, CI集成, DEP, ELF, NX, PE, PIE, RELRO, Rust, SARIF, 二进制分析, 二进制安全, 云安全监控, 云安全运维, 可视化界面, 开源安全工具, 栈保护, 硬ening检查, 网络流量审计, 逆向工程平台, 通知系统, 静态分析