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.

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

will be illustrated here, <strong>and</strong> some more in Chapter 5, when talking specifically about blind<br />

<strong>SQL</strong> injection, but the examples cannot cover all possibilities. So, if you are not able to<br />

extract data using a normal HTTP connection <strong>and</strong> the database user that is performing<br />

the queries is powerful enough, use your creativity: An OOB communication can be the<br />

fastest way to successfully exploit the vulnerable application.<br />

E-mail<br />

Databases are very often critical parts of any infrastructure, <strong>and</strong> as such it is of the utmost<br />

importance that their administrators can quickly react to any problem that might arise. This is<br />

why most modern DBMSs offer some kind of e-mail functionality that can be used to automatically<br />

send <strong>and</strong> receive e-mail messages in response to certain situations. For instance,<br />

if a new application user is added to a company’s profile the company administrator might be<br />

notified by e-mail automatically as a security precaution. The configuration of how to send<br />

the e-mail in this case is already completed; all an attacker needs to do is construct an exploit<br />

that will extract interesting information, package the data in an e-mail, <strong>and</strong> queue the e-mail<br />

using database-specific functions. The e-mail will then appear in the attacker’s mailbox.<br />

Microsoft <strong>SQL</strong> Server<br />

As is often the case, Microsoft <strong>SQL</strong> Server provides a nice built-in feature for sending<br />

e-mails. Actually, depending on the <strong>SQL</strong> server version, there might be not one, but two<br />

different e-mailing subsystems: <strong>SQL</strong> Mail (<strong>SQL</strong> Server 2000, 2005, <strong>and</strong> 2008) <strong>and</strong> Database<br />

Mail (<strong>SQL</strong> Server 2005 <strong>and</strong> 2008).<br />

<strong>SQL</strong> Mail was the original e-mailing system for <strong>SQL</strong> Server. Microsoft announced with<br />

the release of <strong>SQL</strong> Server 2008 that this feature has been deprecated, <strong>and</strong> will be removed<br />

in future versions. It uses the Messaging Application Programming Interface (MAPI), <strong>and</strong><br />

therefore it needs a MAPI messaging subsystem to be present on the <strong>SQL</strong> Server machine<br />

(e.g., Microsoft Outlook, but not Outlook Express) to send e-mails. Moreover, the e-mail<br />

client needs to be already configured with the Post Office Protocol 3/Simple Mail Transfer<br />

Protocol (POP3/SMTP) or Exchange server to connect to, <strong>and</strong> with an account to use<br />

when connected. If the server you are attacking has <strong>SQL</strong> Mail running <strong>and</strong> configured,<br />

you only need to give a try to xp_startmail (to start the <strong>SQL</strong> Client <strong>and</strong> log on to the mail<br />

server) <strong>and</strong> xp_sendmail (the extended procedure to send an e-mail message with <strong>SQL</strong><br />

Mail). xp_startmail optionally takes two parameters (@user <strong>and</strong> @password) to specify the<br />

MAPI profile to use, but in a real exploitation scenario it’s quite unlikely that you have<br />

this information, <strong>and</strong> in any case you might not need it at all: If such parameters are not<br />

provided, xp_startmail tries to use the default account of Microsoft Outlook, which is what<br />

is typically used when <strong>SQL</strong> Mail is configured to send e-mail messages in an automated way.<br />

Regarding xp_sendmail, its syntax is as follows (only the most relevant options are shown):

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

Saved successfully!

Ooh no, something went wrong!