CAPEC-135: Format String Injection
CAPEC版本: 3.9
更新日期: 2023-01-24
攻击模式描述
An adversary includes formatting characters in a string input field on the target application. Most applications assume that users will provide static text and may respond unpredictably to the presence of formatting character. For example, in certain functions of the C programming languages such as printf, the formatting character %s will print the contents of a memory location expecting this location to identify a string and the formatting character %n prints the number of DWORD written in the memory. An adversary can use this to read or write to memory locations or files, or simply to manipulate the value of the resulting text in unexpected ways. Reading or writing memory may result in program crashes and writing memory could result in the execution of arbitrary code if the adversary can write to the program stack.
执行流程
步骤 1 Explore
[Survey application] The adversary takes an inventory of the entry points of the application.
- Spider web sites for all available links
- List parameters, external variables, configuration files variables, etc. that are possibly used by the application.
步骤 2 Experiment
[Determine user-controllable input susceptible to format string injection] Determine the user-controllable input susceptible to format string injection. For each user-controllable input that the adversary suspects is vulnerable to format string injection, attempt to inject formatting characters such as %n, %s, etc.. The goal is to manipulate the string creation using these formatting characters.
- Inject probe payload which contains formatting characters (%s, %d, %n, etc.) through input parameters.
步骤 3 Exploit
[Try to exploit the Format String Injection vulnerability] After determining that a given input is vulnerable to format string injection, hypothesize what the underlying usage looks like and the associated constraints.
- Insert various formatting characters to read or write the memory, e.g. overwrite return address, etc.
前提条件
- The target application must accept a strings as user input, fail to sanitize string formatting characters in the user input, and process this string using functions that interpret string formatting characters.
所需技能
所需资源
- None: No specialized resources are required to execute this type of attack.
后果影响
影响范围: Integrity
技术影响: Modify Data
影响范围: Confidentiality
技术影响: Read Data
影响范围: Access Control
技术影响: Gain Privileges
影响范围: Integrity
技术影响: Execute Unauthorized Commands
说明: Run Arbitrary Code
影响范围: Access Control
技术影响: Bypass Protection Mechanism
缓解措施
Limit the usage of formatting string functions.
Strong input validation - All user-controllable input must be validated and filtered for illegal formatting characters.
示例实例
Untrusted search path vulnerability in the add_filename_to_string function in intl/gettext/loadmsgcat.c for Elinks 0.11.1 allows local users to cause Elinks to use an untrusted gettext message catalog (.po file) in a "../po" directory, which can be leveraged to conduct format string attacks. See also: CVE-2007-2027
分类映射
| 分类名称 | 条目ID | 条目名称 |
|---|---|---|
| OWASP Attacks | - | Format string attack |