CWE-134 · Słabość
Use of Externally-Controlled Format String
- Abstrakcja
- Bazowa
- Status
- Szkic
- Ryzyko wykorzystania
- wysokie
- Dodano
- 19 lipca 2006
- Ostatnia zmiana
- 11 grudnia 2025
Opis
The product uses a function that accepts a format string as an argument, but the format string originates from an external source.
Skutki
Confidentiality
Read Memory
Format string problems allow for information disclosure which can severely simplify exploitation of the program.
Integrity, Confidentiality, Availability
Modify Memory; Execute Unauthorized Code or Commands
Format string problems can result in the execution of arbitrary code, buffer overflows, denial of service, or incorrect data representation.
Zapobieganie
Requirements
Choose a language that is not subject to this flaw.
Implementation
Ensure that all format string functions are passed a static string which cannot be controlled by the user, and that the proper number of arguments are always sent to that function as well. If at all possible, use functions that do not support the %n operator in format strings. [REF-116] [REF-117]
Build and Compilation
Run compilers and linkers with high warning levels, since they may detect incorrect usage.
Przykłady podatności
- CVE-2002-1825 format string in Perl program
- CVE-2001-0717 format string in bad call to syslog function
- CVE-2002-0573 format string in bad call to syslog function
- CVE-2002-1788 format strings in NNTP server responses
- CVE-2006-2480 Format string vulnerability exploited by triggering errors or warnings, as demonstrated via format string specifiers in a .bmp filename.
- CVE-2007-2027 Chain: untrusted search path enabling resultant format string by loading malicious internationalization messages
Słabość nadrzędna
Może prowadzić do
Kiedy powstaje
- Implementation — The programmer rarely intends for a format string to be externally-controlled at all. This weakness is frequently introduced in code that constructs log messages, where a constant format string is omitted.
- Implementation — In cases such as localization and internationalization, the language-specific message repositories could be an avenue for exploitation, but the format string issue would be resultant, since attacker control of those repositories would also allow modification of message length, format, and content.
Dotyczy
Not Language-Specific, C, C++, Perl
Uwagi
This weakness is possible in any programming language that support format strings.
In some circumstances, such as internationalization, the set of format strings is externally controlled by design. If the source of these format strings is trusted (e.g. only contained in library files that are only modifiable by the system administrator), then the external control might not itself pose a vulnerability.
While Format String vulnerabilities typically fall under the Buffer Overflow category, technically they are not overflowed buffers. The Format String vulnerability is fairly new (circa 1999) and stems from the fact that there is no realistic way for a function that takes a variable number of arguments to determine just how many arguments were passed in. The most common functions that take a variable number of arguments, including C-runtime functions, are the printf() family of calls. The Format String problem appears in a number of ways. A *printf() call without a format specifier is dangerous and can be exploited. For example, printf(input); is exploitable, while printf(y, input); is not exploitable in that context. The result of the first call, used incorrectly, allows for an attacker to be able to peek at stack memory since the input string will be used as the format specifier. The attacker can stuff the input string with format specifiers and begin reading stack values, since the remaining parameters will be pulled from the stack. Worst case, this improper use may give away enough control to allow an arbitrary value (or values in the case of an exploit program) to be written into the memory of the running program.
Frequently targeted entities are file names, process names, identifiers.
Format string problems are a classic C/C++ issue that are now rare due to the ease of discovery. One main reason format string vulnerabilities can be exploited is due to the %n operator. The %n operator will write the number of characters, which have been printed by the format string therefore far, to the memory pointed to by its argument. Through skilled creation of a format string, a malicious user may use values on the stack to create a write-what-where condition. Once this is achieved, they can execute arbitrary code. Other operators can be used as well; for example, a %9999s operator could also trigger a buffer overflow, or when used in file-formatting functions like fprintf, it can generate a much larger output than intended.
Format string issues are under-studied for languages other than C. Memory or disk consumption, control flow or variable alteration, and data corruption may result from format string exploitation in applications written in other languages such as Perl, PHP, Python, etc.
Źródła
- Format String Vulnerabilities in Perl Programs — Steve Christey
- Programming Language Format String Vulnerabilities — Hal Burch, Robert C. Seacord
- Format String Attacks — Tim Newsham, Guardent, 2000
- Writing Secure Code — Michael Howard, David LeBlanc, Chapter 5, "Format String Bugs" Page 147, Microsoft Press, 2002
- 24 Deadly Sins of Software Security — Michael Howard, David LeBlanc, John Viega, "Sin 6: Format String Problems." Page 109, McGraw-Hill, 2010
- The Art of Software Security Assessment — Mark Dowd, John McDonald, Justin Schuh, Chapter 8, "C Format Strings", Page 422, Addison Wesley, 2006
- Automated Source Code Security Measure (ASCSM) — Object Management Group (OMG), ASCSM-CWE-134, 2016
- State-of-the-Art Resources (SOAR) for Software Vulnerability Detection, Test, and Evaluation — Gregory Larsen, E. Kenneth Hong Fong, David A. Wheeler, Rama S. Moorthy, 2014
Wpis z katalogu CWE 4.20.