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.

Figure 6.13 Enabling CLR Integration through an Application<br />

Exploiting the Operating System • Chapter 6 287<br />

This positions us to load any .NET binary from the remote server into the database by<br />

using the CREATE ASSEMBLY function.<br />

We’ll load the .NET assembly c:\temp\test.exe with the following injection string:<br />

sname=';create assembly sqb from 'c:\temp\test.exe' with permission_set =<br />

unsafe--<br />

<strong>SQL</strong> Server stores the raw binary (as a HEX string) in the sys.assembly_ files table.<br />

As shown in Figure 6.14, you can view this easily within Query Analyzer.<br />

Figure 6.14 Viewing the Attached File within the Database<br />

Viewing this file through our Web page requires that we combine the substring( ) <strong>and</strong><br />

master.dbo.fn_varbintohexstr() functions:<br />

sname=' union select NULL,NULL,NULL, master.dbo.fn_varbintohexstr<br />

(substring(content,1,5)) from sys.assembly_files--<br />

Figure 6.15 shows how you can use the union, substring, <strong>and</strong> fn_varbintohexstr combination<br />

to read binary files through the browser.

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

Saved successfully!

Ooh no, something went wrong!