etke/checksec.rs

GitHub: etke/checksec.rs

一款用 Rust 编写的跨平台二进制安全属性检测工具,支持 ELF/PE/MachO 格式的安全加固特性分析。

Stars: 119 | Forks: 15

![checksec.rs](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/51f2c8a443213039.svg) [![crates.io](https://img.shields.io/crates/v/checksec.svg)](https://crates.io/crates/checksec) [![docs.rs](https://docs.rs/checksec/badge.svg)](https://docs.rs/checksec) [![github-actions](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/8182673cc3213039.svg)](https://github.com/etke/checksec.rs/actions) 一款使用 Rust 编写的快速跨平台 (ELF/PE/MachO) 二进制 checksec 工具。 *cargo crate 会定期发布* 使用 [goblin](https://docs.rs/goblin) 进行跨平台二进制解析,使用 [ignore](https://docs.rs/ignore) 进行快速递归路径迭代(支持 glob、文件类型和 `.gitignore` 等多种过滤器),以及使用 [serde](https://docs.rs/serde) 进行序列化/反序列化。 ### 前人的工作 此类工具已有大量先例。有些是独立的命令行实用程序,有些是框架或调试器的插件,但它们都仅限于特定平台。 项目 | 作者 | 语言 | 活跃状态 --- | --- |--- | --- [checksec.sh](http://trapkit.de/tools/checksec.html) *(original)*| Tobias Klein | _bash_ | *Jan 28, 2009 - Nov 17, 2011* [checksec](https://github.com/kholia/checksec) | Dhiru Kholia | _python_ | *Apr 18, 2013 - Mar 19, 2014* [checksec.sh](https://github.com/slimm609/checksec.sh) | Brian Davis | _bash_ | *Feb 14, 2014 - current* [pwntools - checksec](https://github.com/Gallopsled/pwntools/blob/26598f3da61677da6254daf25f699bda6635d803/pwnlib/elf/elf.py#L1734) | Gallopsled | _python_ | *Nov 8, 2014 - current* [CheckSec.c](https://github.com/hugsy/stuff/blob/master/CheckSec.c)| hugsy | _c_ | *Dec 7, 2015 - Apr 24, 2018* [checksec](https://github.com/klks/checksec) | klks | _c++_ | *Mar 25, 2017* [iOS-checksec.py](https://gist.github.com/ChiChou/15f0772db25343be0bb7072f15992a4e) | ChiChou | _python_ | *Apr 6, 2017* [checksec-win](https://github.com/wmliang/checksec-win) | Lucas Leong | _c++_ | *Aug 21, 2017* [winchecksec](https://github.com/trailofbits/winchecksec) | Trail Of Bits | _c++_ | *Aug 17, 2018 - current* [pe_mitigation_check.py](https://gist.github.com/edeca/d123c5eb2ce541f36ab245da544d80cd) | David Cannings | _python_ | *Sep 20, 2018* *注:列表非详尽无遗* ## 构建/安装 ### git *(HEAD)* ``` git clone https://github.com/etke/checksec.rs && cd checksec.rs cargo build --release cargo install --path . ``` ### cargo ``` cargo install checksec ``` ### 交叉编译 如果你需要为不同的目标操作系统或架构进行编译,请参阅 [rust-cross](https://github.com/japaric/rust-cross)。 ## 使用方法 ``` USAGE: checksec [FLAGS] [OPTIONS] FLAGS: -h, --help Prints help information -j, --json Output in json format --pretty Human readable json output -P, --process-all Check all running processes -V, --version Prints version information OPTIONS: -d, --directory Target directory -f, --file Target file -p, --process Name of running process to check ``` ### 示例 #### 独立 checksec ##### 单个二进制文件 ``` $ checksec -f test/binaries/true-x86_64 ELF64: | Canary: true CFI: false SafeStack: false Fortify: true Fortified: 2 NX: true PIE: None Relro: Partial RPATH: None RUNPATH: None | File: test/binaries/true-x86_64 ``` ##### 单个二进制文件 (json 输出) ``` $ checksec -f test/binaries/true-x86_64 --json {"binaries":[{"binarytype":"Elf64","file":"test/binaries/true-x86_64","properties":{"Elf":{"canary":true,"clang_cfi":false,"clang_safestack":false,"fortified":2,"fortify":true,"nx":true,"pie":"None","relro":"Partial","rpath":{"paths":["None"]},"runpath":{"paths":["None"]}}}}]} ``` ##### 运行中的进程 ``` $ checksec -P -zsh(34) ↪ ELF64: | Canary: true CFI: false SafeStack: false Fortify: true Fortified: 8 NX: true PIE: Full Relro: Full RPATH: None RUNPATH: None | File: /bin/zsh checksec(216) ↪ ELF64: | Canary: false CFI: false SafeStack: false Fortify: false Fortified: 0 NX: true PIE: Full Relro: Full RPATH: None RUNPATH: None | File: /home/etke/.cargo/bin/checksec init(1) ↪ ELF64: | Canary: false CFI: false SafeStack: false Fortify: false Fortified: 0 NX: true PIE: None Relro: Partial RPATH: None RUNPATH: None | File: /init ``` ##### 运行中的进程 (json 输出) ``` $ checksec -P --json {"processes":[{"binary":[{"binarytype":"Elf64","file":"/bin/zsh","properties":{"Elf":{"canary":true,"clang_cfi":false,"clang_safestack":false,"fortified":8,"fortify":true,"nx":true,"pie":"PIE","relro":"Full","rpath":{"paths":["None"]},"runpath":{"paths":["None"]}}}}],"pid":34},{"binary":[{"binarytype":"Elf64","file":"/init","properties":{"Elf":{"canary":false,"clang_cfi":false,"clang_safestack":false,"fortified":0,"fortify":false,"nx":true,"pie":"None","relro":"Partial","rpath":{"paths":["None"]},"runpath":{"paths":["None"]}}}}],"pid":1},{"binary":[{"binarytype":"Elf64","file":"/home/etke/.cargo/bin/checksec","properties":{"Elf":{"canary":false,"clang_cfi":false,"clang_safestack":false,"fortified":0,"fortify":false,"nx":true,"pie":"PIE","relro":"Full","rpath":{"paths":["None"]},"runpath":{"paths":["None"]}}}}],"pid":232}]} ``` #### libchecksec 只需在任何包含 goblin 依赖的现有项目中添加以下内容,即可在 `goblin::Object::{Elf, Mach, PE}` 对象上启用 checksec trait。 将 `checksec` crate 依赖添加到项目的 `Cargo.toml` 中。 ``` [dependencies] checksec = { version = "0.0.9", features = ["elf", "macho", "pe", "color"] } ``` 现在在项目源代码中,指定对 `checksec` crate 的依赖,并导入所需模块以访问关联的 `Properties` trait。 ``` extern crate checksec; use checksec::elf; use checksec::macho; use checksec::pe; ``` 现在你将能够直接从 `goblin::Object` 访问所有已实现的检查函数。 库用法示例请参见 [examples/](https://github.com/etke/checksec.rs/tree/master/examples)。 ## 待办事项 ### libchecksec 待办 * 特定平台检查 * ELF * Fortifiable * Rpath RW * PE * Authenticode 验证 * MachO * Rpath RW * 平台无关检查 * MachO * 将 `@rpath` 内容放入 `shared::VecRpath`,类似于 ELF 上的 `DT_RPATH`/`DT_RUNPATH` * 代码签名验证 ### checksec 待办 * ? ### 项目待办 * 测试 *(cargo test)* ## 贡献 欢迎改进! * 如有想法,请查看 Github Issues 页面。 * 想要添加功能?提交一个 issue 并标记为 `improvement` * 发现问题?提交一个 issue 并包含以下信息 * 问题描述 * 预期行为 * 附上 `bug` 标签 * 如需 pull request 被审查; * 必须使用提供的项目 `rustfmt.toml` 格式化 * 必须在使用提供的项目 `clippy.toml` 时没有 Clippy 警告/错误 *(如果存在)*
标签:Cargo, Checksec, CLI, DNS 反向解析, ELF, Goblin, MachO, PE, Rust, Web报告查看器, WiFi技术, 二进制分析, 二进制安全, 云安全监控, 云安全运维, 云资产清单, 内存保护, 可视化界面, 网络安全, 网络流量审计, 逆向工程, 通知系统, 通知系统, 隐私保护, 静态分析