kernelstub/Cognitor

GitHub: kernelstub/Cognitor

Cognitor 是一款防御性的 Windows 构建快照语义差异对比 CLI,用于补丁理解、变更审查和负责任的漏洞披露。

Stars: 41 | Forks: 8

# Cognitor image 防御性的 Patch Tuesday 语义差异对比 CLI,用于 Windows 构建快照 它专为补丁理解、验证审查、同级漏洞假设生成以及负责任的漏洞披露工作流而设计。它不会生成漏洞利用、武器化的概念验证材料、shellcode、绕过步骤或攻击性 payload。 ## 安装 ``` go build ./cmd/cognitor ``` ## 用法 大多数用户只需要一条命令: ``` ./cognitor compare ./testdata/snapshots/old ./testdata/snapshots/new ``` 这会扫描两个文件夹,对比二进制文件和证据工件,写入 `findings.db`,创建 `report.md`,并输出整体风险态势。 等效的显式形式: ``` ./cognitor analyze ./testdata/snapshots/old ./testdata/snapshots/new ./cognitor patch-diff ./testdata/snapshots/old ./testdata/snapshots/new --all-formats ./cognitor patch-diff --old ./testdata/snapshots/old --new ./testdata/snapshots/new --out report.md ``` 专注于特定的 Windows DLL,例如 `ntdll.dll`: ``` ./cognitor compare ./old ./new --focus ntdll.dll --workdir ./out ``` 对比快照中的每个 DLL: ``` ./cognitor compare ./old ./new --focus "*.dll" --workdir ./out --all-formats ``` 获取完整的分析师 bundle: ``` ./cognitor compare ./testdata/snapshots/old ./testdata/snapshots/new --workdir ./out --all-formats ``` 这将写入: ``` out/findings.db out/report.md out/report.json out/report.sarif out/report.csv out/cognitor-bundle.json ``` `cognitor-bundle.json` 会记录输入路径、风险态势、生成的工件以及 SHA-256 哈希,以便于交接或 CI 存档。 CI/流水线门禁示例: ``` ./cognitor compare ./testdata/snapshots/old ./testdata/snapshots/new --workdir /tmp/cognitor-convenience --all-formats --fail-on high ``` 高级/手动流水线: ``` ./cognitor snapshot create --name old --path ./snapshots/old ./cognitor snapshot create --name new --path ./snapshots/new --source /path/to/windows/build ./cognitor scan --snapshot old --path ./testdata/snapshots/old --out old.db ./cognitor scan --snapshot new --path ./testdata/snapshots/new --out new.db ./cognitor diff --old old.db --new new.db --out findings.db ./cognitor report --db findings.db --format markdown --out report.md ./cognitor report --db findings.db --format json --out report.json ./cognitor report --db findings.db --format sarif --out report.sarif ./cognitor graph --db findings.db --query newly-protected ./cognitor rules ``` ## 在 Windows 上试用 在 PowerShell 中从项目根目录构建 CLI: ``` .\scripts\build.ps1 ``` 这将创建: ``` bin\cognitor.exe ``` 默认构建目标为运行在典型 Intel 或 AMD 64 位机器上的 Windows 11,也称为 `windows/amd64`。如果您使用的是 ARM 架构的 Windows,请使用以下命令构建: ``` .\scripts\build.ps1 -Arch arm64 ``` 如果您是在 Linux、WSL、Git Bash 或 macOS 上构建,请使用: ``` ./scripts/build.sh ``` 该脚本默认交叉编译出真正的 Windows `.exe` 程序。如果 Windows 提示该可执行文件不兼容,请删除 `bin\cognitor.exe`,并使用与您的 CPU 架构相匹配的命令重新构建。 首先运行内置的模拟测试数据: ``` .\bin\cognitor.exe compare .\testdata\snapshots\old .\testdata\snapshots\new notepad .\report.md ``` 在一次运行中生成所有格式的报告: ``` .\bin\cognitor.exe compare .\testdata\snapshots\old .\testdata\snapshots\new --workdir .\out --all-formats notepad .\out\report.md ``` 或者手动运行每个阶段: ``` .\bin\cognitor.exe scan --snapshot old --path .\testdata\snapshots\old --out old.db .\bin\cognitor.exe scan --snapshot new --path .\testdata\snapshots\new --out new.db .\bin\cognitor.exe diff --old old.db --new new.db --out findings.db .\bin\cognitor.exe report --db findings.db --format markdown --out report.md notepad .\report.md ``` 要使用您自己的新旧文件夹,请创建或选择两个目录: ``` C:\cognitor-data\old C:\cognitor-data\new ``` 将较旧的 Windows 二进制文件放入 `old` 文件夹,将较新的已修补二进制文件放入 `new` 文件夹,然后运行: ``` .\bin\cognitor.exe compare C:\cognitor-data\old C:\cognitor-data\new --workdir C:\cognitor-data\out --all-formats ``` 针对独立的扫描、差异对比和报告阶段: ``` .\bin\cognitor.exe scan --snapshot old --path C:\cognitor-data\old --out old.db .\bin\cognitor.exe scan --snapshot new --path C:\cognitor-data\new --out new.db .\bin\cognitor.exe diff --old old.db --new new.db --out findings.db .\bin\cognitor.exe report --db findings.db --format markdown --out report.md notepad .\report.md ``` 您也可以让 Cognitor 初始化可用于扫描的文件夹: ``` .\bin\cognitor.exe snapshot create --name old --path C:\cognitor-data\old .\bin\cognitor.exe snapshot create --name new --path C:\cognitor-data\new ``` 请使用您获得授权进行分析的二进制文件,例如来自您自己的实验室 VM、挂载的 Windows 映像或内部更新提取工作流的文件。Cognitor 会准备并扫描文件夹,但不会下载 Windows 构建版本。 ## 快照输入 Cognitor 会扫描扩展名为 `.exe`、`.dll` 和 `.sys` 等 PE 类文件。DLL 是一等输入,因此可以直接对比 Windows 库(例如 `ntdll.dll`、`kernel32.dll`、`win32u.dll`)、浏览器 DLL、服务 DLL 以及应用程序 DLL。Cognitor 会收集哈希、文件元数据、可打印字符串、尽力提取的 PE 导入和区段、附属清单以及可选的分析导出数据。 它还会跟踪证据工件,例如 `.edb`、`.dat`、`.log`、`.evtx`、`.etl`、`.reg`、`.json`、`.xml`、`.ini`、`.inf`、`.cfg` 和 `.conf`。这些文件会被计算哈希、进行字符串扫描、存储在快照数据库中并自动进行比较,以便报告能够标出已更改的策略数据库、服务/注册表导出、事件追踪、清单和配置证据。 您可以使用 `snapshot create` 创建可扫描的目录。如果不使用 `--source`,它将初始化 `services.json`、`registry.json` 和 `SNAPSHOT.md`。如果使用 `--source`,它将复制类二进制文件和受支持的附属文件,同时保留相对路径。 反汇编程序导出器可以提供一个名为以下名称的附属文件: ``` binary.sys.analysis.json ``` 其结构如下: ``` { "functions": [ { "name": "DispatchCreate", "basic_block_count": 8, "calls": ["memcpy"], "strings": ["IOCTL_FOO"], "operations": ["copy user buffer"] } ] } ``` ## 报告 Markdown 报告包含运行元数据、执行风险态势、优先审查队列、自动变更清单、主要变更组件、主要发现、语义聚类、可能的漏洞类别、同级漏洞假设以及手动审查计划。JSON 和 SARIF 格式具有确定性,适合自动化处理。CSV 提供了一种紧凑的分类导出格式,适用于电子表格和 CI 仪表盘。 报告还包含初学者指南和研究人员的核对清单。规则引擎会在以下方面寻找防御性的补丁信号:访问检查、内存/边界检查、原生 API/syscall 边界验证、句柄/对象验证、token 和模拟流、RPC 认证和封送处理验证、COM 启动/安全权限更改、ALPC、注册表、服务以及对象生命周期/终止保护。 ## 开发 ``` make test make build ```
标签:AI合规, EVTX分析, Go, Ruby工具, 应用安全, 情报收集, 日志审计, 漏洞研究, 补丁比对, 逆向分析