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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

The “ORA” string at the beginning is the giveaway: It is an Oracle installation! A complete<br />

repository of all Oracle error messages is available at www.ora-code.com.<br />

Banner Grabbing<br />

Error messages can allow you to obtain a fairly precise idea of the technology the Web<br />

application uses to store its data. However, this is not enough, <strong>and</strong> you can go beyond that.<br />

In the first example, for instance, we discovered that the remote database is <strong>SQL</strong> Server,<br />

but there are various versions of this product; at the time of this writing, the most widespread<br />

version is <strong>SQL</strong> Server 2005, but there are still many <strong>SQL</strong> Server 2000 installations in use,<br />

<strong>and</strong> <strong>SQL</strong> Server 2008 was released in August 2008 but it is still at the early stages of deployment.<br />

Being able to discover a few more details, such as the exact version <strong>and</strong> patch level,<br />

would allow you to quickly underst<strong>and</strong> whether the remote database has some well-known<br />

flaw that you can exploit.<br />

Luckily, if the Web application returns the results of the injected queries, figuring out the<br />

exact technology is usually straightforward. All major database technologies allow at least one<br />

specific query that returns the software version, <strong>and</strong> all you need is to make the Web application<br />

return the result of that query. Table 4.1 provides some examples of queries that will return, for<br />

a given technology, a string containing the exact DBMS version.<br />

Table 4.1 Returning the DBMS Version<br />

Database Server<br />

Microsoft <strong>SQL</strong> Server<br />

My<strong>SQL</strong><br />

Oracle<br />

Query<br />

SELECT @@version<br />

SELECT version()<br />

SELECT @@version<br />

SELECT banner FROM v$version<br />

SELECT banner FROM v$version WHERE rownum=1<br />

For instance, on <strong>SQL</strong> Server 2000 SP4, by issuing the query SELECT @@version<br />

you will obtain the following:<br />

Microsoft <strong>SQL</strong> Server 2000 – 8.00.194 (Intel X86)<br />

Aug 6 2000 00:57:48<br />

Copyright (c) 1988–2000 Microsoft Corporation<br />

St<strong>and</strong>ard Edition on Windows NT 5.0 (Build 2195: Service Pack 4)

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

Saved successfully!

Ooh no, something went wrong!