CWE-191 – Integer Underflow (Wrap or Wraparound)

Read Time:1 Minute, 6 Second

Description

The product subtracts one value from another, such that the result is less than the minimum allowable integer value, which produces a value that is not equal to the correct result.

This can happen in signed and unsigned cases.

Modes of Introduction:

– Implementation

 

 

Related Weaknesses

CWE-682
CWE-682

 

Consequences

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

This weakness will generally lead to undefined behavior and therefore crashes. In the case of overflows involving loop index variables, the likelihood of infinite loops is also high.

Integrity: Modify Memory

If the value in question is important to data (as opposed to flow), simple data corruption has occurred. Also, if the wrap around results in other conditions such as buffer overflows, further memory corruption may occur.

Confidentiality, Availability, Access Control: Execute Unauthorized Code or Commands, Bypass Protection Mechanism

This weakness can sometimes trigger buffer overflows which can be used to execute arbitrary code. This is usually outside the scope of a program’s implicit security policy.

 

Potential Mitigations

CVE References

  • CVE-2004-0816
    • Integer underflow in firewall via malformed packet.
  • CVE-2005-1891
    • Malformed icon causes integer underflow in loop counter variable.

CWE-190 – Integer Overflow or Wraparound

Read Time:3 Minute, 26 Second

Description

The software performs a calculation that can produce an integer overflow or wraparound, when the logic assumes that the resulting value will always be larger than the original value. This can introduce other weaknesses when the calculation is used for resource management or execution control.

An integer overflow or wraparound occurs when an integer value is incremented to a value that is too large to store in the associated representation. When this occurs, the value may wrap to become a very small or negative number. While this may be intended behavior in circumstances that rely on wrapping, it can have security consequences if the wrap is unexpected. This is especially the case if the integer overflow can be triggered using user-supplied inputs. This becomes security-critical when the result is used to control looping, make a security decision, or determine the offset or size in behaviors such as memory allocation, copying, concatenation, etc.

Modes of Introduction:

– Implementation

 

Likelihood of Exploit: Medium

 

Related Weaknesses

CWE-682
CWE-682
CWE-20
CWE-119

 

Consequences

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

This weakness will generally lead to undefined behavior and therefore crashes. In the case of overflows involving loop index variables, the likelihood of infinite loops is also high.

Integrity: Modify Memory

If the value in question is important to data (as opposed to flow), simple data corruption has occurred. Also, if the wrap around results in other conditions such as buffer overflows, further memory corruption may occur.

Confidentiality, Availability, Access Control: Execute Unauthorized Code or Commands, Bypass Protection Mechanism

This weakness can sometimes trigger buffer overflows which can be used to execute arbitrary code. This is usually outside the scope of a program’s implicit security policy.

 

Potential Mitigations

Phase: Requirements

Description: 

Ensure that all protocols are strictly defined, such that all out-of-bounds behavior can be identified simply, and require strict conformance to the protocol.

Phase: Requirements

Description: 

Phase: Architecture and Design

Description: 

Phase: Implementation

Description: 

Phase: Implementation

Description: 

Phase: Architecture and Design

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: Implementation

Description: 

Examine compiler warnings closely and eliminate problems with potential security implications, such as signed / unsigned mismatch in memory operations, or use of uninitialized variables. Even if the weakness is rarely exploitable, a single failure may lead to the compromise of the entire system.

CVE References

  • CVE-2018-10887
    • Chain: unexpected sign extension (CWE-194) leads to integer overflow (CWE-190), causing an out-of-bounds read (CWE-125)
  • 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-2005-1513
    • Chain: integer overflow in securely-coded mail program leads to buffer overflow. In 2005, this was regarded as unrealistic to exploit, but in 2020, it was rediscovered to be easier to exploit due to evolutions of the technology.
  • CVE-2002-0391
    • Integer overflow via a large number of arguments.
  • CVE-2002-0639
    • Integer overflow in OpenSSH as listed in the demonstrative examples.
  • CVE-2005-1141
    • Image with large width and height leads to integer overflow.
  • CVE-2005-0102
    • Length value of -1 leads to allocation of 0 bytes and resultant heap overflow.
  • CVE-2004-2013
    • Length value of -1 leads to allocation of 0 bytes and resultant heap overflow.
  • CVE-2017-1000121
    • chain: unchecked message size metadata allows integer overflow (CWE-190) leading to buffer overflow (CWE-119).
  • 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.

CWE-188 – Reliance on Data/Memory Layout

Read Time:36 Second

Description

The software makes invalid assumptions about how protocol data or memory is organized at a lower level, resulting in unintended program behavior.

Modes of Introduction:

– Architecture and Design

 

Likelihood of Exploit: Low

 

Related Weaknesses

CWE-1105
CWE-435

 

Consequences

Integrity, Confidentiality: Modify Memory, Read Memory

Can result in unintended modifications or exposure of sensitive memory.

 

Potential Mitigations

Phase: Implementation, Architecture and Design

Description: 

In flat address space situations, never allow computing memory addresses as offsets from another memory address.

Phase: Architecture and Design

Description: 

Fully specify protocol layout unambiguously, providing a structured grammar (e.g., a compilable yacc grammar).

Phase: Testing

Description: 

Testing: Test that the implementation properly handles each case in the protocol grammar.

CVE References

CWE-187 – Partial String Comparison

Read Time:1 Minute, 5 Second

Description

The software performs a comparison that only examines a portion of a factor before determining whether there is a match, such as a substring, leading to resultant weaknesses.

For example, an attacker might succeed in authentication by providing a small password that matches the associated portion of the larger, correct password.

Modes of Introduction:

– Implementation

 

 

Related Weaknesses

CWE-1023

 

Consequences

Integrity, Access Control: Alter Execution Logic, Bypass Protection Mechanism

 

Potential Mitigations

Phase: Testing

Description: 

Thoroughly test the comparison scheme before deploying code into production. Perform positive testing as well as negative testing.

CVE References

  • CVE-2014-6394
    • Product does not prevent access to restricted directories due to partial string comparison with a public directory
  • CVE-2004-1012
    • Argument parser of an IMAP server treats a partial command “body[p” as if it is “body.peek”, leading to index error and out-of-bounds corruption.
  • CVE-2004-0765
    • Web browser only checks the hostname portion of a certificate when the hostname portion of the URI is not a fully qualified domain name (FQDN), which allows remote attackers to spoof trusted certificates.
  • CVE-2002-1374
    • One-character password by attacker checks only against first character of real password.
  • CVE-2000-0979
    • One-character password by attacker checks only against first character of real password.

CWE-186 – Overly Restrictive Regular Expression

Read Time:1 Minute, 14 Second

Description

A regular expression is overly restrictive, which prevents dangerous values from being detected.

This weakness is not about regular expression complexity. Rather, it is about a regular expression that does not match all values that are intended. Consider the use of a regexp to identify acceptable values or to spot unwanted terms. An overly restrictive regexp misses some potentially security-relevant values leading to either false positives *or* false negatives, depending on how the regexp is being used within the code. Consider the expression /[0-8]/ where the intention was /[0-9]/. This expression is not “complex” but the value “9” is not matched when maybe the programmer planned to check for it.

Modes of Introduction:

– Implementation

 

 

Related Weaknesses

CWE-185
CWE-184
CWE-183

 

Consequences

Access Control: Bypass Protection Mechanism

 

Potential Mitigations

Phase: Implementation

Description: 

Regular expressions can become error prone when defining a complex language even for those experienced in writing grammars. Determine if several smaller regular expressions simplify one large regular expression. Also, subject your regular expression to thorough testing techniques such as equivalence partitioning, boundary value analysis, and robustness. After testing and a reasonable confidence level is achieved, a regular expression may not be foolproof. If an exploit is allowed to slip through, then record the exploit and refactor your regular expression.

CVE References

  • CVE-2005-1604
    • MIE. “.php.ns” bypasses “.php$” regexp but is still parsed as PHP by Apache. (manipulates an equivalence property under Apache)

CWE-185 – Incorrect Regular Expression

Read Time:1 Minute, 49 Second

Description

The software specifies a regular expression in a way that causes data to be improperly matched or compared.

When the regular expression is used in protection mechanisms such as filtering or validation, this may allow an attacker to bypass the intended restrictions on the incoming data.

Modes of Introduction:

– Implementation

 

 

Related Weaknesses

CWE-697
CWE-187
CWE-182

 

Consequences

Other: Unexpected State, Varies by Context

When the regular expression is not correctly specified, data might have a different format or type than the rest of the program expects, producing resultant weaknesses or errors.

Access Control: Bypass Protection Mechanism

In PHP, regular expression checks can sometimes be bypassed with a null byte, leading to any number of weaknesses.

 

Potential Mitigations

Phase: Architecture and Design

Description: 

Regular expressions can become error prone when defining a complex language even for those experienced in writing grammars. Determine if several smaller regular expressions simplify one large regular expression. Also, subject the regular expression to thorough testing techniques such as equivalence partitioning, boundary value analysis, and robustness. After testing and a reasonable confidence level is achieved, a regular expression may not be foolproof. If an exploit is allowed to slip through, then record the exploit and refactor the regular expression.

CVE References

  • CVE-2002-2109
    • Regexp isn’t “anchored” to the beginning or end, which allows spoofed values that have trusted values as substrings.
  • CVE-2005-1949
    • Regexp for IP address isn’t anchored at the end, allowing appending of shell metacharacters.
  • CVE-2001-1072
    • Bypass access restrictions via multiple leading slash, which causes a regular expression to fail.
  • CVE-2002-1527
    • chain: Malformed input generates a regular expression error that leads to information exposure.
  • CVE-2005-1061
    • Certain strings are later used in a regexp, leading to a resultant crash.
  • CVE-2005-2169
    • MFV. Regular expression intended to protect against directory traversal reduces “…/…//” to “../”.
  • CVE-2005-0603
    • Malformed regexp syntax leads to information exposure in error message.
  • CVE-2005-1820
    • Code injection due to improper quoting of regular expression.

CWE-184 – Incomplete List of Disallowed Inputs

Read Time:2 Minute, 27 Second

Description

The product implements a protection mechanism that relies on a list of inputs (or properties of inputs) that are not allowed by policy or otherwise require other action to neutralize before additional processing takes place, but the list is incomplete, leading to resultant weaknesses.

Developers often try to protect their products against malicious input by performing tests against inputs that are known to be bad, such as special characters that can invoke new commands. However, such lists often only account for the most well-known bad inputs. Attackers may be able to find other malicious inputs that were not expected by the developer, allowing them to bypass the intended protection mechanism.

Modes of Introduction:

– Implementation

 

 

Related Weaknesses

CWE-693
CWE-1023
CWE-79
CWE-78
CWE-434
CWE-98

 

Consequences

Access Control: Bypass Protection Mechanism

 

Potential Mitigations

Phase: Implementation

Description: 

Do not rely exclusively on detecting disallowed inputs. There are too many variants to encode a character, especially when different environments are used, so there is a high likelihood of missing some variants. Only use detection of disallowed inputs as a mechanism for detecting suspicious activity. Ensure that you are using other protection mechanisms that only identify “good” input – such as lists of allowed inputs – and ensure that you are properly encoding your outputs.

CVE References

  • CVE-2008-2309
    • product uses a denylist to identify potentially dangerous content, allowing attacker to bypass a warning
  • CVE-2005-2782
    • PHP remote file inclusion in web application that filters “http” and “https” URLs, but not “ftp”.
  • CVE-2004-0542
    • Programming language does not filter certain shell metacharacters in Windows environment.
  • CVE-2004-0595
    • XSS filter doesn’t filter null characters before looking for dangerous tags, which are ignored by web browsers. MIE and validate-before-cleanse.
  • CVE-2005-3287
    • Web-based mail product doesn’t restrict dangerous extensions such as ASPX on a web server, even though others are prohibited.
Read Time:45 Second

Description

The product implements a protection mechanism that relies on a list of inputs (or properties of inputs) that are explicitly allowed by policy because the inputs are assumed to be safe, but the list is too permissive – that is, it allows an input that is unsafe, leading to resultant weaknesses.

Modes of Introduction:

– Implementation

 

 

Related Weaknesses

CWE-697
CWE-434

 

Consequences

Access Control: Bypass Protection Mechanism

 

Potential Mitigations

CVE References

  • CVE-2019-12799
    • chain: bypass of untrusted deserialization issue (CWE-502) by using an assumed-trusted class (CWE-183)
  • CVE-2019-10458
    • sandbox bypass using a method that is on an allowlist
  • CVE-2019-10458
    • CI/CD pipeline feature has unsafe elements in allowlist, allowing bypass of script restrictions
  • CVE-2017-1000095
    • Default allowlist includes unsafe methods, allowing bypass of sandbox

CWE-182 – Collapse of Data into Unsafe Value

Read Time:1 Minute, 16 Second

Description

The software filters data in a way that causes it to be reduced or “collapsed” into an unsafe value that violates an expected security property.

Modes of Introduction:

– Implementation

 

 

Related Weaknesses

CWE-693
CWE-33
CWE-34
CWE-35

 

Consequences

Access Control: Bypass Protection Mechanism

 

Potential Mitigations

Phase: Architecture and Design

Description: 

Avoid making decisions based on names of resources (e.g. files) if those resources can have alternate names.

Phase: Implementation

Description: 

Phase: Implementation

Description: 

Inputs should be decoded and canonicalized to the application’s current internal representation before being validated (CWE-180). Make sure that the application does not decode the same input twice (CWE-174). Such errors could be used to bypass allowlist validation schemes by introducing dangerous inputs after they have been checked.

Phase:

Description: 

Canonicalize the name to match that of the file system’s representation of the name. This can sometimes be achieved with an available API (e.g. in Win32 the GetFullPathName function).

CVE References

  • CVE-2004-0815
    • “/.////” in pathname collapses to absolute path.
  • CVE-2005-3123
    • “/.//..//////././” is collapsed into “/.././” after “..” and “//” sequences are removed.
  • CVE-2002-0325
    • “…/…//” collapsed to “…” due to removal of “./” in web server.
  • CVE-2002-0784
    • chain: HTTP server protects against “..” but allows “.” variants such as “////./../…/”. If the server removes “/..” sequences, the result would collapse into an unsafe value “////../” (CWE-182).
  • CVE-2005-2169
    • MFV. Regular expression intended to protect against directory traversal reduces “…/…//” to “../”.
Read Time:45 Second

Description

The software validates data before it has been filtered, which prevents the software from detecting data that becomes invalid after the filtering step.

This can be used by an attacker to bypass the validation and launch attacks that expose weaknesses that would otherwise be prevented, such as injection.

Modes of Introduction:

– Implementation

 

 

Related Weaknesses

CWE-179

 

Consequences

Access Control: Bypass Protection Mechanism

 

Potential Mitigations

Phase: Implementation, Architecture and Design

Description: 

Inputs should be decoded and canonicalized to the application’s current internal representation before being filtered.

CVE References

  • CVE-2002-0934
    • Directory traversal vulnerability allows remote attackers to read or modify arbitrary files via invalid characters between two . (dot) characters, which are filtered and result in a “..” sequence.
  • CVE-2003-0282
    • Directory traversal vulnerability allows attackers to overwrite arbitrary files via invalid characters between two . (dot) characters, which are filtered and result in a “..” sequence.

News, Advisories and much more

Exit mobile version