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.

206 Chapter 4 • Exploiting <strong>SQL</strong> <strong>Injection</strong><br />

What happens here? Because bcp is a comm<strong>and</strong>-line utility, you can only call it with<br />

xp_cmdshell (or with an equivalent method you might have created; see Chapter 6). The first<br />

parameter that is passed to bcp is the query, which can be any T-<strong>SQL</strong> that returns a result<br />

set. The queryout parameter is used to provide maximum flexibility, because it can h<strong>and</strong>le<br />

bulk copying of data. Then you specify the output file, which is the file where the data must<br />

be written <strong>and</strong> which must reside where it can be accessed with an HTTP connection in<br />

this exploit scenario. The –c switch indicates that a character data type must be used. If you<br />

need to transfer binary data, you should use the –n switch instead.<br />

The –T switch deserves a deeper explanation. Because bcp.exe is a comm<strong>and</strong>-line utility<br />

that needs to talk with a running installation of <strong>SQL</strong> Server, it will need to provide some<br />

form of authentication to perform its job. Usually, such authentication is performed with<br />

a username <strong>and</strong> password using the –U <strong>and</strong> –P parameters, but during a real attack you<br />

might not know (yet) such pieces of information. By using the –T switch, you tell bcp to<br />

connect to <strong>SQL</strong> Server with a trusted connection using Windows integrated security.<br />

That is, the credentials of the user executing the queries will be used.<br />

If everything goes according to plan, the entire sql_logins table will be copied into hashes.<br />

txt, ready to be accessed with your browser, as shown in Figure 4.17.<br />

Figure 4.17 Extracting an Entire Database Table to the File System

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

Saved successfully!

Ooh no, something went wrong!