选项
首页首页 Skill 安全 zeroize-audit

zeroize-audit

trailofbits/skills trailofbits/skills

通过汇编级分析和控制流验证,检测源代码中敏感数据未进行清零的情况,并识别因编译器优化而被移除的清零操作。适用于审计处理机密信息、密钥、密码或其他敏感数据的 C/C++/Rust 代码。

...展开全部
83
更新时间 2026-07-01

关于zeroize-audit

zeroize-audit 技能是一款专注于安全性的审计工具,旨在识别 C、C++ 和 Rust 代码库中对敏感数据的不当处理。其主要目的是检测加密密钥、密码、令牌、种子、随机数、凭据及其他机密值等敏感信息是否存在零化处理缺失的情况。 除了查找缺失的清理操作外,该技能还会分析预期的清零例程是否因编译器优化(如死存储消除)而被移除或削弱。与优化导致的移除相关的发现,需要通过 LLVM IR 或汇编分析提供的编译器证据来支持。

该技能提供多层分析以验证安全的内存清理。其功能包括:针对栈保留和寄存器溢出的汇编级检查、机密数据复制的数据流追踪、堆分配器安全警告、用于分析循环展开等优化效果的语义 LLVM IR 分析,以及用于验证执行路径中清理覆盖率的控制流图分析。 它还可以生成运行时验证测试,并输出结构化的 JSON 报告。用户可选择性地启用高级分析功能,包括汇编分析、语义 IR 分析以及控制流验证。该技能以只读方式处理目标代码库,并将分析结果仅写入临时工作目录。

该技能面向安全工程师、密码学开发人员、审计员以及维护安全关键型软件的团队。 常见用例包括:审计加密实现、审查身份验证系统、验证个人身份信息(PII)的安全处理、调查涉及机密信息的内存安全问题,以及验证敏感数据在正常路径和错误处理路径中是否均被彻底清除。该技能最适合具有有效构建上下文和可编译翻译单元(TU)的项目。

常见问题

zeroize-audit 可以分析哪些类型的代码库?

该技能支持 C、C++ 和 Rust 代码库。分析需要 C/C++ 项目中的 compile_commands.json 文件,或 Rust 项目中的 Cargo.toml 文件。

该技能能否证明零化操作已被优化掉?

可以。声称清零操作已被优化掉的分析结果需要提供相应的编译器证据,例如显示清零操作被移除或弱化的 LLVM IR 或汇编级差异。

zeroize-audit 会修改正在审计的源代码吗?

不会。该技能以只读方式处理目标代码库,仅将分析结果写入临时工作目录。

运行分析有哪些要求?

目标项目必须具备有效的构建上下文和可编译的翻译单元。C/C++ 分析通常需要 `compile_commands.json` 文件,而 Rust 分析则需要 `Cargo.toml` 配置文件。

所有高级分析结果在每个环境中都可用吗?

不一定。某些高级分析依赖于可选功能,例如汇编代码生成、语义 LLVM IR 分析、控制流图分析或 Serena MCP 的可用性。当所需的语义功能不可用时,某些分析结果可能会被降级处理以便进行审查。

在 GitHub 上查看

zeroize-audit — Claude Skill

When to Use

  • Auditing cryptographic implementations (keys, seeds, nonces, secrets)
  • Reviewing authentication systems (passwords, tokens, session data)
  • Analyzing code that handles PII or sensitive credentials
  • Verifying secure cleanup in security-critical codebases
  • Investigating memory safety of sensitive data handling

When NOT to Use

  • General code review without security focus
  • Performance optimization (unless related to secure wiping)
  • Refactoring tasks not related to sensitive data
  • Code without identifiable secrets or sensitive values

Purpose

Detect missing zeroization of sensitive data in source code and identify zeroization that is removed or weakened by compiler optimizations (e.g., dead-store elimination), with mandatory LLVM IR/asm evidence. Capabilities include:

  • Assembly-level analysis for register spills and stack retention
  • Data-flow tracking for secret copies
  • Heap allocator security warnings
  • Semantic IR analysis for loop unrolling and SSA form
  • Control-flow graph analysis for path coverage verification
  • Runtime validation test generation

Scope

  • Read-only against the target codebase (does not modify audited code; writes analysis artifacts to a temporary working directory).
  • Produces a structured report (JSON).
  • Requires valid build context (compile_commands.json) and compilable translation units.
  • "Optimized away" findings only allowed with compiler evidence (IR/asm diff).

Inputs

See {baseDir}/schemas/input.json for the full schema. Key fields:

FieldRequiredDefaultDescription
pathyesRepo root
compile_dbnonullPath to compile_commands.json for C/C++ analysis. Required if cargo_manifest is not set.
cargo_manifestnonullPath to Cargo.toml for Rust crate analysis. Required if compile_db is not set.
confignoYAML defining heuristics and approved wipes
opt_levelsno["O0","O1","O2"]Optimization levels for IR comparison. O1 is the diagnostic level: if a wipe disappears at O1 it is simple DSE; O2 catches more aggressive eliminations.
languagesno["c","cpp","rust"]Languages to analyze
max_tusnoLimit on translation units processed from compile DB
mcp_modenopreferoff, prefer, or require — controls Serena MCP usage
mcp_required_for_advancednotrueDowngrade SECRET_COPY, MISSING_ON_ERROR_PATH, and NOT_DOMINATING_EXITS to needs_review when MCP is unavailable
mcp_timeout_msnoTimeout budget for MCP semantic queries
poc_categoriesnoall 11 exploitableFinding categories for which to generate PoCs. C/C++ findings: all 11 categories supported. Rust findings: only MISSING_SOURCE_ZEROIZE, SECRET_COPY, and PARTIAL_WIPE are supported; other Rust categories are marked poc_supported=false.
poc_output_dirnogenerated_pocs/Output directory for generated PoCs
enable_asmnotrueEnable assembly emission and analysis (Step 8); produces STACK_RETENTION, REGISTER_SPILL. Auto-disabled if emit_asm.sh is missing.
enable_semantic_irnofalseEnable semantic LLVM IR analysis (Step 9); produces LOOP_UNROLLED_INCOMPLETE
enable_cfgnofalseEnable control-flow graph analysis (Step 10); produces MISSING_ON_ERROR_PATH, NOT_DOMINATING_EXITS
enable_runtime_testsnofalseEnable runtime test harness generation (Step 11)

Prerequisites

Before running, verify the following. Each has a defined failure mode.

C/C++ prerequisites:

PrerequisiteFailure mode if missing
compile_commands.json at compile_db pathFail fast — do not proceed
clang on PATHFail fast — IR/ASM analysis impossible
uvx on PATH (for Serena)If mcp_mode=require: fail. If mcp_mode=prefer: continue without MCP; downgrade affected findings per Confidence Gating rules.
{baseDir}/tools/extract_compile_flags.pyFail fast — cannot extract per-TU flags
{baseDir}/tools/emit_ir.shFail fast — IR analysis impossible
{baseDir}/tools/emit_asm.shWarn and skip assembly findings (STACK_RETENTION, REGISTER_SPILL)
{baseDir}/tools/mcp/check_mcp.shWarn and treat as MCP unavailable
{baseDir}/tools/mcp/normalize_mcp_evidence.pyWarn and use raw MCP output

Rust prerequisites:

PrerequisiteFailure mode if missing
Cargo.toml at cargo_manifest pathFail fast — do not proceed
cargo check passesFail fast — crate must be buildable
cargo +nightly on PATHFail fast — nightly required for MIR and LLVM IR emission
uv on PATHFail fast — required to run Python analysis scripts
{baseDir}/tools/validate_rust_toolchain.shWarn — run preflight manually. Checks all tools, scripts, nightly, and optionally cargo check. Use --json for machine-readable output, --manifest to also validate the crate builds.
{baseDir}/tools/emit_rust_mir.shFail fast — MIR analysis impossible (--opt, --crate, --bin/--lib supported; --out can be file or directory)
{baseDir}/tools/emit_rust_ir.shFail fast — LLVM IR analysis impossible (--opt required; --crate, --bin/--lib supported; --out must be .ll)
{baseDir}/tools/emit_rust_asm.shWarn and skip assembly findings (STACK_RETENTION, REGISTER_SPILL). Supports --opt, --crate, --bin/--lib, --target, --intel-syntax; --out can be .s file or directory.
{baseDir}/tools/diff_rust_mir.shWarn and skip MIR-level optimization comparison. Accepts 2+ MIR files, normalizes, diffs pairwise, and reports first opt level where zeroize/drop-glue patterns disappear.
{baseDir}/tools/scripts/semantic_audit.pyWarn and skip semantic source analysis
{baseDir}/tools/scripts/find_dangerous_apis.pyWarn and skip dangerous API scan
{baseDir}/tools/scripts/check_mir_patterns.pyWarn and skip MIR analysis
{baseDir}/tools/scripts/check_llvm_patterns.pyWarn and skip LLVM IR analysis
{baseDir}/tools/scripts/check_rust_asm.pyWarn and skip Rust assembly analysis (STACK_RETENTION, REGISTER_SPILL, drop-glue checks). Dispatches to check_rust_asm_x86.py (production) or check_rust_asm_aarch64.py (EXPERIMENTAL — AArch64 findings require manual verification).
{baseDir}/tools/scripts/check_rust_asm_x86.pyRequired by check_rust_asm.py for x86-64 analysis; warn and skip if missing
{baseDir}/tools/scripts/check_rust_asm_aarch64.pyRequired by check_rust_asm.py for AArch64 analysis (EXPERIMENTAL); warn and skip if missing

Common prerequisite:

PrerequisiteFailure mode if missing
{baseDir}/tools/generate_poc.pyFail fast — PoC generation is mandatory

Approved Wipe APIs

The following are recognized as valid zeroization. Configure additional entries in {baseDir}/configs/.

C/C++

  • explicit_bzero
  • memset_s
  • SecureZeroMemory
  • OPENSSL_cleanse
  • sodium_memzero
  • Volatile wipe loops (pattern-based; see volatile_wipe_patterns in {baseDir}/configs/default.yaml)
  • In IR: llvm.memset with volatile flag, volatile stores, or non-elidable wipe call

Rust

  • zeroize::Zeroize trait (zeroize() method)
  • Zeroizing<T> wrapper (drop-based)
  • ZeroizeOnDrop derive macro

Finding Capabilities

Findings are grouped by required evidence. Only attempt findings for which the required tooling is available.

Finding IDDescriptionRequiresPoC Support
MISSING_SOURCE_ZEROIZENo zeroization found in sourceSource onlyYes (C/C++ + Rust)
PARTIAL_WIPEIncorrect size or incomplete wipeSource onlyYes (C/C++ + Rust)
NOT_ON_ALL_PATHSZeroization missing on some control-flow paths (heuristic)Source onlyYes (C/C++ only)
SECRET_COPYSensitive data copied without zeroization trackingSource + MCP preferredYes (C/C++ + Rust)
INSECURE_HEAP_ALLOCSecret uses insecure allocator (malloc vs. secure_malloc)Source onlyYes (C/C++ only)
OPTIMIZED_AWAY_ZEROIZECompiler removed zeroizationIR diff required (never source-only)Yes
STACK_RETENTIONStack frame may retain secrets after returnAssembly required (C/C++); LLVM IR alloca+lifetime.end evidence (Rust); assembly corroboration upgrades to confirmedYes (C/C++ only)
REGISTER_SPILLSecrets spilled from registers to stackAssembly required (C/C++); LLVM IR load+call-site evidence (Rust); assembly corroboration upgrades to confirmedYes (C/C++ only)
MISSING_ON_ERROR_PATHError-handling paths lack cleanupCFG or MCP requiredYes
NOT_DOMINATING_EXITSWipe doesn't dominate all exitsCFG or MCP requiredYes
LOOP_UNROLLED_INCOMPLETEUnrolled loop wipe is incompleteSemantic IR requiredYes

Agent Architecture

The analysis pipeline uses 11 agents across 8 phases, invoked by the orchestrator ({baseDir}/prompts/task.md) via Task. Agents write persistent finding files to a shared working directory (/tmp/zeroize-audit-{run_id}/), enabling parallel execution and protecting against context pressure.

AgentPhasePurposeOutput Directory
0-preflightPhase 0Preflight checks (tools, toolchain, compile DB, crate build), config merge, workdir creation, TU enumeration{workdir}/
1-mcp-resolverPhase 1, Wave 1 (C/C++ only)Resolve symbols, types, and cross-file references via Serena MCPmcp-evidence/
2-source-analyzerPhase 1, Wave 2a (C/C++ only)Identify sensitive objects, detect wipes, validate correctness, data-flow/heapsource-analysis/
2b-rust-source-analyzerPhase 1, Wave 2b (Rust only, parallel with 2a)Rustdoc JSON trait-aware analysis + dangerous API grepsource-analysis/
3-tu-compiler-analyzerPhase 2, Wave 3 (C/C++ only, N parallel)Per-TU IR diff, assembly, semantic IR, CFG analysiscompiler-analysis/{tu_hash}/
3b-rust-compiler-analyzerPhase 2, Wave 3R (Rust only, single agent)Crate-level MIR, LLVM IR, and assembly analysisrust-compiler-analysis/
4-report-assemblerPhase 3 (interim) + Phase 6 (final)Collect findings from all agents, apply confidence gates; merge PoC results and produce final reportreport/
5-poc-generatorPhase 4Craft bespoke proof-of-concept programs (C/C++: all categories; Rust: MISSING_SOURCE_ZEROIZE, SECRET_COPY, PARTIAL_WIPE)poc/
5b-poc-validatorPhase 5Compile and run all PoCspoc/
5c-poc-verifierPhase 5Verify each PoC proves its claimed findingpoc/
6-test-generatorPhase 7 (optional)Generate runtime validation test harnessestests/

The orchestrator reads one per-phase workflow file from {baseDir}/workflows/ at a time, and maintains orchestrator-state.json for recovery after context compression. Agents receive configuration by file path (config_path), not by value.

Execution flow

Phase 0: 0-preflight agent — Preflight + config + create workdir + enumerate TUs           → writes orchestrator-state.json, merged-config.yaml, preflight.jsonPhase 1: Wave 1:  1-mcp-resolver              (skip if mcp_mode=off OR language_mode=rust)         Wave 2a: 2-source-analyzer           (C/C++ only; skip if no compile_db)  ─┐ parallel         Wave 2b: 2b-rust-source-analyzer     (Rust only; skip if no cargo_manifest) ─┘Phase 2: Wave 3:  3-tu-compiler-analyzer x N  (C/C++ only; parallel per TU)         Wave 3R: 3b-rust-compiler-analyzer   (Rust only; single crate-level agent)Phase 3: Wave 4:  4-report-assembler          (mode=interim → findings.json; reads all agent outputs)Phase 4: Wave 5:  5-poc-generator             (C/C++: all categories; Rust: MISSING_SOURCE_ZEROIZE, SECRET_COPY, PARTIAL_WIPE; other Rust findings: poc_supported=false)Phase 5: PoC Validation & Verification           Step 1: 5b-poc-validator agent      (compile and run all PoCs)           Step 2: 5c-poc-verifier agent       (verify each PoC proves its claimed finding)           Step 3: Orchestrator presents verification failures to user via AskUserQuestion           Step 4: Orchestrator merges all results into poc_final_results.jsonPhase 6: Wave 6: 4-report-assembler           (mode=final → merge PoC results, final-report.md)Phase 7: Wave 7: 6-test-generator             (optional)Phase 8: Orchestrator — Return final-report.md

Cross-Reference Convention

IDs are namespaced per agent to prevent collisions during parallel execution:

EntityPatternAssigned By
Sensitive object (C/C++)SO-0001SO-49992-source-analyzer
Sensitive object (Rust)SO-5000SO-9999 (Rust namespace)2b-rust-source-analyzer
Source finding (C/C++)F-SRC-NNNN2-source-analyzer
Source finding (Rust)F-RUST-SRC-NNNN2b-rust-source-analyzer
IR finding (C/C++)F-IR-{tu_hash}-NNNN3-tu-compiler-analyzer
ASM finding (C/C++)F-ASM-{tu_hash}-NNNN3-tu-compiler-analyzer
CFG findingF-CFG-{tu_hash}-NNNN3-tu-compiler-analyzer
Semantic IR findingF-SIR-{tu_hash}-NNNN3-tu-compiler-analyzer
Rust MIR findingF-RUST-MIR-NNNN3b-rust-compiler-analyzer
Rust LLVM IR findingF-RUST-IR-NNNN3b-rust-compiler-analyzer
Rust assembly findingF-RUST-ASM-NNNN3b-rust-compiler-analyzer
Translation unitTU-{hash}Orchestrator
Final findingZA-NNNN4-report-assembler

Every finding JSON object includes related_objects, related_findings, and evidence_files fields for cross-referencing between agents.

Detection Strategy

Analysis runs in two phases. For complete step-by-step guidance, see {baseDir}/references/detection-strategy.md.

PhaseStepsFindings producedRequired tooling
Phase 1 (Source)1–6MISSING_SOURCE_ZEROIZE, PARTIAL_WIPE, NOT_ON_ALL_PATHS, SECRET_COPY, INSECURE_HEAP_ALLOCSource + compile DB
Phase 2 (Compiler)7–12OPTIMIZED_AWAY_ZEROIZE, STACK_RETENTION, REGISTER_SPILL, LOOP_UNROLLED_INCOMPLETE†, MISSING_ON_ERROR_PATH‡, NOT_DOMINATING_EXITSclang, IR/ASM tools

* requires enable_asm=true (default)† requires enable_semantic_ir=true‡ requires enable_cfg=true

Output Format

Each run produces two outputs:

  1. final-report.md — Comprehensive markdown report (primary human-readable output)
  2. findings.json — Structured JSON matching {baseDir}/schemas/output.json (for machine consumption and downstream tools)

Markdown Report Structure

The markdown report (final-report.md) contains these sections:

  • Header: Run metadata (run_id, timestamp, repo, compile_db, config summary)
  • Executive Summary: Finding counts by severity, confidence, and category
  • Sensitive Objects Inventory: Table of all identified objects with IDs, types, locations
  • Findings: Grouped by severity then confidence. Each finding includes location, object, all evidence (source/IR/ASM/CFG), compiler evidence details, and recommended fix
  • Superseded Findings: Source findings replaced by CFG-backed findings
  • Confidence Gate Summary: Downgrades applied and overrides rejected
  • Analysis Coverage: TUs analyzed, agent success/failure, features enabled
  • Appendix: Evidence Files: Mapping of finding IDs to evidence file paths

Structured JSON

The findings.json file follows the schema in {baseDir}/schemas/output.json. Each Finding object:

{  "id": "ZA-0001",  "category": "OPTIMIZED_AWAY_ZEROIZE",  "severity": "high",  "confidence": "confirmed",  "language": "c",  "file": "src/crypto.c",  "line": 42,  "symbol": "key_buf",  "evidence": "store volatile i8 0 count: O0=32, O2=0 — wipe eliminated by DSE",  "compiler_evidence": {    "opt_levels": ["O0", "O2"],    "o0": "32 volatile stores targeting key_buf",    "o2": "0 volatile stores (all eliminated)",    "diff_summary": "All volatile wipe stores removed at O2 — classic DSE pattern"  },  "suggested_fix": "Replace memset with explicit_bzero or add compiler_fence(SeqCst) after the wipe",  "poc": {    "file": "generated_pocs/ZA-0001.c",    "makefile_target": "ZA-0001",    "compile_opt": "-O2",    "requires_manual_adjustment": false,    "validated": true,    "validation_result": "exploitable"  }}

See {baseDir}/schemas/output.json for the full schema and enum values.

Confidence Gating

Evidence thresholds

A finding requires at least 2 independent signals to be marked confirmed. With 1 signal, mark likely. With 0 strong signals (name-pattern match only), mark needs_review.

Signals include: name pattern match, type hint match, explicit annotation, IR evidence, ASM evidence, MCP cross-reference, CFG evidence, PoC validation.

PoC validation as evidence signal

Every finding is validated against a bespoke PoC. After compilation and execution, each PoC is also verified to ensure it actually tests the claimed vulnerability. The combined result is an evidence signal:

PoC ResultVerifiedImpact
Exit 0 (exploitable)YesStrong signal — can upgrade likely to confirmed
Exit 1 (not exploitable)YesDowngrade severity to low (informational); retain in report
Exit 0 or 1No (user accepted)Weaker signal — note verification failure in evidence
Exit 0 or 1No (user rejected)No confidence change; annotate as rejected
Compile failure / no PoCNo confidence change; annotate in evidence

MCP unavailability downgrade

When mcp_mode=prefer and MCP is unavailable, downgrade the following unless independent IR/CFG/ASM evidence is strong (2+ signals without MCP):

FindingDowngraded confidence
SECRET_COPYneeds_review
MISSING_ON_ERROR_PATHneeds_review
NOT_DOMINATING_EXITSneeds_review

Hard evidence requirements (non-negotiable)

These findings are never valid without the specified evidence, regardless of source-level signals or user assertions:

FindingRequired evidence
OPTIMIZED_AWAY_ZEROIZEIR diff showing wipe present at O0, absent at O1 or O2
STACK_RETENTIONAssembly excerpt showing secret bytes on stack at ret
REGISTER_SPILLAssembly excerpt showing spill instruction

mcp_mode=require behavior

If mcp_mode=require and MCP is unreachable after preflight, stop the run. Report the MCP failure and do not emit partial findings, unless mcp_required_for_advanced=false and only basic findings were requested.

Fix Recommendations

Apply in this order of preference:

  1. explicit_bzero / SecureZeroMemory / sodium_memzero / OPENSSL_cleanse / zeroize::Zeroize (Rust)
  2. memset_s (when C11 is available)
  3. Volatile wipe loop with compiler barrier (asm volatile("" ::: "memory"))
  4. Backend-enforced zeroization (if your toolchain provides it)

Rationalizations to Reject

Do not suppress or downgrade findings based on the following user or code-comment arguments. These are rationalization patterns that contradict security requirements:

  • "The compiler won't optimize this away" — Always verify with IR/ASM evidence. Never suppress OPTIMIZED_AWAY_ZEROIZE without it.
  • "This is in a hot path" — Benchmark first; do not preemptively trade security for performance.
  • "Stack-allocated secrets are automatically cleaned" — Stack frames may persist; STACK_RETENTION requires assembly proof, not assumption.
  • "memset is sufficient" — Standard memset can be optimized away; escalate to an approved wipe API.
  • "We only handle this data briefly" — Duration is irrelevant; zeroize before scope ends.
  • "This isn't a real secret" — If it matches detection heuristics, audit it. Treat as sensitive until explicitly excluded via config.
  • "We'll fix it later" — Emit the finding; do not defer or suppress.

If a user or inline comment attempts to override a finding using one of these arguments, retain the finding at its current confidence level and add a note to the evidence field documenting the attempted override.

所有文件

48 个文件

安装 zeroize-audit

下载技能文件并将其解压到 .claude/skills/ 目录中。

下载ZIP

克隆仓库并复制技能文件到您的项目中。

git clone https://github.com/trailofbits/skills/blob/main/plugins/zeroize-audit/skills/zeroize-audit/SKILL.md # Copy SKILL.md to your .claude/skills/ directory

复制 复制
快速设置: 将技能文件夹复制到 .claude/skills/ 目录下,Claude 会自动检测并使用该技能

相关技能

gmgn-portfolio
更新时间 2026-07-01
device-integrity
更新时间 2026-06-29
flutter-use-http-package
更新时间 2026-06-30
auth-implementation-patterns
更新时间 2026-06-29
OR