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.

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

Table 4.2 Inferring the DBMS Version from Strings<br />

Database Server<br />

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

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

Oracle<br />

Query<br />

SELECT 'some' + 'string'<br />

SELECT 'some' 'string'<br />

SELECT CONCAT('some','string')<br />

SELECT 'some' || 'string'<br />

SELECT CONCAT('some','string')<br />

Therefore, if you have an injectable string parameter, you can try the different concatenation<br />

syntaxes. Depending on which one of them returns the same result as the original<br />

request, you can infer the remote database technology.<br />

In case you don’t have a vulnerable string parameter available, you can perform a similar<br />

technique for numeric parameters. More specifically, you need an <strong>SQL</strong> statement that, on a<br />

specific technology, evaluates to a number. All of the expressions in Table 4.3 will evaluate to<br />

an integer number on the correct database <strong>and</strong> will generate an error on all others.<br />

Table 4.3 Inferring the DBMS Version from Numeric Functions<br />

Database Server<br />

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

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

Oracle<br />

Query<br />

@@pack_received<br />

@@rowcount<br />

connection_id()<br />

last_insert_id()<br />

row_count()<br />

BITAND(1,1)<br />

Finally, simply using some specific <strong>SQL</strong> construct that is peculiar to a particular dialect is<br />

another effective technique that works very well in most situations. For instance, successfully<br />

injecting a WAITFOR DELAY is a clear sign that Microsoft <strong>SQL</strong> Server is used on the<br />

other side.<br />

If you are dealing with My<strong>SQL</strong>, there is a very interesting trick that allows you to<br />

determine its exact version. We know that comments on My<strong>SQL</strong> can be included in three<br />

different ways:

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

Saved successfully!

Ooh no, something went wrong!