Category Archives: CWE

CWE-834 – Excessive Iteration

Read Time:1 Minute, 6 Second

Description

The software performs an iteration or loop without sufficiently limiting the number of times that the loop is executed.

If the iteration can be influenced by an attacker, this weakness could allow attackers to consume excessive resources such as CPU or memory. In many cases, a loop does not need to be infinite in order to cause enough resource consumption to adversely affect the software or its host system; it depends on the amount of resources consumed per iteration.

Modes of Introduction:

Likelihood of Exploit:

 

Related Weaknesses

CWE-691

 

Consequences

Availability: DoS: Resource Consumption (CPU), DoS: Resource Consumption (Memory), DoS: Amplification, DoS: Crash, Exit, or Restart

Excessive looping will cause unexpected consumption of resources, such as CPU cycles or memory. The software’s operation may slow down, or cause a long time to respond. If limited resources such as memory are consumed for each iteration, the loop may eventually cause a crash or program exit due to exhaustion of resources, such as an out-of-memory error.

 

Potential Mitigations

CVE References

 

  • CVE-2011-1027
    • Chain: off-by-one error leads to infinite loop using invalid hex-encoded characters.
  • CVE-2006-6499
    • Chain: web browser crashes due to infinite loop – “bad
      looping logic [that relies on] floating point math [CWE-1339] to exit
      the loop [CWE-835]”

CWE-835 – Loop with Unreachable Exit Condition (‘Infinite Loop’)

Read Time:1 Minute, 27 Second

Description

The program contains an iteration or loop with an exit condition that cannot be reached, i.e., an infinite loop.

If the loop can be influenced by an attacker, this weakness could allow attackers to consume excessive resources such as CPU or memory.

Modes of Introduction:

Likelihood of Exploit:

 

Related Weaknesses

CWE-834
CWE-834

 

Consequences

Availability: DoS: Resource Consumption (CPU), DoS: Resource Consumption (Memory), DoS: Amplification

An infinite loop will cause unexpected consumption of resources, such as CPU cycles or memory. The software’s operation may slow down, or cause a long time to respond.

 

Potential Mitigations

CVE References

 

  • CVE-2011-1027
    • Chain: off-by-one error leads to infinite loop using invalid hex-encoded characters.
  • CVE-2011-1142
    • Chain: self-referential values in recursive definitions lead to infinite loop.
  • CVE-2011-1002
    • NULL UDP packet is never cleared from a queue, leading to infinite loop.
  • CVE-2006-6499
    • Chain: web browser crashes due to infinite loop – “bad
      looping logic [that relies on] floating point math [CWE-1339] to exit
      the loop [CWE-835]”
  • CVE-2010-4476
    • Floating point conversion routine cycles back and forth between two different values.
  • CVE-2010-4645
    • Floating point conversion routine cycles back and forth between two different values.
  • CVE-2010-2534
    • Chain: improperly clearing a pointer in a linked list leads to infinite loop.
  • CVE-2013-1591
    • Chain: an integer overflow (CWE-190) in the image size calculation causes an infinite loop (CWE-835) which sequentially allocates buffers without limits (CWE-1325) until the stack is full.
  • CVE-2008-3688
    • Chain: A denial of service may be caused by an uninitialized variable (CWE-457) allowing an infinite loop (CWE-835) resulting from a connection to an unresponsive server.

CWE-786 – Access of Memory Location Before Start of Buffer

Read Time:1 Minute, 39 Second

Description

The software reads or writes to a buffer using an index or pointer that references a memory location prior to the beginning of the buffer.

This typically occurs when a pointer or its index is decremented to a position before the buffer, when pointer arithmetic results in a position before the beginning of the valid memory location, or when a negative index is used.

Modes of Introduction:

Likelihood of Exploit:

 

Related Weaknesses

CWE-119
CWE-119
CWE-119

 

Consequences

Confidentiality: Read Memory

For an out-of-bounds read, the attacker may have access to sensitive information. If the sensitive information contains system details, such as the current buffers position in memory, this knowledge can be used to craft further attacks, possibly with more severe consequences.

Integrity, Availability: Modify Memory, DoS: Crash, Exit, or Restart

Out of bounds memory access will very likely result in the corruption of relevant memory, and perhaps instructions, possibly leading to a crash.

Integrity: Modify Memory, Execute Unauthorized Code or Commands

If the corrupted memory can be effectively controlled, it may be possible to execute arbitrary code. If the corrupted memory is data rather than instructions, the system will continue to function with improper changes, possibly in violation of an implicit or explicit policy.

 

Potential Mitigations

CVE References

 

  • CVE-2002-2227
    • Unchecked length of SSLv2 challenge value leads to buffer underflow.
  • CVE-2007-4580
    • Buffer underflow from a small size value with a large buffer (length parameter inconsistency, CWE-130)
  • CVE-2007-1584
    • Buffer underflow from an all-whitespace string, which causes a counter to be decremented before the buffer while looking for a non-whitespace character.
  • CVE-2007-0886
    • Buffer underflow resultant from encoded data that triggers an integer overflow.
  • CVE-2006-6171
    • Product sets an incorrect buffer size limit, leading to “off-by-two” buffer underflow.
  • CVE-2006-4024
    • Negative value is used in a memcpy() operation, leading to buffer underflow.
  • CVE-2004-2620
    • Buffer underflow due to mishandled special characters

CWE-787 – Out-of-bounds Write

Read Time:2 Minute, 42 Second

Description

The software writes data past the end, or before the beginning, of the intended buffer.

Typically, this can result in corruption of data, a crash, or code execution. The software may modify an index or perform pointer arithmetic that references a memory location that is outside of the boundaries of the buffer. A subsequent write operation then produces undefined or unexpected results.

Modes of Introduction:

– Implementation

Likelihood of Exploit: High

 

Related Weaknesses

CWE-119
CWE-119
CWE-119
CWE-119

 

Consequences

Integrity, Availability: Modify Memory, DoS: Crash, Exit, or Restart, Execute Unauthorized Code or Commands

 

Potential Mitigations

Phase: Requirements

Effectiveness:

Description: 

Phase: Architecture and Design

Effectiveness:

Description: 

This is not a complete solution, since many buffer overflows are not related to strings.

Phase: Build and Compilation

Effectiveness: Defense in Depth

Description: 

This is not necessarily a complete solution, since these mechanisms can only detect certain types of overflows. In addition, an attack could still cause a denial of service, since the typical response is to exit the application.

Phase: Implementation

Effectiveness:

Description: 

Phase: Operation

Effectiveness: Defense in Depth

Description: 

This is not a complete solution. However, it forces the attacker to guess an unknown value that changes every program execution. In addition, an attack could still cause a denial of service, since the typical response is to exit the application.

Phase: Operation

Effectiveness: Defense in Depth

Description: 

Use a CPU and operating system that offers Data Execution Protection (NX) or its equivalent [REF-60] [REF-61].

This is not a complete solution, since buffer overflows could be used to overwrite nearby variables to modify the software’s state in dangerous ways. In addition, it cannot be used in cases in which self-modifying code is required. Finally, an attack could still cause a denial of service, since the typical response is to exit the application.

Phase: Implementation

Effectiveness: Moderate

Description: 

Replace unbounded copy functions with analogous functions that support length arguments, such as strcpy with strncpy. Create these if they are not available.

This approach is still susceptible to calculation errors, including issues such as off-by-one errors (CWE-193) and incorrectly calculating buffer lengths (CWE-131).

CVE References

 

  • CVE-2020-0022
    • chain: mobile phone Bluetooth implementation does not include offset when calculating packet length (CWE-682), leading to out-of-bounds write (CWE-787)
  • CVE-2019-1010006
    • Chain: compiler optimization (CWE-733) removes or modifies code used to detect integer overflow (CWE-190), allowing out-of-bounds write (CWE-787).
  • CVE-2009-1532
    • malformed inputs cause accesses of uninitialized or previously-deleted objects, leading to memory corruption
  • CVE-2009-0269
    • chain: -1 value from a function call was intended to indicate an error, but is used as an array index instead.
  • CVE-2002-2227
    • Unchecked length of SSLv2 challenge value leads to buffer underflow.
  • CVE-2007-4580
    • Buffer underflow from a small size value with a large buffer (length parameter inconsistency, CWE-130)
  • CVE-2007-4268
    • Chain: integer signedness error (CWE-195) passes signed comparison, leading to heap overflow (CWE-122)
  • CVE-2009-2550
    • Classic stack-based buffer overflow in media player using a long entry in a playlist
  • CVE-2009-2403
    • Heap-based buffer overflow in media player using a long entry in a playlist

CWE-788 – Access of Memory Location After End of Buffer

Read Time:1 Minute, 53 Second

Description

The software reads or writes to a buffer using an index or pointer that references a memory location after the end of the buffer.

This typically occurs when a pointer or its index is incremented to a position after the buffer; or when pointer arithmetic results in a position after the buffer.

Modes of Introduction:

Likelihood of Exploit:

 

Related Weaknesses

CWE-119
CWE-119
CWE-119

 

Consequences

Confidentiality: Read Memory

For an out-of-bounds read, the attacker may have access to sensitive information. If the sensitive information contains system details, such as the current buffers position in memory, this knowledge can be used to craft further attacks, possibly with more severe consequences.

Integrity, Availability: Modify Memory, DoS: Crash, Exit, or Restart

Out of bounds memory access will very likely result in the corruption of relevant memory, and perhaps instructions, possibly leading to a crash. Other attacks leading to lack of availability are possible, including putting the program into an infinite loop.

Integrity: Modify Memory, Execute Unauthorized Code or Commands

If the memory accessible by the attacker can be effectively controlled, it may be possible to execute arbitrary code, as with a standard buffer overflow. If the attacker can overwrite a pointer’s worth of memory (usually 32 or 64 bits), they can redirect a function pointer to their own malicious code. Even when the attacker can only modify a single byte arbitrary code execution can be possible. Sometimes this is because the same problem can be exploited repeatedly to the same effect. Other times it is because the attacker can overwrite security-critical application-specific data — such as a flag indicating whether the user is an administrator.

 

Potential Mitigations

CVE References

 

  • CVE-2009-2550
    • Classic stack-based buffer overflow in media player using a long entry in a playlist
  • CVE-2009-2403
    • Heap-based buffer overflow in media player using a long entry in a playlist
  • CVE-2009-0689
    • large precision value in a format string triggers overflow
  • CVE-2009-0558
    • attacker-controlled array index leads to code execution
  • CVE-2008-4113
    • OS kernel trusts userland-supplied length value, allowing reading of sensitive information
  • CVE-2007-4268
    • Chain: integer signedness error (CWE-195) passes signed comparison, leading to heap overflow (CWE-122)

CWE-789 – Memory Allocation with Excessive Size Value

Read Time:1 Minute, 25 Second

Description

The product allocates memory based on an untrusted, large size value, but it does not ensure that the size is within expected limits, allowing arbitrary amounts of memory to be allocated.

Modes of Introduction:

– Implementation

Likelihood of Exploit:

 

Related Weaknesses

CWE-770
CWE-1284
CWE-476

 

Consequences

Availability: DoS: Resource Consumption (Memory)

Not controlling memory allocation can result in a request for too much system memory, possibly leading to a crash of the application due to out-of-memory conditions, or the consumption of a large amount of memory on the system.

 

Potential Mitigations

Phase: Implementation, Architecture and Design

Effectiveness:

Description: 

Perform adequate input validation against any value that influences the amount of memory that is allocated. Define an appropriate strategy for handling requests that exceed the limit, and consider supporting a configuration option so that the administrator can extend the amount of memory to be used if necessary.

Phase: Operation

Effectiveness:

Description: 

Run your program using system-provided resource limits for memory. This might still cause the program to crash or exit, but the impact to the rest of the system will be minimized.

CVE References

 

  • CVE-2010-3701
    • program uses ::alloca() for encoding messages, but large messages trigger segfault
  • CVE-2008-1708
    • memory consumption and daemon exit by specifying a large value in a length field
  • CVE-2008-0977
    • large value in a length field leads to memory consumption and crash when no more memory is available
  • CVE-2006-3791
    • large key size in game program triggers crash when a resizing function cannot allocate enough memory
  • CVE-2004-2589
    • large Content-Length HTTP header value triggers application crash in instant messaging application due to failure in memory allocation

CWE-79 – Improper Neutralization of Input During Web Page Generation (‘Cross-site Scripting’)

Read Time:5 Minute, 30 Second

Description

The software does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.

Modes of Introduction:

– Architecture and Design

Likelihood of Exploit: High

 

Related Weaknesses

CWE-74
CWE-74
CWE-494
CWE-352

 

Consequences

Access Control, Confidentiality: Bypass Protection Mechanism, Read Application Data

The most common attack performed with cross-site scripting involves the disclosure of information stored in user cookies. Typically, a malicious user will craft a client-side script, which — when parsed by a web browser — performs some activity (such as sending all site cookies to a given E-mail address). This script will be loaded and run by each user visiting the web site. Since the site requesting to run the script has access to the cookies in question, the malicious script does also.

Integrity, Confidentiality, Availability: Execute Unauthorized Code or Commands

In some circumstances it may be possible to run arbitrary code on a victim’s computer when cross-site scripting is combined with other flaws.

Confidentiality, Integrity, Availability, Access Control: Execute Unauthorized Code or Commands, Bypass Protection Mechanism, Read Application Data

The consequence of an XSS attack is the same regardless of whether it is stored or reflected. The difference is in how the payload arrives at the server. XSS can cause a variety of problems for the end user that range in severity from an annoyance to complete account compromise. Some cross-site scripting vulnerabilities can be exploited to manipulate or steal cookies, create requests that can be mistaken for those of a valid user, compromise confidential information, or execute malicious code on the end user systems for a variety of nefarious purposes. Other damaging attacks include the disclosure of end user files, installation of Trojan horse programs, redirecting the user to some other page or site, running “Active X” controls (under Microsoft Internet Explorer) from sites that a user perceives as trustworthy, and modifying presentation of content.

 

Potential Mitigations

Phase: Architecture and Design

Effectiveness:

Description: 

Phase: Implementation, Architecture and Design

Effectiveness:

Description: 

Phase: Architecture and Design, Implementation

Effectiveness: Limited

Description: 

Understand all the potential areas where untrusted inputs can enter your software: parameters or arguments, cookies, anything read from the network, environment variables, reverse DNS lookups, query results, request headers, URL components, e-mail, files, filenames, databases, and any external systems that provide data to the application. Remember that such inputs may be obtained indirectly through API calls.

This technique has limited effectiveness, but can be helpful when it is possible to store client state and sensitive information on the server side instead of in cookies, headers, hidden form fields, etc.

Phase: Architecture and Design

Effectiveness:

Description: 

For any security checks that are performed on the client side, ensure that these checks are duplicated on the server side, in order to avoid CWE-602. Attackers can bypass the client-side checks by modifying values after the checks have been performed, or by changing the client to remove the client-side checks entirely. Then, these modified values would be submitted to the server.

Phase: Architecture and Design

Effectiveness:

Description: 

If available, use structured mechanisms that automatically enforce the separation between data and code. These mechanisms may be able to provide the relevant quoting, encoding, and validation automatically, instead of relying on the developer to provide this capability at every point where output is generated.

Phase: Implementation

Effectiveness:

Description: 

Phase: Implementation

Effectiveness:

Description: 

With Struts, write all data from form beans with the bean’s filter attribute set to true.

Phase: Implementation

Effectiveness: Defense in Depth

Description: 

To help mitigate XSS attacks against the user’s session cookie, set the session cookie to be HttpOnly. In browsers that support the HttpOnly feature (such as more recent versions of Internet Explorer and Firefox), this attribute can prevent the user’s session cookie from being accessible to malicious client-side scripts that use document.cookie. This is not a complete solution, since HttpOnly is not supported by all browsers. More importantly, XMLHTTPRequest and other powerful browser technologies provide read access to HTTP headers, including the Set-Cookie header in which the HttpOnly flag is set.

Phase: Implementation

Effectiveness:

Description: 

Phase: Architecture and Design

Effectiveness:

Description: 

When the set of acceptable objects, such as filenames or URLs, is limited or known, create a mapping from a set of fixed input values (such as numeric IDs) to the actual filenames or URLs, and reject all other inputs.

Phase: Operation

Effectiveness: Moderate

Description: 

Use an application firewall that can detect attacks against this weakness. It can be beneficial in cases in which the code cannot be fixed (because it is controlled by a third party), as an emergency prevention measure while more comprehensive software assurance measures are applied, or to provide defense in depth.

An application firewall might not cover all possible input vectors. In addition, attack techniques might be available to bypass the protection mechanism, such as using malformed inputs that can still be processed by the component that receives those inputs. Depending on functionality, an application firewall might inadvertently reject or modify legitimate requests. Finally, some manual effort may be required for customization.

Phase: Operation, Implementation

Effectiveness:

Description: 

When using PHP, configure the application so that it does not use register_globals. During implementation, develop the application so that it does not rely on this feature, but be wary of implementing a register_globals emulation that is subject to weaknesses such as CWE-95, CWE-621, and similar issues.

CVE References

 

  • CVE-2017-9764
    • Web stats program allows XSS through crafted HTTP header.
  • CVE-2014-5198
    • Web log analysis product allows XSS through crafted HTTP Referer header.
  • CVE-2006-4308
    • Chain: incomplete denylist (CWE-184) only checks “javascript:” tag, allowing XSS (CWE-79) using other tags
  • CVE-2007-5727
    • Chain: incomplete denylist (CWE-184) only removes SCRIPT tags, enabling XSS (CWE-79)
  • CVE-2008-4730
    • Reflected XSS not properly handled when generating an error message
  • CVE-2006-3211
    • Stored XSS in a guestbook application using a javascript: URI in a bbcode img tag.
  • CVE-2006-3295
    • Chain: library file is not protected against a direct request (CWE-425), leading to reflected XSS (CWE-79).

CWE-790 – Improper Filtering of Special Elements

Read Time:14 Second

Description

The software receives data from an upstream component, but does not filter or incorrectly filters special elements before sending it to a downstream component.

Modes of Introduction:

– Implementation

Likelihood of Exploit:

 

Related Weaknesses

CWE-138

 

Consequences

Integrity: Unexpected State

 

Potential Mitigations

CVE References

 

CWE-792 – Incomplete Filtering of One or More Instances of Special Elements

Read Time:15 Second

Description

The software receives data from an upstream component, but does not completely filter one or more instances of special elements before sending it to a downstream component.

Modes of Introduction:

– Implementation

Likelihood of Exploit:

 

Related Weaknesses

CWE-791

 

Consequences

Integrity: Unexpected State

 

Potential Mitigations

CVE References