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 329<br />

n Determine <strong>the</strong> location of <strong>the</strong> vulnerable field within <strong>the</strong> back-end SQL<br />

query by appending various characters such as closing brackets, comment<br />

characters, and SQL keywords.<br />

n Attempt to perform a UNION attack by brute-forcing <strong>the</strong> number of required<br />

columns and <strong>the</strong>n identifying a column with <strong>the</strong> varchar data type, which<br />

can be used to return results.<br />

n Inject custom queries to retrieve arbitrary data — if necessary, concatenating<br />

data from multiple columns into a string that can be retrieved<br />

through a single result of <strong>the</strong> varchar data type.<br />

n If results cannot be retrieved using UNION, inject Boolean conditions (AND<br />

1=1, AND 1=2, and so on) into <strong>the</strong> query to determine whe<strong>the</strong>r conditional<br />

responses can be used to retrieve data.<br />

n If results cannot be retrieved by injecting conditional expressions, try<br />

using conditional time delays to retrieve data.<br />

These tools locate data by querying <strong>the</strong> relevant metadata tables for <strong>the</strong> database<br />

in question. Generally <strong>the</strong>y can perform some level of escalation, such as<br />

using xp_cmdshell to gain OS-level access. They also use various optimization<br />

techniques, making use of <strong>the</strong> many features and built-in functions in <strong>the</strong> various<br />

databases to decrease <strong>the</strong> number of necessary queries in an inference-based<br />

brute-force attack, evade potential filters on single quotes, and more.<br />

NOTE These tools are primarily exploitation tools, best suited to extracting<br />

data from <strong>the</strong> database by exploiting an injection point that you have already<br />

identified and understood. They are not a magic bullet for finding and exploiting<br />

SQL injection flaws. In practice, it is often necessary to provide some<br />

additional SQL syntax before and/or after <strong>the</strong> data injected by <strong>the</strong> tool for <strong>the</strong><br />

tool’s hard-coded attacks to work.<br />

HACK STEPS<br />

When you have identified a SQL injection vulnerability, using <strong>the</strong> techniques<br />

described earlier in this chapter, you can consider using a SQL injection tool to<br />

exploit <strong>the</strong> vulnerability and retrieve interesting data from <strong>the</strong> database. This<br />

option is particularly useful in cases where you need to use blind techniques<br />

to retrieve a small amount of data at a time.<br />

1. Run <strong>the</strong> SQL exploitation tool using an intercepting proxy. Analyze <strong>the</strong><br />

requests made by <strong>the</strong> tool as well as <strong>the</strong> <strong>application</strong>’s responses. Turn on<br />

any verbose output options on <strong>the</strong> tool, and correlate its progress with <strong>the</strong><br />

observed queries and responses.<br />

Continued

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

Saved successfully!

Ooh no, something went wrong!