본문으로 건너뛰기
Skillpedia
보안6.5k · #13971

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가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/analyst/sql-injection/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

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.

repo: BitterSecurity/Decepticon

인기도

GitHub 스타
6.5k
순위
#13971
라이선스
Apache-2.0
업데이트
2026. 11. 1.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬