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.

332 Chapter 7 • Advanced Topics<br />

At this point, your attack is successful <strong>and</strong> the application’s query is subverted. The name<br />

retrieved from the database is h<strong>and</strong>led unsafely, <strong>and</strong> you are able to break out of the data<br />

context within the query <strong>and</strong> modify the query’s structure. In this proof-of-concept attack,<br />

the database version string is copied into the name of your contact, <strong>and</strong> will be displayed<br />

on-screen when you view the updated contact details:<br />

Name: aMicrosoft <strong>SQL</strong> Server 7.00 – 7.00.623 (Intel X86) Nov 27 1998<br />

22:20:07 Copyright (c) 1988–1998 Microsoft Corporation Desktop<br />

Edition on Windows NT 5.1 (Build 2600: )a<br />

Address: 52 Throwley Way<br />

To perform a more effective attack, you would need to use the general techniques<br />

already described for injecting into UPDATE statements (see Chapter 8), again placing your<br />

attacks into one contact field <strong>and</strong> then updating a different field to trigger the vulnerability.<br />

Finding Second-Order Vulnerabilities<br />

Second-order <strong>SQL</strong> injection is more difficult to detect than first-order vulnerabilities, because<br />

your exploit is submitted in one request <strong>and</strong> executed in the application’s h<strong>and</strong>ling of a<br />

different request. The core technique for discovering most input-based vulnerabilities, where<br />

an individual request is submitted repeatedly with various crafted inputs <strong>and</strong> the application’s<br />

responses are monitored for anomalies, is not effective in this instance. Rather, you need to<br />

submit your crafted input in one request, <strong>and</strong> then step through all other application functions<br />

which may make use of that input, looking for anomalies. In some cases, there is only one<br />

instance of the relevant input (e.g., the user’s display name), <strong>and</strong> testing each payload may<br />

necessitate stepping through the application’s entire functionality.<br />

Today’s automated scanners are not very effective at discovering second-order <strong>SQL</strong><br />

injection. They typically submit each request numerous times with different inputs, <strong>and</strong><br />

monitor the responses. If they then crawl other areas of the application <strong>and</strong> encounter<br />

database error messages, they will draw them to your attention, hopefully enabling you to<br />

investigate <strong>and</strong> diagnose the issue. But they are not capable of associating an error message<br />

returned in one location with a piece of crafted input submitted in another. In some cases,<br />

there is no error message, <strong>and</strong> the effects of the second-order condition may be h<strong>and</strong>led<br />

blindly. If there is only a single instance of the relevant persisted item, or persisting it<br />

within the application requires multiple steps (e.g., a user registration process), the problem<br />

is compounded further. Hence, today’s scanners are not able to perform a rigorous<br />

methodology for discovering second-order vulnerabilities.<br />

Without an underst<strong>and</strong>ing of the meaning <strong>and</strong> usage of data items within the application,<br />

the work involved in detecting second-order <strong>SQL</strong> injection grows exponentially with the size<br />

of the application’s functionality. But human testers can use their underst<strong>and</strong>ing of that functionality,<br />

<strong>and</strong> their intuition about where mistakes are often made, to reduce the size of the task.<br />

In most cases, you can use the following methodology to identify second-order vulnerabilities:

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

Saved successfully!

Ooh no, something went wrong!