CAPEC-135: Format String Injection
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.
Last updated
Overview
CAPEC-135 (Format String Injection) is a standard-level attack pattern catalogued by MITRE in the Common Attack Pattern Enumeration and Classification (CAPEC). It describes a recurring method attackers use to exploit software weaknesses.
How the attack works
The phases an attacker typically follows.
- Step 1Explore
[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.
- Step 2Experiment
[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.
- Step 3Exploit
[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.
What the attacker needs
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 skill: 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.
Resources required
- None: No specialized resources are required to execute this type of attack.
Consequences
What a successful CAPEC-135 attack can achieve.
Modify Data
Affects: Integrity
Read Data
Affects: Confidentiality
Gain Privileges
Affects: Access Control
Execute Unauthorized Commands
Affects: Integrity
Run Arbitrary Code
Bypass Protection Mechanism
Affects: Access Control
How to mitigate it
Defenses that reduce the risk of CAPEC-135.
- Limit the usage of formatting string functions.
- Strong input validation - All user-controllable input must be validated and filtered for illegal formatting characters.
Examples
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
Terminology & mappings
Mapped taxonomies
- OWASP Attacks: Format string attack
Frequently asked questions
Common questions about CAPEC-135.
- What is CAPEC-135?
- 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.
- How does a Format String Injection attack work?
- It typically unfolds over 3 phases. It begins with: [Survey application] The adversary takes an inventory of the entry points of the application.
- How do you prevent CAPEC-135?
- Limit the usage of formatting string functions.
- What weaknesses does CAPEC-135 target?
- CAPEC-135 exploits 3 CWE weaknesses, including CWE-20 (Improper Input Validation), CWE-74 (Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection')), CWE-134 (Use of Externally-Controlled Format String).
- How severe is CAPEC-135?
- MITRE rates CAPEC-135 as High severity with high likelihood of attack.
References
Attack-pattern data is sourced from the MITRE CAPEC catalog (v3.9). Weakness associations link to the corresponding CWE entries on RadicalNotion.AI.
Defend against CAPEC-135
Track the CVEs and weaknesses this technique exploits, with AI-written analysis and remediation steps.