CAPEC

Common Attack Pattern Enumeration and Classification
Common Attack Pattern Enumeration and Classification

A Community Knowledge Resource for Building Secure Software

Home > CAPEC List > Individual CAPEC Dictionary Definition (Release 1.1)   View the CAPEC List

Individual CAPEC Dictionary Definition (Release 1.1)
Individual CAPEC Dictionary Definition (Release 1.1)

Buffer Overflow via Environment Variables
Attack Pattern ID
Pattern Abstraction: Detailed

10

Typical Severity

High

Description

Summary


This attack pattern involves causing a buffer overflow through manipulation of environment variables. Once the attacker finds that they can modify an environment variable, they may try to overflow associated buffers. This attack leverages implicit trust often placed in environment variables.

Attack Execution Flow

  1. 1- The attacker tries to find an environment variable which can be overwritten for instance by gathering information about the target host (error pages, software's version number, etc.).

  2. 2- The attacker manipulates the environment variable to contain excessive-length content to cause a buffer overflow.

  3. 3- The attacker potentially leverages the buffer overflow to inject maliciously crafted code in an attempt to execute privileged command on the target environment.

Attack Prerequisites

The application uses environment variables.

An environment variable exposed to the user is vulnerable to a buffer overflow.

The vulnerable environment variable uses untrusted data.

Tainted data used in the environment variables is not properly validated. For instance boundary checking is not done before copying the input data to a buffer.

Typical Likelihood of Exploit

High

Methods of Attack
  • Injection
Examples-Instances

Description

Attack Example: Buffer Overflow in $HOME

A buffer overflow in sccw allows local users to gain root access via the $HOME environmental variable.

Related Vulnerability

CVE-1999-0906

Description

Attack Example: Buffer Overflow in TERM

A buffer overflow in the rlogin program involves its consumption of the TERM environmental variable.

Related Vulnerability

CVE-1999-0046

Attacker Skill or Knowledge Required

Low : An attacker can simply overflow a buffer by inserting a long string into an attacker-modifiable injection vector. The result can be a DoS. High : Exploiting a buffer overflow to inject malicious code into the stack of a software system or even the heap can require a higher skill level.

Probing Techniques

While interacting with a system an attacker would typically investigate for environment variables that can be overwritten. The more a user knows about a system the more likely she will find a vulnerable environment variable.

On a web environment, the attacker can read the client side code and search for environment variables that can be overwritten.

There are tools such as Sharefuzz (http://sharefuzz.sourceforge.net/) which is an environment variable fuzzer for Unix that support loading a shared library. Attackers can use such tools to uncover a buffer overflow in an environment variable.

Indicators-Warnings of Attack

If the application does bound checking, it should fail when the data source is larger than the size of the destination buffer. If the application's code is well written, that failure should triger an alert.

Obfuscation Techniques

Solutions and Mitigations

Do not expose environment variable to the user.

Do not use untrusted data in your environment variables.

Use a language or compiler that performs automatic bounds checking

There are tools such as Sharefuzz (http://sharefuzz.sourceforge.net/) which is an environment variable fuzzer for Unixes that support loading a shared library. You can use Sharefuzz to determine if you are exposing an environment variable vulnerable to buffer overflow.

Attack Motivation-Consequences
  • Denial of Service
  • Run Arbitrary Code
  • Information Leakage
  • Data Modification
  • Privilege Escalation
Injection Vector

The user modifiable environment variable.

Payload

User supplied data potentially containing malicious code.

Activation Zone

When the subroutine which uses the environment variable returns control to the main program, it jumps to the return address portion of the stack frame. Unfortunately that return address may have been overwritten by the overflowed buffer and the address may contain a call to a privileged command or to a malicious code.

Payload Activation Impact

The most common is remote code execution.

Related Weaknesses
CWE-IDWeakness NameWeakness Relationship Type
120Unbounded Transfer ('Classic Buffer Overflow')Targeted
302Authentication Bypass by Assumed-Immutable DataTargeted
118Range ErrorsTargeted
119Failure to Constrain Operations within the Bounds of an Allocated Memory BufferTargeted
74Failure to Sanitize Data into a Different Plane (aka 'Injection')Targeted
99Insufficient Control of Resource Identifiers (aka 'Resource Injection')Targeted
20Insufficient Input ValidationTargeted
Related Attack Patterns
IDNameRelationship TypeRelationship Description
100Overflow BuffersMore Detailed
Related Security Principles
  • Reluctance to trust
Related Guidelines
  • Bound checking should be performed when copying data to a buffer.
Purpose

Penetration

CIA Impact
Confidentiality ImpactIntegrity ImpactAvailability Impact
HighHighHigh
Technical Context
Architectural ParadigmFrameworkPlatformLanguage
AllAllAllAll
References

G. Hoglund and G. McGraw. Exploiting Software: How to Break Code. Addison-Wesley, February 2004.

CWE – Buffer Errors

Source
Submission(s)
SubmitterOrganizationDateComment
G. Hoglund and G. McGraw. Exploiting Software: How to Break Code. Addison-Wesley, February 2004.Cigital, Inc2007-03-01
Modification(s)
ModifierOrganizationDateComment
Eric DalciCigital, Inc2007-02-13Fleshed out content to CAPEC schema from the original descriptions in "Exploiting Software"
Sean BarnumCigital, Inc2007-03-05Review and revise
Richard StruseVOXEM, Inc2007-03-26Review and feedback leading to changes in Name
Sean BarnumCigital, Inc2007-04-13Modified pattern content according to review and feedback
 
Page Last Updated: April 18, 2008