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.

234 Chapter 5 • Blind <strong>SQL</strong> <strong>Injection</strong> Exploitation<br />

status=Incubating' AND ASCII(SUBSTRING(SYSTEM_USER,1,1)) & 8=8-- (False)<br />

status=Incubating' AND ASCII(SUBSTRING(SYSTEM_USER,1,1)) & 4=4-- (False)<br />

status=Incubating' AND ASCII(SUBSTRING(SYSTEM_USER,1,1)) & 2=2-- (True)<br />

status=Incubating' AND ASCII(SUBSTRING(SYSTEM_USER,1,1)) & 1=1-- (True)<br />

Because True represents 1 <strong>and</strong> False represents 0, we have the bitstring 01110011, which<br />

is 115 10<br />

. Looking up 115 10<br />

on an ASCII chart give us s which is the first character of the<br />

username. Our focus then shifts to the next byte <strong>and</strong> the next after that, until all bytes have<br />

been retrieved. When compared to the binary search method this bit-by-bit approach also<br />

requires eight requests, so you may wonder what the point is of all this bit manipulation;<br />

however, since each request is independent of all the others they can be trivially parallelized.<br />

Eight requests appear to be inefficient in retrieving a single byte, but when the only<br />

available option is blind <strong>SQL</strong> injection this is a small price to pay. It goes without saying that<br />

although many <strong>SQL</strong> injection attacks can be implemented by h<strong>and</strong>, issuing eight custom<br />

requests to extract a single byte would leave most people reaching for the painkillers.<br />

Because all that differs between requests for different bits is a bunch of offsets, this task is<br />

eminently automatable, <strong>and</strong> later in this chapter we will examine a number of tools that take<br />

the pain out of crafting these inference attacks.<br />

Tip<br />

If you are ever in a situation where you need to have an integer value broken<br />

up into a bitstring using <strong>SQL</strong>, <strong>SQL</strong> Server 2000 <strong>and</strong> 2005 support a userdefined<br />

function, FN_REPLINTTOBITSTRING( ), which takes as its sole argument<br />

an integer <strong>and</strong> returns a 32-character string representing the bitstring.<br />

For example, FN_REPLINTTOBITSTRING(ASCII(‘s’)) returns 000000000000000000<br />

00000001110011, which is a 32-bit representation of 115 10<br />

or s.<br />

Alternative Channel Techniques<br />

The second category of methods for extracting data in blind <strong>SQL</strong> injection vulnerabilities<br />

is by means of alternative channels, <strong>and</strong> what sets these methods apart from the inference<br />

techniques is that although inference techniques rely on the response sent by the vulnerable<br />

page, alternative channel techniques utilize transports apart from the page response. This<br />

includes channels such as DNS, e-mail, <strong>and</strong> HTTP requests. A further attribute of alternative<br />

channel techniques is that generally they enable you to retrieve chunks of data at a time<br />

rather than inferring the value of individual bits or bytes, which makes alternative channels<br />

a very attractive option to explore. Instead of using eight requests to retrieve a single byte,<br />

you could possibly retrieve 200 bytes with a single request. However, most alternative<br />

channel techniques require larger exploit strings than inference techniques.

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

Saved successfully!

Ooh no, something went wrong!