Overview

The purpose of the OWASP Stinger manual is to provide users a comprehensive guide to developing upon and deploying the OWASP J2EE Stinger filter. If you have any comments or suggestions concerning the Stinger manual, please to not hesitate to email me at eric.sheridan@owasp.org.

Development

Deployment

Fetch the Latest Files

The latest Stinger release can be downloaded here. The user implementing Stinger should download the jar file into a directory accessible by the Java container. For example, deploying Stinger in Tomcat would require downloading the files in the WEB-INF/lib/ directory.

Configure Deployment Descriptor

There are two major pieces of information necessary to deploy Stinger in your J2EE environment. First, the Java container must be told to implement the Stinger J2EE filter. This is specified in the web.xml file via the following:

Stinger 2.x accepts three filter parameters: config, error-page, and reload. The config parameter tells the Stinger filter the location of the SVDL file. The error-page parameter is actually the result of a new feature in Stinger 2.x. All exceptions that are thrown from the web application are now caught in Stinger. This prevents sending exceptions to the client and potentially revealing sensitive information (think database exceptions). Instead of leaking sensitive information, Stinger simply redirects the client to a specified page upon catching an exception. The third parameter, reload, tells Stinger whether to dynamically load the SVDL file for each incoming HTTP request. As a rule of thumb, set reload to true in testing environments and false for production environments.

The second major piece of information dictates which requests should pass the Stinger J2EE filter. This is specified in the web.xml file via the following:

This entry tells the J2EE container that every request handled by the container should pass through the Stinger filter.

Configure Your SVDL File

A template SVDL file for the latest Stinger release can be found here. The SVDL file is broken down into three sections.

The Regular Expression Section

The Cookie Rule Section

The Parameter Rule Section

The Regular Expression Section

All regular expressions to be used in Stinger are defined in this section. Essentially, a regular expression entry is comprised of a name, a regular expression, and a description. The description element is for user readability and is not used within Stinger. The regular expressions equiped with Stinger were taken from the OWASP RegEx Repository. If you have custom regular expressions and would like to donate them to the Stinger project, please email me at eric.sheridan@owasp.org.

The Cookie Rule Section

This section contains definitions for all of the cookies for which we are assigning a rule. A cookie rule is comprised of a name, a regular expression, the URI in which it is created, the URI's which it is enforced, and the actions taken if the cookie is missing or malformed. For most web applications, we wish to create and enforce a cookie for a particular URI. In this case, we have an entry similar to the one found below. In this case the following rule applies: if a cookie is missing from the request sent to the created/enforced URI, then no violation occurs. However, if a cookies is malformed in the request sent to the created/enforced URI, then a violation occurs.

The missing and malformed sections simply specify the severity of the violation as well as the actions to be executed. There exists three possible severities: FATAL, CONTINUE, and IGNORE.

If a severity is FATAL, then Stinger stops processing the packet and immediately executes the associated actions.

If a severity is CONTINUE, then Stinger appends the violation a list and continues to process the packet.

If a severity is IGNORE, no violation is appended to the list of violation and Stinger continues its request validation.

Several actions accept parameters which are designated by the <parameter> tag.

The Parameter Section

The parameter section describes the parameter rules associated with a particular URI. A URI and its associated rules constitute a rule set. Every SVDL implementation must contain a default rule set similar to the following:

A default Stinger rule set must have the path (the URI) set to STINGER_DEFAULT and the rule name set to STINGER_ALL. When a request to a URI without an associated rule set is submitted, the default rule set is utilized. When a parameter without an associated rule is sent to the application, then the default rules are utilized.

The following is a sample rule set entry for a fictitious web application:

Although this entry is quite large, there are only a few new entries which must be noted. As we see, this rule set utilizes a regular expression which is intended to cover the following URIs:

/Stinger-2.4

/Stinger-2.4/

/Stinger-2.4/index.jsp.

For this rule set, we have specified two rules, each describing a parameter accepted by the web application. These two parameters, username and hidden1, have very similar entries to that of the cookie rules. Each parameter has an associated regular expression, a missing section, and a malformed section.

Important SVDL Rules/Guidelines

When creating your own SVDL file, please remember the
following rules/guidelines:

Defaults:

Stinger assumes there will always exist a default rule set

Requested URI's without a rule set will use the default rule set

Parameters without an associated rule will use the default rule

Cookies:

You must specify a created page for a cookie rule

If a cookie is missing on the created page, then no violation

If a cookie is malformed on the created page, then violation

You must specify at least one enforced uri per cookie rule

You can specify more than one enforced uri per cookie rule

Rule Sets:

There must exist at least one path per rule set.

There can exist multiple paths for a single rule set.

Actions:

Order actions carefully and appropriately. Ex. You cannot drop a packet and then display a message.

Several actions accept parameters. They must be defined

SVDL Learner Filter

A project is underway to create a J2EE filter which generates an SVDL file based on captured HTTP traffic. The learner filter will behave similar to that of the SVDL Generator filter whereby parameters without an associated rule will be colored red. The learner filter will then look for a user-submitted value for that parameter and build an appropriate rule with default missing and malformed actions. When the user is finished crawling the site, the J2EE container is shut down and the Learner filter writes the rules to disk. The learner filter is considered developmental, yet it is included in the Stinger 2.x releases.

reload - specifies whether the SVDL should be dynamically loaded at runtime

Apply Stinger to a URI Pattern

Configure the SVDL for your application

Actions

Stinger is an action based input validation engine. The user can specify actions to be taken place upon violations found in an HTTP request. The following section describes how the actions are implemented as well as the parameters they accept. One major goal of this section is to illustrate the simplicity of creating Stinger actions. If you have created a custom action and are interested in submitting it to the Stinger project, please email me at eric.sheridan@owasp.org.

AbstractAction

Description

Developing your own action is relatively straight forward within Stinger. To implement a custom class, simply extend the AbstractAction class and implement the abstract doAction method. For more information related to building custom actions, please refer to the development section.

Invalidate

Description

If the session object exists, then it will be invalidated by this action. This action is considered more severe and should be deployed only when an obvious attack occurs. For example, cookie values are rarely tampered with by the client side code (i.e. javascript). Therefore, we can (safely?) assume that any cookie modification is considered a deliberate attack.

Log

Description

As the name implies, we can log any and every request sent to the web application. The Log action is an essential action and should be heavily implemented in Stinger deployment.

Parameters

The Log action currently accepts 3 parameters:

log - the log file where the message should be recorded

level - the level of the log message (i.e. INFO, SEVERE, etc.)

message - the message which shall be logged. The message parameter itself accepts 3 format parameters.
These include the offender's ip address, the offender's remote port, the parameter/cookie name,
the parameter/cookie value, an entity encoded version of the parameter/cookie value, and the JSESSIONID.
The format strings are %ip, %port, %name, %value, %encoded_value, and %js respectively.
limit - the limit of the log file size
count - the maximum number of log files to use
append - specifies append mode (true/false)

Encode all Input

This SVDL configuration encodes all parameters in the HTTP request. By entity encoding all parameter-based user input, we significantly reduce the likelihood of certain forms of Cross Site Scripting and SQL Injection attacks.

Encode all Input and Log All Violations

This SVDL configuration encodes all parameters in the HTTP request and logs all violations that may occur. As a result, we significantly reduce the likelihood of certain input validation attacks and we have a logging mechanism to detect and verifies these attacks.

Encode all Input for a Particular URI

This SVDL configuration encodes all parameters in the HTTP request that are sent to a specific set of URI's. If a malformed parameter is sent to another URI not listed in our rule, then the global rule handles the packet. Since the global rule does nothing, the malformed data will be accepted.