access-control
Skill này làm gì
Playbook này hướng dẫn rà soát ai có thể thay đổi các cài đặt quan trọng hoặc chuyển tiền trong hợp đồng thông minh. Playbook dành cho kiểm toán viên và lập trình viên muốn xác minh các kiểm tra quyền.
Khi nào nên dùng
- ✓Khi một hợp đồng Solidity có các hàm thay đổi quyền sở hữu, cài đặt hoặc tiền.
- ✓Khi bạn muốn kiểm tra xem các kiểm tra vai trò hoặc chủ sở hữu có đúng không.
- ✓Khi một đội muốn tìm các hàm công khai nhưng lẽ ra phải bị hạn chế.
Liên kết skill
https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/contracts/access-control/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Bạn có thể kiểm tra xem các hàm quản trị của hợp đồng chúng tôi có thiếu kiểm tra chủ sở hữu đúng cách không?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent tìm mọi hàm thay đổi trạng thái, kiểm tra modifier phân quyền nào áp dụng, rồi đánh dấu những hàm thiếu hoặc sai kiểm tra.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Access Control Playbook
Access control bugs are the most boring class — and the most common in production audits. They're cheap to find with grep + LSP. They drain millions when missed (LeetSwap, Audius, Saddle, Akropolis).
Audit steps
1. Find every state-changing function
# Functions that are NOT view/pure and NOT internal/private
grep -rE 'function [a-zA-Z_]+\(.*\)(public|external)' src/ | grep -v 'view\|pure'
# Or via slither
slither . --print function-summary
2. For each external/public state-changer, ask
- Does it modify storage that affects user funds, ownership, or configuration?
- Is there a modifier (
onlyOwner,onlyRole,onlyDAO, custom auth)? - If yes, what's the modifier checking?
- If no, should there be one?
3. Audit each modifier
Common modifier patterns + bugs:
| Pattern | Bug |
|---|---|
require(msg.sender == owner) |
owner settable by anyone? setOwner unprotected? |
require(msg.sender == tx.origin) |
Wrong — tx.origin breaks meta-transactions, AND it's phishable |
_msgSender() in OZ ERC2771Context |
Forwarder trusted but anyone can forward — does the contract validate the forwarder? |
onlyRole(MINTER) |
Who can grant MINTER? Is the admin a multisig or single key? |
require(initialized == false) |
Initializer can be called twice if initialized writeable elsewhere |
require(block.timestamp > deployTime + 24 hours) |
Time-based is often a fake delay — check if deployTime is settable |
require(approvedSigners[msg.sender]) |
Approval list managed by single key? |
4. Specific anti-patterns to grep
# Functions accidentally external (default in Solidity <0.5)
grep -rn 'function [a-zA-Z_]*[^ ]* *{' src/ | grep -v 'internal\|private\|public\|external'
# msg.sender == tx.origin (phishable)
grep -rn 'tx.origin' src/
# Reentrancy in access-control checks
grep -rn 'onlyOwner.*nonReentrant' src/ # both? often wrong order
# `delegatecall` without auth gate
grep -rn 'delegatecall' src/
# `selfdestruct` available
grep -rn 'selfdestruct\|suicide(' src/
5. Initializer bugs
// VULNERABLE
function initialize(address _owner) external {
owner = _owner;
// missing: require(!initialized); initialized = true;
}
// VULNERABLE (proxy implementation)
contract Impl {
constructor() { ... } // NEVER RUNS in proxy context
// initialize() should set proxy state but doesn't gate
}
// SAFE
function initialize(address _owner) external initializer {
// OZ's initializer modifier enforces single-call
__Ownable_init(_owner);
}
For UUPS/Transparent proxies: check _authorizeUpgrade is overridden
and gated. Default OZ override is empty (revert).
6. Function-selector collisions (proxies)
Transparent proxy admin function selectors collide w/ impl function selectors → admin functions become uncallable, OR impl functions are shadowed by admin. Check w/ slither:
slither-check-erc src/Impl.sol --erc ERC1967
7. Role grant/revoke
For AccessControl:
DEFAULT_ADMIN_ROLEis the admin of all roles by default- Anyone with DEFAULT_ADMIN_ROLE can grant any role to anyone
- If init code grants DEFAULT_ADMIN_ROLE to deployer w/ no transfer to multisig → key person risk
Check role hierarchy:
grep -rn '_setRoleAdmin\|_setupRole\|grantRole' src/
PoC template (Foundry)
function test_unauth_call() public {
address attacker = address(0xBEEF);
vm.prank(attacker);
// Call the function that should require auth
target.dangerousFunction(arg1, arg2);
// Assert state change happened
assertEq(target.criticalParam(), expectedManipulatedValue);
// No revert = vulnerable
}
function test_role_takeover() public {
address attacker = address(0xBEEF);
vm.startPrank(attacker);
// If grantRole is callable by anyone
target.grantRole(target.MINTER_ROLE(), attacker);
assertTrue(target.hasRole(target.MINTER_ROLE(), attacker));
// Now exploit MINTER_ROLE
target.mint(attacker, 1_000_000 ether);
}
function test_init_re_entry() public {
// Call initialize twice
target.initialize(address(this));
vm.expectRevert("Initializable: contract is already initialized");
target.initialize(attacker);
}
function test_upgrade_no_auth() public {
address attacker = address(0xBEEF);
address malicious = address(new MaliciousImpl());
vm.prank(attacker);
target.upgradeTo(malicious);
// Now any call goes to
Câu hỏi thường gặp
Vì sao lớp lỗi này phổ biến?
Playbook gọi đây là lớp phổ biến nhất trong các đợt kiểm toán sản xuất, và nó dễ tìm bằng các tìm kiếm đơn giản.
Mẫu sai phổ biến là gì?
Dùng tx.origin để phân quyền, và playbook nói đây là sai và có thể bị khai thác qua lừa đảo.
Agent kiểm tra gì về vai trò?
Ai có thể cấp vai trò, và admin là multisig hay một khóa đơn.
Chi tiết
Mô tả gốc của tác giả
Missing modifiers, wrong msg.sender checks, default-public functions, missing onlyOwner / onlyRole / onlyDAO authorization.
Độ phổ biến
- Sao GitHub
- 6.5k
- Vị trí xếp hạng
- #14005
- Giấy phép
- Apache-2.0
- Cập nhật
- 1/11/2026
Bình luận
- …
Thêm skill từ kho mã này
detector-overview
6.5kGiúp agent của bạn đọc code mà một công cụ quét đã đánh dấu, rồi quyết định điểm nào là lỗ hổng bảo mật thật và điểm nào là báo động giả.
exploiter-overview
6.5kGiúp agent của bạn ghép nhiều lỗ hổng bảo mật đã xác nhận thành một chuỗi kiểm thử và kiểm tra chuỗi đó có thể gây hậu quả đến đâu.
llm-redteam-overview
6.5kGiúp agent của bạn tìm đúng hướng dẫn red-team AI cho một bài kiểm thử, bao quát 15 nhóm chiến thuật từ prompt injection đến lạm dụng mô hình.
aatmf-t01-prompt-injection
6.5kGiải thích prompt injection, khi các chỉ dẫn ẩn cố ghi đè một hệ thống AI, để chuyên gia bảo mật có thể kiểm tra lỗi này.
Skill tương tự
reverse-engineer-anything
422kGiúp agent của bạn xem bên trong các app và package đã phát hành để giải thích tính năng, so sánh phiên bản hoặc hướng dẫn dựng lại bằng công cụ REA.
1password
394kGiúp agent của bạn cài đặt CLI của 1Password, đăng nhập, và đọc hoặc đưa thông tin bí mật vào mà không in giá trị ra cuộc trò chuyện.
healthcheck
394kGiúp agent của bạn rà soát bảo mật máy tính hoặc máy chủ đang chạy OpenClaw, như SSH, tường lửa, cập nhật và sao lưu, rồi đề xuất cách sửa an toàn.