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.

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

We want to extract the username that the page uses to connect to the database. Our<br />

Microsoft <strong>SQL</strong> Server database has a function called SYSTEM_USER that will return the<br />

login username in whose context the database session has been established. Normally, you<br />

can view this with the <strong>SQL</strong> SELECT SYSTEM_USER, but in this case the results are not<br />

visible. Figure 5.1 depicts an attempt to extract data using the verbose error message technique,<br />

but the page returns a st<strong>and</strong>ard error page. Unfortunately, the developers followed bad<br />

security advice, <strong>and</strong> rather than steering clear of dynamic <strong>SQL</strong> they chose to catch database<br />

exceptions <strong>and</strong> display a generic error message.<br />

Figure 5.1 Unsuccessful Attempt to Extract Data through Error Messages<br />

When we submit status=Incubating the page executes the preceding <strong>SQL</strong> query <strong>and</strong><br />

returns the string shown in Figure 5.2.<br />

Figure 5.2 Response When Counting Unhatched Eggs<br />

We can alter the status parameter such that the <strong>SQL</strong> query returns an empty result set by<br />

adding the “always false” clause <strong>and</strong> ‘1’= ‘2 to the legitimate query, yielding the following<br />

<strong>SQL</strong> statement:<br />

SELECT COUNT(chick_id) FROM chickens WHERE status='Incubating' <strong>and</strong> '1'='2'<br />

Figure 5.3 shows the response to this query. From the message, we can infer that the<br />

query returned an empty result set. Keep in mind that for two rows, status was Incubating, but<br />

the trailing false clause ensured that no rows would match.

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

Saved successfully!

Ooh no, something went wrong!