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

Create successful ePaper yourself

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

Advanced Topics • Chapter 7 333<br />

1. After you have mapped out the application’s content <strong>and</strong> functionality, review it,<br />

looking for any items of user-controllable data that are persisted by the application<br />

<strong>and</strong> reused in subsequent functions. Work on each item individually, <strong>and</strong> perform<br />

the following steps on each instance.<br />

2. Submit a simple value within the item that is likely to cause problems if used<br />

unsafely in an <strong>SQL</strong> query, such as a single quote or an alphanumeric string<br />

with a single quote within it. If required, walk through any multistage processes<br />

(such as user registration) to ensure that your value is fully persisted within the<br />

application.<br />

3. If you find that the application’s input filters block your input, use the techniques<br />

described earlier in this chapter (in “Evading Input Filters”) to try to defeat the<br />

front-end input filters.<br />

4. Walk through all of the application’s functionality where you have seen the data<br />

item being explicitly used, <strong>and</strong> also any functions where it might conceivably be<br />

implicitly used. Look for any anomalous behavior that may indicate that the input<br />

has caused a problem, such as database error messages, HTTP 500 status codes,<br />

more cryptic error messages, broken functionality, missing or corrupted data, <strong>and</strong><br />

so forth.<br />

5. For each potential issue identified, try to develop a proof-of-concept attack to<br />

verify that an <strong>SQL</strong> injection vulnerability is present. Be aware that malformed<br />

persisted data may cause anomalous conditions in ways that are not directly<br />

vulnerable (e.g., integer conversion errors, or failure of subsequent data validation).<br />

Try supplying the same input with two quotation marks together, <strong>and</strong> see<br />

whether the anomaly goes away. Try using database-specific constructs such as<br />

string concatenation functions <strong>and</strong> version banners to confirm that you are<br />

modifying an <strong>SQL</strong> query. If the anomalous condition is blind (i.e., it does not<br />

return the results of the query or any error message), try using time delay techniques<br />

to verify that a vulnerability is present.<br />

You should be aware that some second-order <strong>SQL</strong> injection vulnerabilities are fully<br />

blind <strong>and</strong> have no discernible effects on the contents of any application responses.<br />

For example, if an application function writes persisted data to logs in an unsafe manner,<br />

<strong>and</strong> h<strong>and</strong>les any exceptions gracefully, the steps I just described will probably miss the<br />

vulnerability. To detect these kinds of flaws, you need to repeat the preceding steps using<br />

various inputs in step 1 designed to trigger time delays when used unsafely in <strong>SQL</strong><br />

queries, <strong>and</strong> then monitor all of the application’s functionality for anomalous delays.<br />

To do this effectively, you will need to use syntax that is specific to the type of database<br />

being used <strong>and</strong> the types of queries (SELECT, INSERT, etc.) being performed. In practice,<br />

this may be a very lengthy exercise indeed.

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

Saved successfully!

Ooh no, something went wrong!