CWE-124 缓冲区下溢

admin 2022年1月2日04:15:11评论188 views字数 2561阅读8分32秒阅读模式

CWE-124 缓冲区下溢

Buffer Underwrite ('Buffer Underflow')

结构: Simple

Abstraction: Base

状态: Incomplete

被利用可能性: Medium

基本描述

The software 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.

相关缺陷

  • cwe_Nature: ChildOf cwe_CWE_ID: 786 cwe_View_ID: 1000 cwe_Ordinal: Primary

  • cwe_Nature: ChildOf cwe_CWE_ID: 786 cwe_View_ID: 699 cwe_Ordinal: Primary

  • cwe_Nature: ChildOf cwe_CWE_ID: 787 cwe_View_ID: 1000

  • cwe_Nature: ChildOf cwe_CWE_ID: 787 cwe_View_ID: 699

适用平台

Language: [{'cwe_Name': 'C', 'cwe_Prevalence': 'Undetermined'}, {'cwe_Name': 'C++', 'cwe_Prevalence': 'Undetermined'}]

常见的影响

范围 影响 注释
['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', 'Confidentiality', 'Availability', 'Access Control', 'Other'] ['Execute Unauthorized Code or Commands', 'Modify Memory', 'Bypass Protection Mechanism', 'Other'] 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. The consequences would only be limited by how the affected data is used, such as an adjacent memory location that is used to specify whether the user has special privileges.
['Access Control', 'Other'] ['Bypass Protection Mechanism', 'Other'] When the consequence is arbitrary code execution, this can often be used to subvert any other security service.

可能的缓解方案

策略:

Requirements specification: The choice could be made to use a language that is not susceptible to these issues.

Implementation

策略:

Sanity checks should be performed on all calculated values used as index or for pointer arithmetic.

示例代码

In the following C/C++ example, a utility function is used to trim trailing whitespace from a character string. The function copies the input string to a local character string and uses a while statement to remove the trailing whitespace by moving backward through the string and overwriting whitespace with a NUL character.

bad C

char trimTrailingWhitespace(char strMessage, int length) {

char retMessage;
char
message = malloc(sizeof(char)*(length+1));

// copy input string to a temporary string

char message[length+1];
int index;
for (index = 0; index message[index] = strMessage[index];

}
message[index] = '';

// trim trailing whitespace

int len = index-1;
while (isspace(message[len])) {

message[len] = '';
len--;

}

// return string without trailing whitespace

retMessage = message;
return retMessage;

}文章来源于互联网:scap中文网

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年1月2日04:15:11
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   CWE-124 缓冲区下溢http://cn-sec.com/archives/612882.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息