PortSwigger SQL Injection CheatSheet
Payloads from Portswigger SQL Injection Cheat Sheet. ( I did not write any of these)
SQL Injection Cheat Sheet
This cheat sheet contains examples of useful syntax for performing various tasks during SQL injection attacks.
String Concatenation
You can concatenate multiple strings to make a single string.
Oracle:
sqlCopy code'foo'||'bar'Microsoft:
sqlCopy code'foo'+'bar'PostgreSQL:
sqlCopy code'foo'||'bar'MySQL:
sqlCopy code'foo' 'bar' -- Note the space between the two strings CONCAT('foo','bar')
Substring
Extract part of a string from a specified offset with a specified length. The offset index is 1-based. Each example returns the string "ba".
Oracle:
sqlCopy codeSUBSTR('foobar', 4, 2)Microsoft:
sqlCopy codeSUBSTRING('foobar', 4, 2)PostgreSQL:
sqlCopy codeSUBSTRING('foobar', 4, 2)MySQL:
sqlCopy codeSUBSTRING('foobar', 4, 2)
Comments
Use comments to truncate a query and remove the portion of the original query that follows your input.
Oracle:
Microsoft:
PostgreSQL:
MySQL:
Database Version
Query the database to determine its type and version. This information is useful for formulating more complicated attacks.
Oracle:
Microsoft:
PostgreSQL:
MySQL:
Database Contents
List the tables that exist in the database, and the columns that those tables contain.
Oracle:
Microsoft:
PostgreSQL:
MySQL:
Conditional Errors
Test a single boolean condition and trigger a database error if the condition is true.
Oracle:
Microsoft:
PostgreSQL:
MySQL:
Extracting Data via Visible Error Messages
Elicit error messages that leak sensitive data returned by your malicious query.
Microsoft:
PostgreSQL:
MySQL:
Batched (or Stacked) Queries
Execute multiple queries in succession. Note that subsequent queries' results are not returned to the application.
Oracle:
Microsoft:
PostgreSQL:
MySQL:
Time Delays
Cause a time delay in the database when the query is processed.
Oracle:
Microsoft:
PostgreSQL:
MySQL:
Conditional Time Delays
Test a single boolean condition and trigger a time delay if the condition is true.
Oracle:
Microsoft:
PostgreSQL:
MySQL:
DNS Lookup
Cause the database to perform a DNS lookup to an external domain. Use Burp Collaborator to generate a unique subdomain and confirm the DNS lookup.
Oracle:
Microsoft:
PostgreSQL:
MySQL:
DNS Lookup with Data Exfiltration
Perform a DNS lookup to an external domain containing the results of an injected query. Use Burp Collaborator to retrieve details of any DNS interactions.
Oracle:
Microsoft:
PostgreSQL:
MySQL:
Use these examples as a reference for common SQL injection techniques and payloads. Remember to use these techniques ethically and legally, only testing systems you have explicit permission to test.
Source
Last updated
