19.09.2017 Views

the-web-application-hackers-handbook

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

326 Chapter 9 n Attacking Data Stores<br />

Attacking databases is a huge topic that is beyond <strong>the</strong> scope of this book. This<br />

section points you toward a few key ways in which vulnerabilities and functionality<br />

within <strong>the</strong> main database types can be leveraged to escalate your attack.<br />

The key conclusion to draw is that every database contains ways to escalate<br />

privileges. Applying current security patches and robust hardening can help<br />

mitigate many of <strong>the</strong>se attacks, but not all of <strong>the</strong>m. For fur<strong>the</strong>r reading on this<br />

highly fruitful area of current research, we recommend The Database Hacker’s<br />

Handbook (Wiley, 2005).<br />

MS-SQL<br />

Perhaps <strong>the</strong> most notorious piece of database functionality that an attacker can<br />

misuse is <strong>the</strong> xp_cmdshell stored procedure, which is built into MS-SQL by<br />

default. This stored procedure allows users with DBA permissions to execute<br />

operating system commands in <strong>the</strong> same way as <strong>the</strong> cmd.exe command prompt.<br />

For example:<br />

master..xp_cmdshell ‘ipconfig > foo.txt’<br />

The opportunity for an attacker to misuse this functionality is huge. He can<br />

perform arbitrary commands, pipe <strong>the</strong> results to local files, and read <strong>the</strong>m back.<br />

He can open out-of-band network connections back to himself and create a<br />

backdoor command and communications channel, copying data from <strong>the</strong> server<br />

and uploading attack tools. Because MS-SQL runs by default as LocalSystem,<br />

<strong>the</strong> attacker typically can fully compromise <strong>the</strong> underlying operating system,<br />

performing arbitrary actions. MS-SQL contains a wealth of o<strong>the</strong>r extended<br />

stored procedures, such as xp_regread and xp_regwrite, that can be used to<br />

perform powerful actions within <strong>the</strong> registry of <strong>the</strong> Windows operating system.<br />

Dealing with Default Lockdown<br />

Most installations of MS-SQL encountered on <strong>the</strong> Internet will be MS-SQL 2005<br />

or later. These versions contain numerous security features that lock down <strong>the</strong><br />

database by default, preventing many useful attack techniques from working.<br />

However, if <strong>the</strong> <strong>web</strong> <strong>application</strong>’s user account within <strong>the</strong> database is sufficiently<br />

high-privileged, it is possible to overcome <strong>the</strong>se obstacles simply by<br />

reconfiguring <strong>the</strong> database. For example, if xp_cmdshell is disabled, it can be<br />

re-enabled with <strong>the</strong> sp_configure stored procedure. The following four lines<br />

of SQL do this:<br />

EXECUTE sp_configure ‘show advanced options’, 1<br />

RECONFIGURE WITH OVERRIDE<br />

EXECUTE sp_configure ‘xp_cmdshell’, ‘1’<br />

RECONFIGURE WITH OVERRIDE

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

Saved successfully!

Ooh no, something went wrong!