Many modern applications are developed on frameworks. These frameworks provide the developer less work to do as the framework does much of the “Housekeeping”. So the objects developed by the development team shall extend the functionality of the framework. '''It is here that the knowledge of a given framework, and language in which the framework and application is implemented, is of paramount importance.''' Much of the transactional functionality may not be visible in the developer’s code and handled in “Parent” classes.

+

Many modern applications are developed on frameworks. These frameworks provide the developer less work to do as the framework does much of the “Housekeeping”. So the objects developed by the development team shall extend the functionality of the framework. '''It is here that the knowledge of a given framework, and language in which the framework and application is implemented, is of paramount importance.''' Much of the transactional functionality may not be visible in the developer’s code and handled in “Parent” classes.

The analyst must be aware and knowledgeable of the underlying framework.

The analyst must be aware and knowledgeable of the underlying framework.

Revision as of 08:37, 9 January 2009

Understanding the Attack Surface

“For every input there will be an equal and opposite output (Well sort of)”

A major part of actually performing a security code review is performing an analysis of the attack surface. An application takes inputs and produces output of some kind. Attacking applications is down to using the streams for input and trying to sail a battleship up them that the application is not expecting. Firstly, all input to the code needs to be identified. Input, for example, can be:

Browser input

Cookies

Property files

External processes

Data feeds

Service responses

Flat files

Command line parameters

Environment variables

Exploring the attack surface includes dynamic and static data flow analysis: Where and when are variables set and how the variables are used throughout the workflow, how attributes of objects and parameters might affect other data within the program. It determines if the parameters, method calls, and data exchange mechanisms implement the required security.

All transactions within the application need to be identified and analyzed along with the relevant security functions they invoke. The areas that are covered during transaction analysis are:

Data/Input Validation of data from all untrusted sources.

Authentication

Session Management

Authorization

Cryptography (Data at rest and in transit)

Error Handling /Information Leakage

Logging /Auditing

Secure Code Environment

Understand What You Are Reviewing

Many modern applications are developed on frameworks. These frameworks provide the developer less work to do as the framework does much of the “Housekeeping”. So the objects developed by the development team shall extend the functionality of the framework. It is here that the knowledge of a given framework, and language in which the framework and application is implemented, is of paramount importance. Much of the transactional functionality may not be visible in the developer’s code and handled in “Parent” classes.

The analyst must be aware and knowledgeable of the underlying framework.

For example:

Java:

In struts the struts-config.xml and the web.xml files are the core points to view the transactional functionality of an application.

Understand what you are reviewing:

Many modern applications are developed on frameworks. These frameworks provide the developer less work to do as the framework does much of the “House Keeping”. So the objects developed by the development team shall extend the functionality of the framework.
It is here that the knowledge of a given framework and language which the framework and application is implemented in, is of paramount importance. Much of the transactional functionality may not be visible in the developers code and handled in “Parent” classes.

The analyst must be aware and knowledgeable of the underlying framework

For example:

Java:

In struts the struts-config.xml and the web.xml files are the core points to view the transactional functionality of an application.

The struts-config.xml file contains the action mappings for each HTTP request while the web.xml file contains the deployment descriptor.

Example: The struts framework has a validator engine, which relies on regular expressions to validate the input data. The beauty of the validator is that no code has to be written for each form bean. (Form bean is the java object which received the data from the HTTP request) . The validator is not enabled by default in struts. To enable the validator a plug-in must be defined in the <plug-in> section of struts-config.xml in Red above. The property defined tells the struts framework where the custom validation rules are defined (validation.xml) and a definition of the actual rules themselves (validation-rules.xml).

Without a proper understanding of the struts framework and by simply auditing the Java code one would not see any validation being executed and one does not see the relationship between the defined rules and the java functions.

The action mappings in Blue define the action taken by the application upon receiving a request. Here we can see that when the URL contains the path "/login", the LoginAction shall be called. From the action mappings we can see the transactions the application performs when external input is received.

Without knowledge of these files a transactional analysis would be very difficult and not accurate.

Optionally, you may provide a file web.config at the root of the virtual directory for a web application. If the file is absent, the default configuration settings in machine.config will be used. If the file is present, any settings in web.config will override the default settings.

loginUrl: Specifies the URL where the request is redirected for logon if no valid authentication cookie is found.

protection: Specifies that the cookie is encrypted using 3DES or DES, but data validation is not performed on the cookie. Beware of plaintext attacks!!

timeout: Cookie expiry time in minutes

The point to make here is that many of the important security settings are not set in the code per se but in the framework configuration files.
Knowledge of the framework is of paramount importance when reviewing framework-based applications.