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.

Microsoft <strong>SQL</strong> Server 2005 Hashes<br />

References • Chapter 10 431<br />

Microsoft <strong>SQL</strong> Server 2005 does not store a case-insensitive version of the password hash;<br />

however, the mixed-case version is still accessible. The following <strong>SQL</strong> statement will retrieve<br />

the password hash for the sa account:<br />

SELECT password_hash FROM sys.sql_logins WHERE name='sa'<br />

The following example hash value includes a four-byte constant (0x0100), an eight-byte<br />

salt (4086CEB6), <strong>and</strong> a 40-byte mixed-case hash (beginning with D8277):<br />

0x01004086CEB6D8277477B39B7130D923F399C6FD3C6BD46A0365<br />

File Read/Write<br />

It is possible to read local files providing you have INSERT <strong>and</strong> ADMINISTER BULK<br />

OPERATIONS permissions. The following <strong>SQL</strong> will read the local file c:\boot.ini into the<br />

localfile table:<br />

CREATE TABLE localfile(data varchar(8000));<br />

BULK INSERT localfile FROM 'c:\boot.ini';<br />

You can then extract data back out from the localfile table using a SELECT statement.<br />

If you are extracting table data out via error messages, you may be limited to one row per<br />

query. In this case, you may need a point of reference to select each row one by one. You can<br />

use the ALTER TABLE statement to add an auto-incrementing IDENTITY column to the<br />

localfile table. The following <strong>SQL</strong> statement will add an IDENTITY column named id with<br />

an initial value of 1, incrementing with each row in the table:<br />

ALTER TABLE localfile ADD id INT IDENTITY(1,1);<br />

Data can now be extracted by referencing the id column. For example:<br />

SELECT data FROM localfile WHERE id = 1;<br />

SELECT data FROM localfile WHERE id = 2;<br />

SELECT data FROM localfile WHERE id = 3;<br />

My<strong>SQL</strong> Cheat Sheet<br />

My<strong>SQL</strong> is a popular open source database platform commonly implemented alongside PHP<br />

<strong>and</strong> Ruby on Rails applications. This section provides a quick reference of common <strong>SQL</strong><br />

statements used in <strong>SQL</strong> injection attacks against My<strong>SQL</strong> Server.<br />

Enumerating Database<br />

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

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

lists the <strong>SQL</strong> statements used to enumerate schema information from My<strong>SQL</strong> 5.0 <strong>and</strong> later.

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

Saved successfully!

Ooh no, something went wrong!