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.

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

his attack. Regardless of the goal, the attacker wants to be able to read both ASCII text <strong>and</strong><br />

binary files somehow.<br />

An obvious question that naturally follows is how the attacker is able to view these files,<br />

assuming he is able to coerce the DBMS into reading it. Although in this chapter we will<br />

examine a few of the answers to these questions, we covered these methods extensively in<br />

Chapters 4 <strong>and</strong> 5. Simply put, the goal of this subsection is to underst<strong>and</strong> how an attacker<br />

can view the contents of the target file system as part of an <strong>SQL</strong> query. Actually extruding<br />

the data is a different problem to be solved.<br />

My<strong>SQL</strong><br />

My<strong>SQL</strong> provides the well-abused functionality of allowing a text file to be read into the<br />

database through its LOAD DATA INFILE <strong>and</strong> LOAD_FILE comm<strong>and</strong>s. According to<br />

the current My<strong>SQL</strong> reference manual, “The LOAD DATA INFILE statement reads rows<br />

from a text file into a table at a very high speed. The filename must be given as a literal<br />

string.”<br />

Let’s examine the use of the LOAD DATA INFILE comm<strong>and</strong> as it was intended<br />

to be used.<br />

We’ll start by creating a simple text file called users.txt:<br />

cat users.txt<br />

haroon meer haroon@fakedomain.com 1<br />

Dafydd Stuttard mail@fakedomain.net 1<br />

Dave Hartley dave@fakedomain.co.uk 1<br />

Rodrigo Marcos rodrigo@fakedomain.com 1<br />

Gary Oleary-Steele garyo@fakedomain.com 1<br />

Joe Hemler joe@fakedomain.com 1<br />

Marco Slaviero marco@fakedomain.com 1<br />

Alberto Revelli r00t@fakedomain.net 1<br />

Alex<strong>and</strong>er Kornbrust ak@fakedomain.com 1<br />

Justin Clarke justin@fakedomain.com 1<br />

Then we’ll run the following comm<strong>and</strong> within the My<strong>SQL</strong> console to create a table<br />

to house the author details:<br />

mysql> create table authors (fname char(50), sname char(50), email<br />

char(100), flag int);<br />

Query OK, 0 rows affected (0.01 sec)

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

Saved successfully!

Ooh no, something went wrong!