CWE-123 任意地址可写任意内容条件

admin 2022年1月7日02:53:53评论60 views字数 3701阅读12分20秒阅读模式

CWE-123 任意地址可写任意内容条件

Write-what-where Condition

结构: Simple

Abstraction: Base

状态: Draft

被利用可能性: High


Any condition where the attacker has the ability to write an arbitrary value to an arbitrary location, often as the result of a buffer overflow.


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

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


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


范围 影响 注释
['Integrity', 'Confidentiality', 'Availability', 'Access Control'] ['Modify Memory', 'Execute Unauthorized Code or Commands', 'Gain Privileges or Assume Identity', 'DoS: Crash, Exit, or Restart', 'Bypass Protection Mechanism'] Clearly, write-what-where conditions can be used to write data to areas of memory outside the scope of a policy. Also, they almost invariably can be used to execute arbitrary code, which is usually outside the scope of a program's implicit security policy. 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.
['Integrity', 'Availability'] ['DoS: Crash, Exit, or Restart', 'Modify Memory'] Many memory accesses can lead to program termination, such as when writing to addresses that are invalid for the current process.
['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.


Architecture and Design

策略: Language Selection

Use a language that provides appropriate memory abstractions.



Use OS-level preventative functionality integrated after the fact. Not a complete solution.


The classic example of a write-what-where condition occurs when the accounting information for memory allocations is overwritten in a particular fashion. Here is an example of potentially vulnerable code:

bad C

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

char buf1 = (char ) malloc(BUFSIZE);
char buf2 = (char ) malloc(BUFSIZE);
strcpy(buf1, argv[1]);


Vulnerability in this case is dependent on memory layout. The call to strcpy() can be used to write past the end of buf1, and, with a typical layout, can overwrite the accounting information that the system keeps for buf2 when it is allocated. Note that if the allocation header for buf2 can be overwritten, buf2 itself can be overwritten as well.

The allocation header will generally keep a linked list of memory "chunks". Particularly, there may be a "previous" chunk and a "next" chunk. Here, the previous chunk for buf2 will probably be buf1, and the next chunk may be null. When the free() occurs, most memory allocators will rewrite the linked list using data from buf2. Particularly, the "next" chunk for buf1 will be updated and the "previous" chunk for any subsequent chunk will be updated. The attacker can insert a memory address for the "next" chunk and a value to write into that memory address for the "previous" chunk.

This could be used to overwrite a function pointer that gets dereferenced later, replacing it with a memory address that the attacker has legitimate access to, where they have placed malicious code, resulting in arbitrary code execution.


映射的分类名 ImNode ID Fit Mapped Node Name
CLASP Write-what-where condition
Software Fault Patterns SFP8 Faulty Buffer Access
CERT C Secure Coding ARR30-C Imprecise Do not form or use out-of-bounds pointers or array subscripts
CERT C Secure Coding ARR38-C Imprecise Guarantee that library functions do not form invalid pointers
CERT C Secure Coding STR31-C Imprecise Guarantee that storage for strings has sufficient space for character data and the null terminator
CERT C Secure Coding STR32-C Imprecise Do not pass a non-null-terminated character sequence to a library function that expects a string



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


匿名网友 填写信息

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