---
title: "CAPEC-135: Format String Injection"
url: https://radicalnotion.ai/capec/capec-135
type: capec
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."
updated: 2026-06-01
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CAPEC-135: Format String Injection

- **Abstraction:** Standard
- **Status:** Draft
- **Typical severity:** High
- **Likelihood of attack:** High
- **CAPEC catalog 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

### Step 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.

### Step 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.

### Step 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.

## 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.

## Resources required

- None: No specialized resources are required to execute this type of attack.

## Consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Integrity | Modify Data | - |
| Confidentiality | Read Data | - |
| Access Control | Gain Privileges | - |
| Integrity | Execute Unauthorized Commands | Run Arbitrary Code |
| 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.

## Example instances

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

## Related weaknesses (CWE)

- [CWE-20](https://radicalnotion.ai/cwe/cwe-20): Improper Input Validation
- [CWE-74](https://radicalnotion.ai/cwe/cwe-74): Improper Neutralization of Special Elements in Output Used by a Downstream Component
- [CWE-134](https://radicalnotion.ai/cwe/cwe-134): Use of Externally-Controlled Format String

## Related attack patterns

| Relationship | CAPEC | Name |
| --- | --- | --- |
| Parent | [CAPEC-137](https://radicalnotion.ai/capec/capec-137) | Parameter Injection |
| Child | [CAPEC-67](https://radicalnotion.ai/capec/capec-67) | String Format Overflow in syslog() |

## Taxonomy mappings

| Taxonomy | Entry | Id |
| --- | --- | --- |
| OWASP Attacks | Format string attack | - |

## Frequently asked questions

### 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: CWE-20 (Improper Input Validation), CWE-74 (Improper Neutralization of Special Elements in Output Used by a Downstream Component) and 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.

Primary source: [MITRE CAPEC](https://capec.mitre.org/data/definitions/135.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/capec/capec-135). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
