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.

As expected, this creates sp.txt file in the /tmp directory:<br />

$ cat sp.txt<br />

SensePost 2008<br />

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

When reading binary files from the file system we used My<strong>SQL</strong>’s built-in HEX function,<br />

so it makes perfect sense that when trying to write binary to the file system we would do<br />

the reverse. We therefore use the My<strong>SQL</strong> built-in function, UNHEX( ):<br />

mysql> select UNHEX('53656E7365506F7374203038');<br />

+-----------------------------------+<br />

| UNHEX('53656E7365506F7374203038') |<br />

+-----------------------------------+<br />

| SensePost 08 |<br />

+-----------------------------------+<br />

1 row in set (0.00 sec)<br />

With this combination, we are effectively primed to write any kind of file, anywhere on<br />

the file system (without the ability to overwrite existing files [<strong>and</strong> keeping in mind that the<br />

file will be world-writable]). Before a brief discussion on what you can do with the ability<br />

to write any file anywhere, it is probably worth it to see what happened to www.apache.org<br />

when attackers gave themselves the same capability.<br />

Notes from the Underground…<br />

How We Defaced apache.org<br />

In May 2000, the main Web page of the Apache Foundation (maker of the Apache<br />

Web Server) was subtly defaced to house the “Powered by Microsoft BackOffice” logo.<br />

The pranksters, { } <strong>and</strong> Hardbeat, documented their attack at www.dataloss.net/papers/<br />

how.defaced.apache.org.txt in a paper titled “How we defaced www.apache.org.”<br />

The pair first obtained access by abusing an ftpd configuration error <strong>and</strong> then<br />

uploading a crude Web shell to the Web server root. This allowed them to have a<br />

low-privileged shell running as the user nobody. They then went on to say:<br />

“After a long search we found out that mysql was running as user root <strong>and</strong> was<br />

reachable locally. Because apache.org was running bugzilla which requires a mysql<br />

account <strong>and</strong> has it username/password plaintext in the bugzilla source it was easy to<br />

get a username/passwd for the mysql database.”<br />

Continued

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

Saved successfully!

Ooh no, something went wrong!