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.

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

then focus your efforts on comprehensively validating the editable inputs, which is usually<br />

a much more manageable task.<br />

Examples of technologies that implement this strategy are HTTP Data Integrity<br />

Validator (HDIV) <strong>and</strong> SPF. You can use HDIV to protect most J2EE Web applications that<br />

follow the Model-View-Controller (MVC) pattern <strong>and</strong> you can download it at www.hdiv.<br />

org. You can use SPF to protect ASP.NET Web applications when run on IIS 6.0; however,<br />

it can be leveraged to protect virtually any Web application when run on IIS 7.0. Refer to<br />

the Tools <strong>and</strong> Traps sidebar, “Protecting Web Applications with ASP.NET <strong>and</strong> IIS,” for more<br />

information. You can download SPF at www.gdssecurity.com/l/spf/.<br />

URL/Page-Level Strategies<br />

Let’s look at some other techniques for virtual-patching a vulnerable URL or page without<br />

changing the source code.<br />

Page Overriding<br />

If a page is vulnerable <strong>and</strong> needs replacing, you can create a replacement page or class that<br />

is substituted at runtime. The substitution is accomplished with configuration in the Web<br />

application’s configuration file. In ASP.NET applications, you can use HTTP h<strong>and</strong>lers to<br />

accomplish this task.<br />

Figure 9.9 shows a custom HTTP h<strong>and</strong>ler configured to h<strong>and</strong>le requests to<br />

PageVulnToSqlI.aspx instead of the vulnerable page itself. The substituted h<strong>and</strong>ler class<br />

implements the logic of the original page in a secure manner. This could include stringent<br />

validation of request parameters <strong>and</strong> the use of secure data access objects.<br />

Figure 9.9 Configuring an HTTP H<strong>and</strong>ler in web.config<br />

<br />

<br />

<br />

You can use a similar approach in the deployment descriptor of a J2EE Web application.<br />

You can map the vulnerable URL to a servlet that h<strong>and</strong>les the request in a secure manner, as<br />

shown in Figure 9.10.

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

Saved successfully!

Ooh no, something went wrong!