trailofbits/winchecksec
GitHub: trailofbits/winchecksec
Windows PE 文件安全缓解措施的静态检测工具,可分析 ASLR、DEP、CFG 等多种安全特性的启用状态。
Stars: 609 | Forks: 77
# winchecksec
[](https://github.com/trailofbits/winchecksec/actions/workflows/ci.yml)
`winchecksec` 对常见的 Windows 安全特性进行静态检测。
目前支持检测以下安全特性:
* ASLR:
* `/DYNAMICBASE` 且剥离了重定位项的边缘情况
* 用于 64 位系统的 `/HIGHENTROPYVA`
* 代码完整性/签名:
* `/INTEGRITYCHECK`
* 使用有效(受信任且活跃)证书进行的 Authenticode 签名(目前在 Linux 上不支持)
* DEP(也称为 W^X, NX)
* 通过 (`/ALLOWISOLATION`) 实现的清单隔离
* 结构化异常处理和 SafeSEH 支持
* Control Flow Guard 和 Return Flow Guard 检测
* Stack cookie (`/GS`) 支持
## 构建
`winchecksec` 依赖于 [pe-parse](https://github.com/trailofbits/pe-parse) 和
[uthenticode](https://github.com/trailofbits/uthenticode),可以通过 `vcpkg` 安装:
```
$ vcpkg install pe-parse uthenticode
```
**注意**:在 Windows 上,`vcpkg` 默认为 32 位构建。如果你正在进行 64 位的 `winchecksec`
构建,则需要显式地将依赖项构建为 64 位:
```
$ vcpkg install pe-parse:x64-windows uthenticode:x64-windows
```
### 在 Linux 上构建
```
$ git clone https://github.com/trailofbits/winchecksec.git
$ cd winchecksec
$ mkdir build
$ cd build
$ cmake -DCMAKE_BUILD_TYPE=Release ..
$ cmake --build .
$ ./build/winchecksec
```
### 在 Windows 上构建
```
> git clone https://github.com/trailofbits/winchecksec.git
> cd winchecksec
> mkdir build
> cd build
> cmake ..
> cmake --build . --config Release
> .\Release\winchecksec.exe C:\Windows\notepad.exe
```
## 使用
作为命令行工具,`winchecksec` 有两种输出模式:便于阅读的纯文本模式,以及用于其他程序消费的 JSON 模式。纯文本模式是默认的;通过传递 `--json` 或 `-j` 来启用 JSON 输出:
```
> .\Release\winchecksec.exe C:\Windows\notepad.exe
Dynamic Base : "Present"
ASLR : "Present"
High Entropy VA : "Present"
Force Integrity : "NotPresent"
Isolation : "Present"
NX : "Present"
SEH : "Present"
CFG : "NotPresent"
RFG : "NotPresent"
SafeSEH : "NotApplicable"
GS : "Present"
Authenticode : "NotPresent"
.NET : "NotPresent"
> .\Release\winchecksec.exe -j C:\Windows\notepad.exe
[{
"path": "C:\\Windows\\notepad.exe",
"mitigations": {
"dynamicBase": {
"presence": "Present",
"description": "Binaries with dynamic base support can be dynamically rebased, enabling ASLR."
},
"rfg": {
"description": "Binaries with RFG enabled have additional return-oriented-programming protections.",
"presence": "NotPresent"
},
"seh": {
"description": "Binaries with SEH support can use structured exception handlers.",
"presence": "Present"
},
// ...
}
}]
```
`winchecksec` 还提供了一个 C++ API;文档托管在
[这里](https://trailofbits.github.io/winchecksec/)。
## 开发
`winchecksec` 使用 `clang-format` 进行格式化。你可以使用 `clang-format` 目标在
本地自动格式化它:
```
$ make clang-format
```
`winchecksec` 还附带了一套单元测试,使用
[pegoat](https://github.com/trailofbits/pegoat) 作为各种安全缓解措施的参考。
要构建单元测试,请在 CMake 构建中传递 `-DBUILD_TESTS=1`。
## Windows 10 上不同 EXE 标志的统计
纯净 Windows 10 (1803) 安装中各种安全特性的普及率:
| aslr | authenticode | cfg | dynamicBase | forceIntegrity | gs | highEntropyVA | isolation | nx | rfg | safeSEH | seh |
| ---- | ------------ | --- | ----------- | -------------- | -- | ------------- | ---------- | --- | --- | ------- | --- |
| 79% | 37% | 49% | 79% | 3% | 65% | 43% | 100% | 79% | 6% | 25%| 91% |
标签:ASLR, Bash脚本, C++, CFG, Cli工具, Conpot, DEP, PE文件解析, SEH, Web报告查看器, Windows安全, 二进制分析, 云安全监控, 云安全运维, 云资产清单, 代码签名, 可执行文件检测, 安全缓解措施, 数据擦除, 漏洞利用防护, 网络安全审计, 逆向工程, 防御识别, 静态分析