Section 1: Introduction

Background
ModSecurity is an open source web application firewall that can work either embedded in an Apache web server or as a reverse proxy. The new features in version 2.0 and version 2.5 (released in February 2008) allow for a highly configurable capability that can address vulnerabilities (e.g. discovered during black-box penetration testing) on a per-application basis. ModSecurity provides for free a broad set of generic Core Rulesets that cover areas such as protocol compliance, malicious client software detection, XML protection, error detection, and generic attack detection ("Detect application level attacks such as described in the OWASP top 10"). However, the Core Set rule documentation (see README in modsecurity-core-rules_2.5-1.6.0.tar.gz) cautions that since attackers may examine the freely-available core rules to get around them, some core rules should be viewed more as a "nuisance reduction" mechanism instead of a security mechanism.

The lessons in WebGoat 5.2 detail over 30 different types of attacks on the WebGoat application (see the WebGoat v5 User & Install Guide).

Purpose
The purpose of this project is to create custom ModSecurity rulesets that, in addition to the Core Set, will protect WebGoat 5.2 Standard Release from as many of its vulnerabilities as possible (the goal is 90%) without changing one line of source code. To ensure that it will be a complete 'no touch' on WebGoat and its environment, ModSecurity 2.5.5 will be configured on Apache server as a remote proxy server.

For those vulnerabilities that cannot be prevented (partially or not at all), I will document my efforts in attempting to protect them. Business logic vulnerabilities will be particularly challenging to solve.

The opportunity, challenges, issues or need this project addresses:
 * Provides application-level protection for those web applications that cannot be touched
 * New custom rulesets can be added as new attack types are discovered
 * This solution is programming language and platform agnostic
 * With outside help from consultants, this solution can be used by companies that have zero knowledge of software security
 * A possible unintended side-effect: introduce software security awareness into an organization, which may lead to software security development lifecycle practices for future projects
 * Common types of business logic vulnerabilities (this will be a challenge)

Tasks and deliverables

 * Set up and test the development environment. The initial Reverse Proxy server OS will be Kubuntu 7.10.


 * Identify WebGoat vulnerabilities and exploitation methods. Publish to wiki for review, feedback, and modification.


 * Develop rulesets for 50% of the vulnerabilities, starting with the low-hanging fruit. Deliver user documentation. Publish progress to wiki as each vulnerability is addressed.


 * Peer review, feedback, modification at 50% project completion (Milestone 1)


 * Develop rulesets for the 2nd 50% of the vulnerabilities. Publish progress to wiki as each vulnerability is addressed.


 * Test final rulesets and ModSecurity Reverse Proxy on two other Linux distros.


 * Produce final rulesets and documentation.


 * Peer review, feedback, modification, deliver final product (Project completion)

Project member comments at 100%
The project has a heavy Lua scripting influence simply because it was easier for me with my background being software development; the project's subtitle could almost be "ModSecurity for Software Developer Dummies" and the project probably entered into a realm where no one person has gone before.

One of my security hats is pentesting, and this project has put ModSecurity in my toolbox. Now instead of only "Modify the source code and fix the vulnerability" as a recommendation for particular vulnerabilities, I can also recommend "Or, deploy a WAF and write a custom ruleset to mitigate the vulnerability". This is particularly applicable to PCI-DSS compliance, which for application security contains a triumvirate of penetration testing, code review, and a Web Application Firewall. Now I have all three of those in my arsenal of solutions that I can provide to the customer.

Using ModSecurity's Lua scripting on the back end and its Javascript injection functionality on the front end lends itself to mitigating almost any type of vulnerability, including business logic flaws. Of course, performance considerations must be taken into account and in high octane scenarios using these features might not be feasible.

Thanks to Ryan Barnett at Breach Security for turning the project almost into a contest; he presented a "traditional" ModSecurity solution to counter many of my Lua lesson solutions. You can compare them and decide which is easier to develop, test, and debug.

A thank you also goes out to Christian Folini, especially for (perhaps unknowingly) giving me moral support when it was needed.

Stephen Evans - 27 October 2008

Future development and long-term vision
The following are possibilities for future development:

1. Package Lua script functionality:

Several business logic flaws were solved using Lua scripting. Perhaps these examples can be expanded into more robust solutions, or as a project reviewer stated: "In some scenarios it may be advantageous to use Lua scripts to provide “packaged” functionality for some complex issues..."

2. Use ModSecurity to protect Hacme Bank:

A description: Hacme Bank (v2.0 Released 5/19/2006) is designed to teach application developers, programmers, architects and security professionals how to create secure software. Hacme Bank simulates a "real-world" web services-enabled online banking application, which was built with a number of known and common vulnerabilities. This allows users to attempt real exploits against a web application and thus learn the specifics of the issue and how best to fix it. The web services exposed by Hacme Bank are used by our other testing applications including Hacme Books and Hacme Travel.

Hacme Bank is .NET-based and uses Microsoft IIS so ModSecurity would have to be deployed in a reverse proxy configuration.

3. Implement security event logging as a ModSecurity:

The lack of security logging in an application can make it difficult to trace security breaches and violations of security policy. Get Ken van Wyk's take on this at xx:xx to of Cigital's Silver Bullet podcast #30 (http://www.cigital.com/silverbullet/show-030/) with Gary McGraw. To quote:

The steps would be: 1. Identify areas of an application that require security events. 2. Write traditional ModSecurity rules for these events and write to the audit log file. 3. Write Lua scripts that, if possible, modify existing log files written by other applications; or, that write to a new, standalone file in a different format that integrates with other log file formats that are used by other ecosystems.

Contributors
Project team: Stephen Evans

1st reviewer: Ivan Ristic (Curriculum) & Breach Research Labs (Ryan Barnett, Brian Rectanus)

2nd reviewer: Christian Folini (Curriculum)

Special thanks go out to the reviewers for graciously volunteering their time for this project.

Other contributors:
 * Dinis Cruz, who sculpted the original project proposal into something useful.
 * Paulo Coimbra, who exhibits extreme patience in his dealings with the project team.
 * Bruce Mayhew of the OWASP WebGoat project.