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.

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

Summary<br />

This chapter demonstrated how <strong>SQL</strong> injection attacks can be used to attack the host on<br />

which the database server is running. The ability to read <strong>and</strong> write files to the file system<br />

<strong>and</strong> the ability to execute operating system comm<strong>and</strong>s is built into most modern RDBMSs<br />

today, <strong>and</strong> this by extension means that this functionality is available to most <strong>SQL</strong> injection<br />

attackers.<br />

The ability to use a single vulnerability such as a discovered <strong>SQL</strong> injection point as a<br />

beachhead to launch attacks at other hosts is one of those penetration testing techniques<br />

that separates the men from the boys. This chapter covered how simple primitives such as<br />

file reading, file writing, <strong>and</strong> comm<strong>and</strong> execution can be used within <strong>SQL</strong> injection attacks<br />

against the most prominent application architectures.<br />

With these primitives under your belt, you can move on to Chapter 7, which covers<br />

advanced <strong>SQL</strong> injection topics.<br />

Solutions Fast Track<br />

Accessing the File System<br />

˛˛ The following pertains to reading files from the file system using <strong>SQL</strong> injection:<br />

In My<strong>SQL</strong>, you can use the LOAD DATA INFILE <strong>and</strong> LOAD_FILE( )<br />

comm<strong>and</strong>s to read arbitrary files from the host.<br />

In Microsoft <strong>SQL</strong> Server, you can read files from the filesystem using BULK<br />

INSERT or OLE Automation. On newer systems (<strong>SQL</strong> Server 2005 <strong>and</strong> later),<br />

you can use a quirk in the CREATE ASSEMBLY methods to read files from the<br />

file system.<br />

In Oracle, you can read files using Oracle Directory, Oracle Text, or the utl_ file<br />

method.<br />

˛˛ The following pertains to writing files to the file system using <strong>SQL</strong> injection:<br />

In My<strong>SQL</strong>, you can write files to the file system by using the select into outfile<br />

<strong>and</strong> select into dumpfile comm<strong>and</strong>s.<br />

In Microsoft <strong>SQL</strong> Server, you can use OLE Automation <strong>and</strong> simple redirection<br />

(through comm<strong>and</strong> execution) to create files on the target file system. You can<br />

use debug.exe <strong>and</strong> BCP from the comm<strong>and</strong> line to assist with creating binaries on<br />

the target.<br />

In Oracle, you can accomplish file writing using utl_file, DBMS_ADVISOR,<br />

Java, or operating system comm<strong>and</strong>s <strong>and</strong> st<strong>and</strong>ard redirection.

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

Saved successfully!

Ooh no, something went wrong!