19.09.2017 Views

the-web-application-hackers-handbook

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

624 Chapter 15 n Exploiting Information Disclosure<br />

Engineering Informative Error Messages<br />

In some situations, it may be possible to systematically engineer error conditions<br />

in such a way as to retrieve sensitive information within <strong>the</strong> error message itself.<br />

One common situation in which this possibility arises is where you can cause<br />

<strong>the</strong> <strong>application</strong> to attempt some invalid action on a specific item of data. If <strong>the</strong><br />

resulting error message discloses <strong>the</strong> value of that data, and you can cause<br />

interesting items of information to be processed in this way, you may be able<br />

to exploit this behavior to extract arbitrary data from <strong>the</strong> <strong>application</strong>.<br />

Verbose open database connectivity (ODBC) error messages can be leveraged<br />

in a SQL injection attack to retrieve <strong>the</strong> results of arbitrary database queries.<br />

For example, <strong>the</strong> following SQL, if injected into a WHERE clause, would cause <strong>the</strong><br />

database to cast <strong>the</strong> password for <strong>the</strong> first user in <strong>the</strong> users table to an integer<br />

to perform <strong>the</strong> evaluation:<br />

‘ and 1=(select password from users where uid=1)--<br />

This results in <strong>the</strong> following informative error message:<br />

Error: Conversion failed when converting <strong>the</strong> varchar value<br />

‘37CE1CCA75308590E4D6A35F288B58FACDBB0841’ to data type int.<br />

TRY IT<br />

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

A different way in which this kind of technique can be used is where an<br />

<strong>application</strong> error generates a stack trace containing a description of <strong>the</strong> error,<br />

and you can engineer a situation where interesting information is incorporated<br />

into <strong>the</strong> error description.<br />

Some databases provide a facility to create user-defined functions written<br />

in Java. By exploiting a SQL injection flaw, you may be able to create your own<br />

function to perform arbitrary tasks. If <strong>the</strong> <strong>application</strong> returns error messages to<br />

<strong>the</strong> browser, from within your function you can throw a Java exception containing<br />

arbitrary data that you need to retrieve. For example, <strong>the</strong> following code<br />

executes <strong>the</strong> operating system command ls and <strong>the</strong>n generates an exception<br />

that contains <strong>the</strong> output from <strong>the</strong> command. This returns a stack trace to <strong>the</strong><br />

browser, <strong>the</strong> first line of which contains a directory listing:<br />

ByteArrayOutputStream baos = new ByteArrayOutputStream();<br />

try<br />

{<br />

Process p = Runtime.getRuntime().exec(“ls”);<br />

InputStream is = p.getInputStream();<br />

int c;<br />

while (-1 != (c = is.read()))<br />

baos.write((byte) c);<br />

}

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

Saved successfully!

Ooh no, something went wrong!