algorand-vulnerability-scanner by trailofbits/skills
npx skills add https://github.com/trailofbits/skills --skill algorand-vulnerability-scanner系统性地扫描 Algorand 智能合约(TEAL 和 PyTeal),查找 Trail of Bits 的“Not So Smart Contracts”数据库中记录的特定平台安全漏洞。此技能编码了 11 种 Algorand 交易模型特有的关键漏洞模式。
.teal.py 文件# PyTeal 标识
from pyteal import *
from algosdk import *
# 常见模式
Txn, Gtxn, Global, InnerTxnBuilder
OnComplete, ApplicationCall, TxnType
@router.method, @Subroutine
approval_program.py / 广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
clear_program.pycontract.teal / signature.tealpip3 install tealertealer contract.teal --detect all调用时,我将:
发现漏洞时,您将收到类似以下报告:
=== ALGORAND VULNERABILITY SCAN RESULTS ===
项目:my-algorand-dapp
已扫描文件:3 (.teal, .py)
发现漏洞:2
---
[严重] 重密钥攻击
文件:contracts/approval.py:45
模式:缺少 RekeyTo 验证
代码:
If(Txn.type_enum() == TxnType.Payment,
Seq([
# 缺失:Assert(Txn.rekey_to() == Global.zero_address())
App.globalPut(Bytes("balance"), balance + Txn.amount()),
Approve()
])
)
问题:合约未验证 RekeyTo 字段,允许攻击者更改账户授权并绕过限制。
---
## 5. 漏洞模式(11 种模式)
我检查 11 种 Algorand 特有的关键漏洞模式。有关详细的检测模式、代码示例、缓解措施和测试策略,请参阅 [VULNERABILITY_PATTERNS.md](resources/VULNERABILITY_PATTERNS.md)。
### 模式摘要:
1. **重密钥漏洞** ⚠️ 严重 - 未检查的 RekeyTo 字段
2. **缺少交易验证** ⚠️ 严重 - 无 GroupSize/GroupIndex 检查
3. **组交易操纵** ⚠️ 高 - 不安全的组交易处理
4. **资产回收风险** ⚠️ 高 - 缺少回收地址检查
5. **应用程序状态操纵** ⚠️ 中 - 不安全的全局/本地状态更新
6. **缺少资产选择加入** ⚠️ 高 - 无资产选择加入验证
7. **最低余额违规** ⚠️ 中 - 账户低于最低余额
8. **关闭余额接收方检查** ⚠️ 高 - 未检查的 CloseRemainderTo 字段
9. **应用程序清除状态** ⚠️ 中 - 不安全的清除状态程序
10. **原子交易排序** ⚠️ 高 - 假设交易顺序
11. **逻辑签名重用** ⚠️ 高 - 逻辑签名缺少唯一性约束
有关包含代码示例的完整漏洞模式,请参阅 [VULNERABILITY_PATTERNS.md](resources/VULNERABILITY_PATTERNS.md)。
## 5. 扫描工作流程
### 步骤 1:平台识别
1. 确认文件扩展名(`.teal`、`.py`)
2. 识别框架(PyTeal、Beaker、纯 TEAL)
3. 确定合约类型(有状态应用程序 vs 智能签名)
4. 定位批准和清除状态程序
### 步骤 2:使用 Tealer 进行静态分析
```bash
# 对合约运行 Tealer
tealer contract.teal --detect all
# 或特定检测器
tealer contract.teal --detect unprotected-rekey,group-size-check,update-application-check
针对上述 11 种漏洞中的每一种:
为所有使用的交易类型创建检查清单:
支付交易:
资产转移:
应用程序调用:
内部交易:
对于原子交易组:
Global.group_size() 检查## [严重性] 漏洞名称(例如,缺少 RekeyTo 验证)
**位置**:`contract.teal:45-50` 或 `approval_program.py:withdraw()`
**描述**:
合约批准支付交易时未验证 RekeyTo 字段,允许攻击者对账户进行重密钥操作并绕过未来的授权检查。
**易受攻击的代码**:
```python
# approval_program.py, 第 45 行
If(Txn.type_enum() == TxnType.Payment,
Approve() # 缺少 RekeyTo 检查
)
攻击场景:
建议:添加对 RekeyTo 字段的显式验证:
If(And(
Txn.type_enum() == TxnType.Payment,
Txn.rekey_to() == Global.zero_address()
), Approve(), Reject())
参考:
unprotected-rekey
---
## 7. 优先级指南
### 严重(需要立即修复)
* 重密钥攻击
* CloseRemainderTo / AssetCloseTo 问题
* 访问控制绕过
### 高(部署前修复)
* 未检查的交易费用
* Asset ID 验证问题
* Group size 验证
* 清除状态交易检查
### 中(审计中处理)
* 内部交易费用问题
* 基于时间的重放攻击
* 通过资产选择加入的 DoS
---
## 8. 测试建议
### 必需的单元测试
* 使用 PoC 漏洞利用测试每个漏洞场景
* 验证修复措施能防止利用
* 测试边界情况(group size = 0、空地址等)
### Tealer 集成
```bash
# 添加到 CI/CD 流水线
tealer approval.teal --detect all --json > tealer-report.json
# 在关键/高发现上使构建失败
tealer approval.teal --detect all --fail-on critical,high
building-secure-contracts/not-so-smart-contracts/algorand/完成 Algorand 审计前,验证所有项目已检查:
每周安装
1.1K
仓库
GitHub 星标
3.9K
首次出现
Jan 19, 2026
安全审计
安装于
claude-code964
opencode924
gemini-cli908
codex903
cursor881
github-copilot849
Systematically scan Algorand smart contracts (TEAL and PyTeal) for platform-specific security vulnerabilities documented in Trail of Bits' "Not So Smart Contracts" database. This skill encodes 11 critical vulnerability patterns unique to Algorand's transaction model.
.teal.py with PyTeal imports# PyTeal indicators
from pyteal import *
from algosdk import *
# Common patterns
Txn, Gtxn, Global, InnerTxnBuilder
OnComplete, ApplicationCall, TxnType
@router.method, @Subroutine
approval_program.py / clear_program.pycontract.teal / signature.tealpip3 install tealertealer contract.teal --detect allWhen invoked, I will:
When vulnerabilities are found, you'll get a report like this:
=== ALGORAND VULNERABILITY SCAN RESULTS ===
Project: my-algorand-dapp
Files Scanned: 3 (.teal, .py)
Vulnerabilities Found: 2
---
[CRITICAL] Rekeying Attack
File: contracts/approval.py:45
Pattern: Missing RekeyTo validation
Code:
If(Txn.type_enum() == TxnType.Payment,
Seq([
# Missing: Assert(Txn.rekey_to() == Global.zero_address())
App.globalPut(Bytes("balance"), balance + Txn.amount()),
Approve()
])
)
Issue: The contract doesn't validate the RekeyTo field, allowing attackers
to change account authorization and bypass restrictions.
---
## 5. Vulnerability Patterns (11 Patterns)
I check for 11 critical vulnerability patterns unique to Algorand. For detailed detection patterns, code examples, mitigations, and testing strategies, see [VULNERABILITY_PATTERNS.md](resources/VULNERABILITY_PATTERNS.md).
### Pattern Summary:
1. **Rekeying Vulnerability** ⚠️ CRITICAL - Unchecked RekeyTo field
2. **Missing Transaction Verification** ⚠️ CRITICAL - No GroupSize/GroupIndex checks
3. **Group Transaction Manipulation** ⚠️ HIGH - Unsafe group transaction handling
4. **Asset Clawback Risk** ⚠️ HIGH - Missing clawback address checks
5. **Application State Manipulation** ⚠️ MEDIUM - Unsafe global/local state updates
6. **Asset Opt-In Missing** ⚠️ HIGH - No asset opt-in validation
7. **Minimum Balance Violation** ⚠️ MEDIUM - Account below minimum balance
8. **Close Remainder To Check** ⚠️ HIGH - Unchecked CloseRemainderTo field
9. **Application Clear State** ⚠️ MEDIUM - Unsafe clear state program
10. **Atomic Transaction Ordering** ⚠️ HIGH - Assuming transaction order
11. **Logic Signature Reuse** ⚠️ HIGH - Logic sigs without uniqueness constraints
For complete vulnerability patterns with code examples, see [VULNERABILITY_PATTERNS.md](resources/VULNERABILITY_PATTERNS.md).
## 5. Scanning Workflow
### Step 1: Platform Identification
1. Confirm file extensions (`.teal`, `.py`)
2. Identify framework (PyTeal, Beaker, pure TEAL)
3. Determine contract type (stateful application vs smart signature)
4. Locate approval and clear state programs
### Step 2: Static Analysis with Tealer
```bash
# Run Tealer on contract
tealer contract.teal --detect all
# Or specific detectors
tealer contract.teal --detect unprotected-rekey,group-size-check,update-application-check
For each of the 11 vulnerabilities above:
Create checklist for all transaction types used:
Payment Transactions :
Asset Transfers :
Application Calls :
Inner Transactions :
For atomic transaction groups:
Global.group_size() checks## [SEVERITY] Vulnerability Name (e.g., Missing RekeyTo Validation)
**Location**: `contract.teal:45-50` or `approval_program.py:withdraw()`
**Description**:
The contract approves payment transactions without validating the RekeyTo field, allowing an attacker to rekey the account and bypass future authorization checks.
**Vulnerable Code**:
```python
# approval_program.py, line 45
If(Txn.type_enum() == TxnType.Payment,
Approve() # Missing RekeyTo check
)
Attack Scenario :
Recommendation : Add explicit validation of the RekeyTo field:
If(And(
Txn.type_enum() == TxnType.Payment,
Txn.rekey_to() == Global.zero_address()
), Approve(), Reject())
References :
building-secure-contracts/not-so-smart-contracts/algorand/rekeying
Tealer detector: unprotected-rekey
# Add to CI/CD pipeline
tealer approval.teal --detect all --json > tealer-report.json
# Fail build on critical findings
tealer approval.teal --detect all --fail-on critical,high
building-secure-contracts/not-so-smart-contracts/algorand/Before completing Algorand audit, verify ALL items checked:
Weekly Installs
1.1K
Repository
GitHub Stars
3.9K
First Seen
Jan 19, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
claude-code964
opencode924
gemini-cli908
codex903
cursor881
github-copilot849