Sc sqli

From ersinkoc/security-check · View interactive version

Sc sqli is an AI agent skill from the GitHub repository ersinkoc/security-check. SQL Injection detection across all variants — classic, blind, time-based, second-order, and UNION-based

How to use this skill

Skill file

SC: SQL Injection

Purpose

Detects SQL injection vulnerabilities in all forms: classic (error-based), blind (boolean and time-based), UNION-based, second-order, and ORM bypass patterns. Traces user input from HTTP request parameters through application logic to database query construction, identifying points where unsanitized data enters SQL statements.

Activation

Called by sc-orchestrator during Phase 2 (Vulnerability Hunting). Runs against all detected languages.

Phase 1: Discovery

File Patterns to Search

**/*.go, **/*.ts, **/*.js, **/*.py, **/*.php, **/*.java, **/*.kt, **/*.cs,
**/*.rb, **/routes/*, **/controllers/*, **/models/*, **/repositories/*,
**/dal/*, **/dao/*, **/*query*, **/*sql*, **/*database*, **/*db*

Keyword Patterns to Search

# Direct SQL construction
"SELECT.*FROM"           # SQL SELECT statements
"INSERT INTO"            # SQL INSERT
"UPDATE.*SET"            # SQL UPDATE
"DELETE FROM"            # SQL DELETE
"EXEC ", "EXECUTE "      # Stored procedure execution

# String concatenation in queries
"+ .*query"              # String concat with query variable
`${.*}`.*SELECT          # Template literals in SQL
f"SELECT, f"INSERT       # Python f-strings in SQL
"WHERE.*=.*'" + "        # String concat in WHERE clause
".format(.*)".*SELECT    # str.format() in SQL

# Language-specific database calls
"db.Query(", "db.Exec("              # Go database/sql
"sequelize.query(", ".rawQuery("     # Node.js Sequelize
"cursor.execute(", "connection.execute("  # Python DB-API
"$wpdb->query(", "->whereRaw("      # PHP WordPress/Laravel
"createNativeQuery(", "createQuery(" # Java JPA
"FromSqlRaw(", "ExecuteSqlRaw("      # C# Entity Framework

Semantic Patterns

  1. String concatenation — any variable concatenated into a string that is later passed to a database query function
  2. Template literal interpolation — variables embedded in SQL via template literals or f-strings
  3. ORM raw query methods — framework ORM methods that accept raw SQL strings
  4. Stored procedure calls — dynamic stored procedure name or parameter construction
  5. Query builder misuse — using .where() with raw strings instead of parameterized objects

Data Flow Tracing (Source → Sink)

Sources (user input):

Sinks (database queries):

Phase 2: Verification

For each candidate finding:

Exploitability Checklist

  1. Can user-controlled input reach the SQL query without modification?
  2. Is the input inserted into the SQL structure (not just values)?
  3. Can the attacker control the position of quotes, operators, or keywords?
  4. Is there a way to observe the result (error messages, data differences, timing)?

Sanitization Check

  1. Is input passed through a parameterized query / prepared statement?
  2. Is input cast to a specific type (integer, UUID) before use?
  3. Is input validated against an allowlist of expected values?
  4. Is input escaped using a database-specific escape function?

Framework Protection Check

Context-Aware False Positive Elimination

  1. Is the "query" actually a search query against a search engine (Elasticsearch), not SQL?
  2. Is the variable a constant/enum, not user input?
  3. Is the concatenation building a query that uses parameterized placeholders?
  4. Is the code in a migration file, seed file, or schema definition (not runtime)?

Severity Classification

Language-Specific Notes

Go

// VULNERABLE: String concatenation in query
query := "SELECT * FROM users WHERE id = " + r.URL.Query().Get("id")
rows, err := db.Query(query)

// SAFE: Parameterized query
rows, err := db.Query("SELECT * FROM users WHERE id = $1", r.URL.Query().Get("id"))

TypeScript/JavaScript

// VULNERABLE: Template literal in raw query
const users = await prisma.$queryRawUnsafe(`SELECT * FROM users WHERE name = '${req.query.name}'`)

// SAFE: Tagged template (Prisma parameterizes these)
const users = await prisma.$queryRaw`SELECT * FROM users WHERE name = ${req.query.name}`

Python

# VULNERABLE: f-string in SQL
cursor.execute(f"SELECT * FROM users WHERE id = {request.GET['id']}")

# SAFE: Parameterized query
cursor.execute("SELECT * FROM users WHERE id = %s", [request.GET['id']])

PHP

// VULNERABLE: Direct interpolation
$result = $pdo->query("SELECT * FROM users WHERE id = " . $_GET['id']);

// SAFE: Prepared statement
$stmt = $pdo->prepare("SELECT * FROM users WHERE id = ?");
$stmt->execute([$_GET['id']]);

Java

// VULNERABLE: String concatenation in JDBC
String query = "SELECT * FROM users WHERE id = " + request.getParameter("id");
ResultSet rs = stmt.executeQuery(query);

// SAFE: Prepared statement
PreparedStatement ps = conn.prepareStatement("SELECT * FROM users WHERE id = ?");
ps.setString(1, request.getParameter("id"));
ResultSet rs = ps.executeQuery();

C#

// VULNERABLE: String interpolation in raw SQL
var users = context.Users.FromSqlRaw($"SELECT * FROM Users WHERE Id = {id}").ToList();

// SAFE: Parameterized
var users = context.Users.FromSqlRaw("SELECT * FROM Users WHERE Id = {0}", id).ToList();

Output Format

Finding: SQLI-{NNN}

Common False Positives

  1. ORM standard methods — .filter(), .findOne(), LINQ queries are parameterized by default
  2. Prisma tagged templates — prisma.$queryRaw\...\` auto-parameterizes (but $queryRawUnsafe` does not)
  3. Search engine queries — Elasticsearch DSL, MongoDB queries are not SQL
  4. Schema/migration files — DDL statements in migration files are not user-input-driven
  5. Constants in queries — "SELECT * FROM users WHERE role = 'admin'" with no variable input
  6. Query builders with safe API — knex('users').where('id', input) parameterizes automatically
  7. Type-safe inputs — When input is guaranteed to be an integer via type casting before reaching query
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.