Server Side Include (SSI) Injection
Attack Pattern ID: 101 (Standard Attack Pattern Completeness: Complete)Typical Severity: HighStatus: Draft
+ Description

Summary

An attacker can use Server Side Include (SSI) Injection to send code to a web application that then gets executed by the web server. Doing so enables the attacker to achieve similar results to Cross Site Scripting, viz., arbitrary code execution and information disclosure, albeit on a more limited scale, since the SSI directives are nowhere near as powerful as a full-fledged scripting language. Nonetheless, the attacker can conveniently gain access to sensitive files, such as password files, and execute shell commands.

Attack Execution Flow

Explore
  1. Determine applicability:

    The attacker determines whether server side includes are enabled on the target web server.

    Attack Step Techniques

    IDAttack Step Technique DescriptionEnvironments
    1

    Look for popular page file names. The attacker will look for .shtml, .shtm, .asp, .aspx, and other well known strings in URLs to help determine whether SSI functionality is enabled.

    env-Web
    2

    Fetch .htaccess file. In Apache web server installations, the .htaccess file may enable server side includes in specific locations. In those cases, the .htaccess file lives inside the directory where SSI is enabled, and is theoretically fetchable from the web server. Although most web servers deny fetching the .htaccess file, a misconfigured server will allow it. Thus, an attacker will frequently try it.

    env-Web

    Indicators

    IDtypeIndicator DescriptionEnvironments
    1Positive

    If .htaccess files are used, their contents should be checked for "Options Includes" or "Options IncludesNOEXEC".

    env-Web
    2Positive

    If apache is used, the contents of the httpd.conf file and similar configuration files should be checked for "Options Includes" or "Options IncludesNOEXEC".

    env-Web
    3Positive

    IIS configurations contain server-side include compatibility.

    env-Web
    4Inconclusive

    Web pages that include mundane, but dynamic information (like the current date, a file's size, or some other data that SSI can produce) might be producing that content through SSI.

    env-Web

    Security Controls

    IDtypeSecurity Control Description
    1Preventative
    Adding "AllowOverrides none" to the main httpd.conf file on an server (and the similar restrictions in other application servers) can prevent unexpected loosening of SSI functionality, even by internal developers.
  2. Attempt SSI:

    Look for user controllable input, including HTTP headers, that can carry server side include directives to the web server

    Attack Step Techniques

    IDAttack Step Technique DescriptionEnvironments
    1

    Use a spidering tool to follow and record all links. Make special note of any links that include parameters in the URL.

    env-Web
    2

    Use a proxy tool to record all links visited during a manual traversal of the web application. Make special note of any links that include parameters in the URL. Manual traversal of this type is frequently necessary to identify forms that are GET method forms rather than POST forms.

    env-Web

    Indicators

    IDtypeIndicator DescriptionEnvironments
    1Positive

    URL parameters are used.

    env-Web
    2Inconclusive

    No parameters appear on the URL. Even though none appear, the web application may still use them if they are provided.

    env-Web

    Outcomes

    IDtypeOutcome Description
    1Success
    A list of URLs, with their corresponding parameters is created by the attacker.

    Security Controls

    IDtypeSecurity Control Description
    1Detective
    Monitor velocity of page fetching in web logs. Humans who view a page and select a link from it will click far slower and far less regularly than tools. Tools make requests very quickly and the requests are typically spaced apart regularly (e.g. 0.8 seconds between them).
    2Detective
    Create links on some pages that are visually hidden from web browsers. Using IFRAMES, images, or other HTML techniques, the links can be hidden from web browsing humans, but visible to spiders and programs. A request for the page, then, becomes a good predictor of an automated tool probing the application.
    3Preventative
    Actively monitor the application and either deny or redirect requests from origins that appear to be automated.
  3. SecurityDatabase\Alert\Inject SSI:

    The attacker may then need to view a particular page in order to have the server execute the include directive and run a command or open a file on behalf of the attacker

    Outcomes

    IDtypeOutcome Description
    1Success
    The attacker views data (perhaps from a file) that he normally should not see.
    2Success
    The attacker executes a command on the server, or influences the arguments to a command executed via SSI on the server.
+ Attack Prerequisites

A web server that supports server side includes and has them enabled

User controllable input that can carry include directives to the web server

+ Typical Likelihood of Exploit

Likelihood: Very High

It is fairly easy to determine whether server-side includes are permitted on the target server. An attacker can potentially glean a lot of information if SSI Injection were found to be possible.

+ Methods of Attack
  • Injection
  • Protocol Manipulation
+ Examples-Instances

Description

Consider a website hosted on a server that permits Server Side Includes (SSI), such as Apache with the "Options Includes" directive enabled.

Whenever an error occurs, the HTTP Headers along with the entire request are logged, which can then be displayed on a page that allows review of such errors. A malicious user can inject SSI directives in the HTTP Headers of a request designed to create an error.

When these logs are eventually reviewed, the server parses the SSI directives and executes them.

+ Attacker Skills or Knowledge Required

Skill or Knowledge Level: Medium

The attacker needs to be aware of SSI technology, determine the nature of injection and be able to craft input that results in the SSI directives being executed.

+ Resources Required

None: Determining whether the server supports SSI does not require special tools, and nor does injecting directives that get executed.

+ Probing Techniques

The attacker can probe for enabled SSI by injecting content that can be interpreted as SSI directives and viewing the page output

+ Solutions and Mitigations

Set the OPTIONS IncludesNOEXEC in the global access.conf file or local .htaccess (Apache) file to deny SSI execution in directories that do not need them

All user controllable input must be appropriately sanitized before use in the application. This includes omitting, or encoding, certain characters or strings that have the potential of being interpreted as part of an SSI directive

Server Side Includes must be enabled only if there is a strong business reason to do so. Every additional component enabled on the web server increases the attack surface as well as administrative overhead

+ Attack Motivation-Consequences
  • Information Leakage
  • Run Arbitrary Code
+ Injection Vector

User controllable input

+ Payload

SSI directives that can cause disclosure of file contents or execution of commands

+ Activation Zone

The web server that parses and executes SSI directives before rendering the HTML page

+ Payload Activation Impact

The SSI directives cause the inclusion of certain file's contents or the execution of a shell command, as directed by the attacker

+ Related Weaknesses
CWE-IDWeakness NameWeakness Relationship Type
97Failure to Sanitize Server-Side Includes (SSI) Within a Web PageTargeted
74Failure to Sanitize Data into a Different Plane ('Injection')Secondary
20Improper Input ValidationSecondary
713OWASP Top Ten 2007 Category A2 - Injection FlawsSecondary
+ Related Attack Patterns
NatureTypeIDNameDescriptionView(s) this relationship pertains toView\(s\)
ChildOfCategoryCategory253Remote Code Inclusion 
Mechanism of Attack (primary)1000
ChildOfCategoryCategory369WASC Threat Classification 2.0 - WASC-36 - SSI Injection 
WASC Threat Classification 2.0333
+ Related Security Principles
  • Reluctance To Trust

  • Complete Mediation

+ Related Guidelines
  • Never Use Unvalidated Input as Part of a Directive to any Internal Component

+ Purposes
  • Penetration
  • Exploitation
+ CIA Impact
Confidentiality Impact: HighIntegrity Impact: HighAvailability Impact: High
+ Technical Context
Architectural Paradigms
Client-Server
SOA
Frameworks
All
Platforms
All
Languages
All
PHP
+ Content History
Submissions
SubmitterDateComments
Chiradeep B. Chhaya2007-04-20First Draft
Modifications
ModifierOrganizationDateComments
Sean BarnumCigital, Inc2007-04-20Review and revision of content