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.

180 Chapter 4 • Exploiting <strong>SQL</strong> <strong>Injection</strong><br />

Each table of the database is contained in a file with the extension MYD. For instance,<br />

here are some of the MYD files of a default mysql database:<br />

tables_priv.MYD<br />

host.MYD<br />

help_keyword.MYD<br />

columns_priv.MYD<br />

db.MYD<br />

You can extract the contents of a specific table of that database with the following query:<br />

SELECT load_file('databasename/tablename.MYD')<br />

However, without information_schema you will have to brute-force the table name for this<br />

query to succeed. Also, note that load_file (discussed in more detail in Chapter 6) only allows<br />

you to retrieve a maximum number of bytes that is specified in the @@max_allowed_packet<br />

variable, so this technique is not suited for tables that store large amounts of data.<br />

Oracle<br />

The last example we will cover is how to enumerate the database schema when the back-end<br />

DBMS is Oracle. An important fact to remember when using Oracle is that you will<br />

normally be accessing only one database at a time, as databases in Oracle are normally<br />

accessed via a specific connection, <strong>and</strong> multiple databases accessed by an application will<br />

generally have different connections. Therefore, unlike <strong>SQL</strong> Server <strong>and</strong> My<strong>SQL</strong>, you won’t be<br />

enumerating the databases present when finding the database schema.<br />

The first thing you may be interested in is the list of tables that belong to the current<br />

user. In the context of an application, this will generally be the application tables in the<br />

database:<br />

select table_name from user_tables;<br />

You can extend this to look at all of the tables in the database <strong>and</strong> their owners:<br />

select owner,table_name from all_tables;<br />

You can enumerate some more information about your application tables to determine<br />

the number of columns <strong>and</strong> rows that are present in the tables as follows:<br />

select a.table_name||'['||count(*)||']='||num_rows from user_tab_columns a,<br />

user_tables b where a.table_name=b.table_name group by<br />

a.table_name,num_rows<br />

EMP[8]=14<br />

DUMMY[1]=1<br />

DEPT[3]=4<br />

SALGRADE[3]=5

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

Saved successfully!

Ooh no, something went wrong!