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.

Platform-Level <strong>Defense</strong>s • Chapter 9 395<br />

more so than WAFs. Consider that the queries the Web application sends to the database<br />

are, for the most part, a known quantity of comm<strong>and</strong>s, <strong>and</strong> their structure is known as<br />

well. You can leverage this information to configure a highly tuned set of rules that takes<br />

appropriate action (log, block, etc.) against unusual or malicious queries before ever hitting<br />

the database. One of the hardest problems with locking down input in a WAF is that<br />

malicious users can send in any combination of requests to the Web server. An example<br />

open source implementation is Green<strong>SQL</strong>, which you can download at www.greensql.net.<br />

Securing the Database<br />

When an attacker has an exploitable <strong>SQL</strong> injection vulnerability, he can take one of two<br />

primary exploit paths. He can go after the application data itself, which depending on the<br />

application <strong>and</strong> the data could be very lucrative. This is especially true if the application<br />

h<strong>and</strong>les <strong>and</strong> insecurely stores personally identifiable information or financial data, such as<br />

bank account <strong>and</strong> credit card information. Alternatively, the attacker may be interested in<br />

leveraging the database server to penetrate internal, trusted networks. In this section, we’re<br />

going to look at ways to limit unauthorized access to application data. Then we’ll look at<br />

some techniques for hardening the database server to help prevent privilege escalation <strong>and</strong><br />

limiting access to server resources outside the context of the target database server. You should<br />

fully test the steps we’ll be covering in a non-production environment first, to avoid breaking<br />

the functionality of existing applications. New applications have the benefit of building these<br />

recommendations into the development life cycle early to avoid dependencies on unnecessary<br />

<strong>and</strong> privileged functionality.<br />

Locking Down the Application Data<br />

Let’s first examine some techniques restricting the scope of an <strong>SQL</strong> injection attack to the<br />

application database only. We’re also going to look at ways to restrict access even if the<br />

attacker has been successfully s<strong>and</strong>boxed to the application database.<br />

Use the Least-Privileged Database Login<br />

Applications should connect to the database server in the context of a login that has permissions<br />

for performing required application tasks only. This critical defense can significantly mitigate<br />

the risk of <strong>SQL</strong> injection, by restricting what an attacker can access <strong>and</strong> execute when<br />

exploiting the vulnerable application. For example, a Web application used for reporting purposes,<br />

such as checking the performance of your investment portfolio, should ideally access the<br />

database with a login that has inherited only the permissions on objects (stored procedures,<br />

tables, etc.) needed to produce this data. This could be EXECUTE permissions on several<br />

stored procedures <strong>and</strong> possibly SELECT permissions on a h<strong>and</strong>ful of table columns. In the<br />

event of <strong>SQL</strong> injection, this would at least limit the possible set of comm<strong>and</strong>s to the stored<br />

procedures <strong>and</strong> tables within the application database <strong>and</strong> prevent malicious <strong>SQL</strong> outside this

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

Saved successfully!

Ooh no, something went wrong!