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.

Such a query will return output similar to the following:<br />

+---------------------+-------------------------+--------------+<br />

| grantee | privilege_type | is_grantable |<br />

+---------------------+-------------------------+--------------+<br />

| 'root'@'localhost' | SELECT | YES |<br />

| 'root'@'localhost' | INSERT | YES |<br />

| 'root'@'localhost' | UPDATE | YES |<br />

| 'root'@'localhost' | DELETE | YES |<br />

| 'root'@'localhost' | CREATE | YES |<br />

| 'root'@'localhost' | DROP | YES |<br />

| 'root'@'localhost' | RELOAD | YES |<br />

| 'root'@'localhost' | SHUTDOWN | YES |<br />

| 'root'@'localhost' | PROCESS | YES |<br />

| 'root'@'localhost' | FILE | YES |<br />

| 'root'@'localhost' | REFERENCES | YES |<br />

| 'root'@'localhost' | INDEX | YES |<br />

<br />

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

If you need to know the privileges granted to users on the different databases,<br />

the following query will do the job:<br />

SELECT grantee, table_schema, privilege_type FROM<br />

information_schema.schema_privileges<br />

For space reasons, all the queries that could be useful for enumerating information for a<br />

specific technology cannot be included, but some cheat sheets are available in Chapter 10.<br />

Cheat sheets are also available online that can assist you in quickly locating the proper query<br />

for h<strong>and</strong>ling a specific job on a specific database. One place to look is http://pentestmonkey.<br />

net/cheat-sheets/.<br />

Unfortunately, information_schema is available only in My<strong>SQL</strong> 5 <strong>and</strong> later, so if you are<br />

dealing with an earlier version the process will be more difficult, as a brute-force attack might<br />

be the only way to determine the names of tables <strong>and</strong> columns. One thing you can do<br />

(however, it’s a little complicated) is access the files that store the database, import their raw<br />

content into a table that you create, <strong>and</strong> then extract that table using one of the techniques<br />

you’ve seen so far. Let’s briefly walk through an example of this technique. You can easily find<br />

the current database name with the following query:<br />

SELECT database()<br />

The files for this database will be stored in a directory with the same name as the<br />

database itself. This directory will be contained in the main My<strong>SQL</strong> data directory, which is<br />

returned by the following query:<br />

SELECT @@datadir

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

Saved successfully!

Ooh no, something went wrong!