CWE-122 堆缓冲区溢出

admin 2022年1月2日04:15:08CWE(弱点枚举)评论22 views3257字阅读10分51秒阅读模式

CWE-122 堆缓冲区溢出

Heap-based Buffer Overflow

结构: Simple

Abstraction: Variant

状态: Draft

被利用可能性: High


A heap overflow condition is a buffer overflow, where the buffer that can be overwritten is allocated in the heap portion of memory, generally meaning that the buffer was allocated using a routine such as malloc().


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

  • cwe_Nature: ChildOf cwe_CWE_ID: 788 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'}]


范围 影响 注释
Availability ['DoS: Crash, Exit, or Restart', 'DoS: Resource Consumption (CPU)', 'DoS: Resource Consumption (Memory)'] Buffer overflows generally lead to crashes. Other attacks leading to lack of availability are possible, including putting the program into an infinite loop.
['Integrity', 'Confidentiality', 'Availability', 'Access Control'] ['Execute Unauthorized Code or Commands', 'Bypass Protection Mechanism', 'Modify Memory'] Buffer overflows often can be used to execute arbitrary code, which is usually outside the scope of a program's implicit security policy. Besides important user data, heap-based overflows can be used to overwrite function pointers that may be living in memory, pointing it to the attacker's code. Even in applications that do not explicitly use function pointers, the run-time will usually leave many in memory. For example, object methods in C++ are generally implemented using function pointers. Even in C programs, there is often a global offset table used by the underlying runtime.
['Integrity', 'Confidentiality', 'Availability', 'Access Control', 'Other'] ['Execute Unauthorized Code or Commands', 'Bypass Protection Mechanism', 'Other'] When the consequence is arbitrary code execution, this can often be used to subvert any other security service.



Pre-design: Use a language or compiler that performs automatic bounds checking.

Architecture and Design


Use an abstraction library to abstract away risky APIs. Not a complete solution.

Build and Compilation


Pre-design through Build: Canary style bounds checking, library changes which ensure the validity of chunk data, and other such fixes are possible, but should not be relied upon.



Implement and perform bounds checking on input.


策略: Libraries or Frameworks

Do not use dangerous functions such as gets. Look for their safe equivalent, which checks for the boundary.



Use OS-level preventative functionality. This is not a complete solution, but it provides some defense in depth.


While buffer overflow examples can be rather complex, it is possible to have very simple, yet still exploitable, heap-based buffer overflows:

bad C

#define BUFSIZE 256
int main(int argc, char argv) {

char buf;
buf = (char )malloc(sizeof(char)*BUFSIZE);
strcpy(buf, argv[1]);


The buffer is allocated heap memory with a fixed size, but there is no guarantee the string in argv[1] will not exceed this size and cause an overflow.

This example applies an encoding procedure to an input string and stores it into a buffer.

bad C

char * copy_input(char user_supplied_string){

int i, dst_index;
char dst_buf = (char)malloc(4sizeof(char) * MAX_SIZE);
if ( MAX_SIZE die("user string too long, die evil hacker!");

dst_index = 0;
for ( i = 0; i

if( '&' == user_supplied_string[i] ){

dst_buf[dst_index++] = '&';
dst_buf[dst_index++] = 'a';
dst_buf[dst_index++] = 'm';
dst_buf[dst_index++] = 'p';
dst_buf[dst_index++] = ';';

else if ('

/ encode to < /

else dst_buf[dst_index++] = user_supplied_string[i];

return dst_buf;文章来源于互联网:scap中文网

特别标注: 本站(CN-SEC.COM)所有文章仅供技术研究,若将其信息做其他用途,由用户承担全部法律及连带责任,本站不承担任何法律及连带责任,请遵守中华人民共和国安全法.
  • 我的微信
  • 微信扫一扫
  • weinxin
  • 我的微信公众号
  • 微信扫一扫
  • weinxin
  • 本文由 发表于 2022年1月2日04:15:08
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                  CWE-122 堆缓冲区溢出


匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: