Communitygithub.com

Foundryスマートコントラクトセキュリティ監査

Foundryプロジェクトに対して、静的解析、シンボリック実行、プロパティベーステスト、手動レビューを組み合わせた多層防御型のプリデプロイ監査を実行します。

Foundryスマートコントラクトセキュリティ監査 とは?

このスキルは、Foundryプロジェクト向けの事前デプロイ監査を自動化するためのものです。Slither(90以上の検出器)とAderyn(Cyfrin)による静的解析、Mythrilによるオプションのシンボリック実行、Forgeのファジングと不変条件テストを含むプロパティベーステスト、そして手動レビューチェックリストと秘密鍵の衛生管理を組み合わせます。Foundry、Slither、Aderyn、Mythril、gitleaksを前提とし、脆弱性チェックリストと安全なデプロイ手順のリファレンスが同梱されています。主なユースケースは、価値を扱うコントラクト(ERC-20/721/1155、ボールト、ステーキング、AMM、ブリッジ、ガバナンス)のデプロイ前であり、高/重大な静的検出、テスト失敗、漏洩した鍵、低カバレッジがあるとFAILとなります。監査結果はJSONレポートとして出力され、各発見事項にはSWC ID、重大度、影響を受けるコントラクト/関数/行、および推奨される修正措置が含まれます。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/mukul975/Anthropic-Cybersecurity-Skills/tree/main/skills/auditing-foundry-smart-contract-security

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Foundryスマートコントラクトセキュリティ監査 は何をしますか?

概要

デプロイされたスマートコントラクトは不変であり、実際の資金を管理するため、メインネットに送信されたバグは修正できず、悪用されるだけです。壊滅的なDeFiの損失のほとんどは、リエントランシー、アクセス制御の破損、オラクル/価格操作、未チェックの算術演算や外部呼び出しといった、少数の繰り返し発生するクラスに起因します。

このスキルは、Foundryプロジェクトに対して多層防御のプリデプロイ監査を実行し、互いに見逃すものを補完し合う4つの独立した手法を階層化します。

  1. 静的解析 — slither(90以上の検出器)とaderyn(Cyfrin、Rust)がAST/IRを数秒でスキャンし、既知のアンチパターンを検出します。
  2. シンボリック実行 — mythril(オプション、低速)が実行パスを探索し、SMTソルバーで深い算術/リエントランシーバグを解決します。
  3. プロパティベーステスト — ファジング(testFuzz_*)と不変条件テスト(invariant_* + ゴースト変数を持つハンドラーコントラクト)を使用したforge testで、プロトコルレベルのプロパティが数百万のランダムシーケンスにわたって成立することを証明します。
  4. 手動レビュー + キー衛生 — 構造化チェックリスト(references/vulnerability-checklist.mdを参照)とシークレット/キーストア監査により、秘密鍵が平文で存在することはなく、デプロイは暗号化されたcastキーストアを介して行われます(references/secure-deployment-and-keys.mdを参照)。

このスキルは開発者側、デプロイ前に使用されます。インシデント後のSOCではなく、コントラクトを構築するエンジニアが実行します。発見事項がデプロイをゲートします。高/重大な静的検出、テスト失敗、漏洩した鍵、または低カバレッジがあると、FAILとなります。

使用すべきタイミング

  • 任意のSolidityコントラクトをテストネットまたはメインネットEVMチェーンにデプロイする前。
  • Foundryプロジェクト(foundry.toml、src/、test/、script/)を作成またはレビューするとき。
  • コントラクトが価値を扱う場合:トークン(ERC-20/721/1155)、ボールト、ステーキング、AMM、ブリッジ、ガバナンス。
  • ファズテストや不変条件テストを追加する場合、または価値移動関数のカバレッジが不明な場合。
  • デプロイスクリプトを作成するとき — 鍵が暗号化されたキーストアにあり、.envのプレーンテキストではないことを確認するため。
  • 価格オラクル、外部呼び出し、delegatecall、またはアップグレード可能なプロキシを統合するとき。
  • Slither/Aderynのレポートをトリアージし、実際のバグと誤検知を区別する必要があるとき。

前提条件

  • Foundryがインストールされていること(forge、cast、anvil):curl -L https://foundry.paradigm.xyz | bash && foundryup
  • Slither + solc:pip install slither-analyzer および solc-select install <ver> && solc-select use <ver>
  • Aderyn(推奨):cargo install aderyn(または npm i -g @cyfrin/aderyn)
  • Mythril(オプション、低速なシンボリック実行):pip install mythril
  • gitleaks(キー漏洩スキャン):付属の implementing-secret-scanning-with-gitleaks スキルを参照
  • コンパイルが通るFoundryプロジェクト(forge buildが成功)— アナライザにはビルドアーティファクトが必要です。
  • Solidity ^0.8.xを想定(組み込みのオーバーフローチェック付き);0.8より前のコントラクトは追加のSafeMathレビューが必要です。

Pythonツールは仮想環境(virtualenv)にインストールすることを推奨します(外部管理ディストリビューションの場合)。資金がロック解除されたウォレットが存在するマシンで、信頼できないコントラクトソースに対して解析を実行しないでください。

手順

ステップ1:プロジェクトのビルドと健全性チェック

forge build                    # アナライザは最新のアーティファクトを必要とします
forge fmt --check              # スタイルゲート(オプション)
cat foundry.toml               # solcバージョン、オプティマイザー、リマッピング、evm_versionを確認

ステップ2:静的解析(高速、毎回実行)

# Slither — プロジェクト全体(foundry.toml + remappingsを自動的に使用)
slither . --json slither-report.json

# Aderyn — Cyfrin Rustアナライザ、補完的な検出器
aderyn . -o aderyn-report.json

または、両方を実行し、重複を排除し、結果をゲートするバンドルされたオーケストレーターを実行します:

python3 scripts/agent.py --project . --output audit-report.json

ステップ3:クリティカルなコントラクトのシンボリック実行(オプション、低速)

# 最も価値の高いコントラクトのみ — Mythrilはパス爆発を起こします
myth analyze src/Vault.sol --solc-json mythril.config.json --execution-timeout 300 -o json
# または:python3 scripts/agent.py --project . --mythril src/Vault.sol

ステップ4:プロパティベーステスト — ファズ + 不変条件

forge test -vvv                                  # ユニット + ファズテスト
forge coverage --report summary                  # 価値移動コードのカバレッジ
forge test --match-test invariant_ -vvv          # 不変条件スイート(ハンドラーベース)

価値を扱うすべてのコントラクトには、ハンドラーを使った不変条件テスト(制限付き入力、ゴースト変数、targetContract(handler))が必要です。単なるユニットテストではありません。ハンドラーパターンについては references/api-reference.md を参照し、各アクセス制御ガードに対して test_RevertWhen_*(vm.expectRevert付き)を作成してください。

ステップ5:チェックリストに基づく手動レビュー

すべてのコントラクトについて references/vulnerability-checklist.md を確認してください:リエントランシー(checks-effects-interactions / nonReentrant)、アクセス制御、オラクル操作、delegatecall/プロキシストレージレイアウト、未チェックの戻り値、tx.origin、弱いランダム性、DoS、フロントランニング/MEV、およびERC固有の落とし穴(approve race、fee-on-transfer、rebasing)。

ステップ6:キー衛生と安全なデプロイ

gitleaks detect --no-banner            # 秘密鍵/ニーモニック/.envがコミットされていないこと
git ls-files | grep -E '\.env$|keystore' && echo "WARN: secrets tracked by git"

# デプロイキーを暗号化されたキーストアに一度だけインポート — 平文のPRIVATE_KEY環境変数は使用しない
cast wallet import deployer --interactive

# キーストアアカウントを使用してデプロイ(最初にテストネット)、--broadcastの前にシミュレーション
forge script script/Deploy.s.sol --account deployer --rpc-url <testnet> --broadcast --verify

完全な強化ルール(MetaMask衛生、メインネット用ハードウェアウォレット、RPC信頼、デプロイ後検証)については references/secure-deployment-and-keys.md を参照してください。

ステップ7:トリアージとレポート

Slither + Aderyn + Mythril + テスト結果を結合し、(ファイル、行)で重複を排除し、確認された誤検知を削除し、悪用可能性×財務影響でランク付けし、各発見事項をSWC IDにマッピングします。オーケストレーターはPASS/FAILゲートを含む audit-report.json を出力します。

期待される出力

発見事項にSWC識別子、重大度、ツールソース、影響を受けるコントラクト/関数/行、および推奨される修正措置を含むJSON監査レポート。さらに、テスト/カバレッジの要約と単一のPASS / FAILデプロイゲート。高/重大な静的検出、テスト失敗、漏洩したシークレット、または価値移動コードの設定されたしきい値を下回るカバレッジがある場合はFAILとなります。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

abusing-dpapi-for-credential-access

Extract and decrypt Windows DPAPI-protected secrets (Credential Manager, browser logins/cookies, Wi-Fi credentials, KeePass keys) online or offline using SharpDPAPI, SharpChrome, Mimikatz, or Impacket

abusing-shadow-credentials-for-privesc

Take over Active Directory accounts by writing attacker-controlled public keys to msDS-KeyCredentialLink (Shadow Credentials) with pyWhisker, Whisker, or Certipy, then authenticate via PKINIT to recover the target

achieving-cmmc-level-2-compliance

>-

acquiring-disk-image-with-dd-and-dcfldd

Create forensically sound bit-for-bit disk images with dd or dcfldd on a Linux forensic workstation, preserving evidence integrity through hash verification (MD5/SHA) during acquisition. Use when imaging a suspect drive, USB device, or memory card for investigation, preserving volatile disk evidence during incident response, or producing a verified copy for legal or law-enforcement proceedings before any destructive analysis.

analyzing-active-directory-acl-abuse

Detect dangerous ACL misconfigurations in Active Directory using ldap3

analyzing-android-malware-with-apktool

Perform static analysis of Android APK malware using apktool for resource decompilation, jadx for Java source recovery, and androguard for manifest inspection, dangerous permission-combination detection, and identification of obfuscated code, dynamic code loading, and reflection-based API calls. Use to statically triage a suspicious APK without executing it or to build mobile malware detection rules.

analyzing-api-gateway-access-logs

Parses API Gateway access logs (AWS API Gateway, Kong, Nginx) to detect

analyzing-apt-group-with-mitre-navigator

Query ATT&CK data with attackcti, mitreattack-python, and stix2, then build MITRE ATT&CK Navigator layers and multi-layer heatmap overlays mapping one or more APT groups

analyzing-azure-activity-logs-for-threats

Queries Azure Monitor activity logs and sign-in logs via azure-monitor-query

analyzing-bootkit-and-rootkit-samples

Analyzes bootkit and advanced rootkit malware infecting the Master

analyzing-browser-forensics-with-hindsight

Parse Chromium-based browser databases with Hindsight to extract and correlate browsing history, downloads, cookies, cached content, autofill data, saved passwords, and extensions from Chrome, Edge, Brave, Opera, and Vivaldi into a unified timeline (XLSX, JSON, or SQLite output). Use during incident response, insider-threat investigations, or criminal cases when you need to reconstruct a user

analyzing-campaign-attribution-evidence

Systematically evaluate cyber-campaign evidence to attribute an operation to a threat actor, using the Diamond Model and Analysis of Competing Hypotheses (ACH) to weigh infrastructure overlaps, TTP consistency, malware code similarity, and timing/language artifacts into confidence-weighted attribution assessments. Use when an incident investigation needs a defensible attribution confidence level.

analyzing-certificate-transparency-for-phishing

Monitor Certificate Transparency logs using crt.sh and Certstream to

analyzing-cloud-storage-access-patterns

Detect abnormal access in AWS S3, GCS, and Azure Blob Storage by analyzing CloudTrail Data Events, GCS audit logs, and Azure Storage Analytics for after-hours bulk downloads, new-IP access, and API-call spikes (e.g. GetObject) via statistical baselines and time-series anomaly detection. Use when investigating suspected cloud data exfiltration or building related detection rules.

analyzing-cobalt-strike-beacon-configuration

Extract and analyze Cobalt Strike beacon configuration from PE files

analyzing-cobaltstrike-malleable-c2-profiles

Parse and analyze Cobalt Strike Malleable C2 profiles with dissect.cobaltstrike (profiles and beacon-payload configs) and pyMalleableC2 (AST parsing) to extract HTTP/DNS transforms, URIs, headers, sleep/jitter, and injection behavior, then generate network detection signatures. Use when reverse-engineering a captured malleable profile or building detections against Cobalt Strike Beacon traffic.

analyzing-command-and-control-communication

Analyzes malware C2 communication over HTTP, HTTPS, DNS, and custom

analyzing-cyber-kill-chain

Analyzes intrusion activity against the Lockheed Martin Cyber Kill Chain

analyzing-disk-image-with-autopsy

Perform comprehensive forensic analysis of raw (dd), E01, or AFF disk images with Autopsy and The Sleuth Kit, recovering deleted files, examining metadata and embedded artifacts, keyword searching, and building investigation timelines with visual reports. Use for structured analysis of a forensic disk image or when stakeholders need visual reports from evidence.

analyzing-dns-logs-for-exfiltration

Analyzes DNS query logs to detect data exfiltration via DNS tunneling,

関連スキル