CAPECattack pattern
CAPEC-135 Format String Injection
High
Official page ↗
- Abstraction
- Standard
- Status
- Draft
- Likelihood of attack
- High
- Typical severity
- High
- CAPEC version
- 3.9
Description
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.
Execution flow
1. [Explore] [Survey application] The adversary takes an inventory of the entry points of 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.
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.
Prerequisites
• 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.
Skills required
• [High] In order to discover format string vulnerabilities it takes only low skill, however, converting this discovery into a working exploit requires advanced knowledge on the part of the adversary.
Consequences
• Integrity: Modify Data
• Confidentiality: Read Data
• Access Control: Gain Privileges
• Integrity: Execute Unauthorized Commands
• Access Control: Bypass Protection Mechanism
Mitigations
• Limit the usage of formatting string functions.
• Strong input validation - All user-controllable input must be validated and filtered for illegal formatting characters.
Related
Child of · CAPEC (1)
- CAPEC-137 Parameter Injection attack pattern
Weakness · CWE (3)
Referenced by CAPEC · child of (1)
- CAPEC-67 String Format Overflow in syslog() attack pattern