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.

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

Such a URL will probably be used in a query that will look something like the<br />

following:<br />

SELECT name,phone,email FROM people WHERE name LIKE '%smith%'<br />

The resultant page will contain a message similar to this:<br />

100 results founds for smith<br />

To retrieve the database version, you can inject on the name parameter as follows:<br />

http://www.victim.com/searchpeople.asp?name='%2B@@version%2B'<br />

The resultant query will therefore become:<br />

SELECT name,phone,email FROM people WHERE name LIKE '%'+@@version+'%'<br />

This query will look for names that contain the string stored in @@version, which will<br />

probably be zero; however, the resultant page will have all the information you are looking for:<br />

0 results found for Microsoft <strong>SQL</strong> Server 2000 – 8.00.194 (Intel X86) Aug 6<br />

2000 00:57:48 Copyright (c) 1988–2000 Microsoft Corporation St<strong>and</strong>ard Edition<br />

on Windows NT 5.0 (Build 2195: Service Pack 4)<br />

You can repeat these techniques for other pieces of information that can be useful for<br />

obtaining a more accurate fingerprint. Here are some of the most useful Microsoft <strong>SQL</strong><br />

Server built-in variables:<br />

■ ■ @@version DBMS version<br />

■ ■ @@servername Name of the server where <strong>SQL</strong> Server is installed<br />

■ ■ @@language Name of the language that is currently used<br />

■ ■ @@spid Process ID of the current user<br />

Blind Fingerprint<br />

If the application does not return the desired information directly in the response, you need<br />

an indirect approach in order to underst<strong>and</strong> the technology that is used in the back end.<br />

Such an indirect approach is based on the subtle differences in the <strong>SQL</strong> dialects the different<br />

DBMSs use. The most common technique leverages the differences in how the various<br />

products concatenate strings. Let’s take the following simple query as an example:<br />

SELECT 'somestring'<br />

This query is valid for all major DBMSs, but if you want to split the string into two<br />

substrings, the differences start to appear. More specifically, you can use the differences noted<br />

in Table 4.2.

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

Saved successfully!

Ooh no, something went wrong!