String Format Overflow in syslog() |
Attack Pattern ID: 67 (Detailed Attack Pattern Completeness: Complete) | Typical Severity: Very High | Status: Draft |
Summary
This attack targets the format string vulnerabilities in the syslog() function. An attacker would typically inject malicious input in the format string parameter of the syslog function. This is a common problem, and many public vulnerabilities and associated exploits have been posted.
Attack Execution Flow
The attacker finds that he can inject data to the format string parameter of Syslog().
The attacker craft a malicious input and inject it into the format string parameter. From now on, the attacker can exeute arbitrary code and do more damage.
The format string argument of the Syslog function can be tainted with user supplid data.
Description
Format string vulnerability in TraceEvent function for ntop before 2.1 allows remote attackers to execute arbitrary code by causing format strings to be injected into calls to the syslog function, via (1) an HTTP GET request, (2) a user name in HTTP authentication, or (3) a password in HTTP authentication.
Related Vulnerabilities
CVE-2002-0412
If the source code of the application is available, an attacker can use static analysis tools to spot a syslog vulnerability (a simple grep may also work).
If the source code is not available, automated tools such as Fuzzer and advanced Web Scanner can be used. If the tool supplied data reaches the syslog's format string argument, the application under scrutiny may have unexpected behavior.
If the source code is not available, a more complexe technique involve the use of library and system call tracer combined with the use of binary auditing tool such as IDA Pro. Reverse Engineering technique can be used to find format string vulnerability in the syslog function call. For instance it is possible to get the address of the buffer that is later used as the format string when reading data
The code should be reviewed for misuse of the Syslog function call. Manual or automated code review can be used. The reviewer needs to 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, do not use the %n operator in format strings. The following code shows a correct usage of Syslog():
The following code shows a vulnerable usage of Syslog():
- Run Arbitrary Code
- Denial of Service
- Privilege Escalation
- Data Modification
The maliciously crafted data can read from the stack if passed to the Syslog function as a format String.
The signature of the syslog function is as following : "void syslog(int priority, const char *format, ...);"
A vulnerable usage would be : "syslog(LOG_ERR, cmdBuf);" where cmdBuf is a user controlled data which leads to a format string vulnerability. The activation zone is the format String argument which accepts user supplied data.
The impacts of this attack can be execution of arbitrary code. Execution of arbitary code can lead to many problems such as corruption of data, unauthorized access, etc.
CWE-ID | Weakness Name | Weakness Relationship Type |
---|---|---|
120 | Buffer Copy without Checking Size of Input ('Classic Buffer Overflow') | Secondary |
134 | Uncontrolled Format String | Targeted |
74 | Failure to Sanitize Data into a Different Plane ('Injection') | Secondary |
20 | Improper Input Validation | Secondary |
680 | Integer Overflow to Buffer Overflow | Targeted |
697 | Insufficient Comparison | Targeted |
Vulnerability ID | Relationship Description |
---|---|
CVE-2002-0573 | format string in bad call to syslog function |
CVE-2001-0717 | format string in bad call to syslog function |
CVE-2002-0412 | format string in bad call to syslog function |
Nature | Type | ID | Name | Description | View(s) this relationship pertains to |
---|---|---|---|---|---|
ChildOf | Attack Pattern | 100 | Overflow Buffers | Mechanism of Attack (primary)1000 | |
ChildOf | Category | 339 | WASC Threat Classification 2.0 - WASC-06 - Format String | WASC Threat Classification 2.0333 | |
ParentOf | Attack Pattern | 69 | Target Programs with Elevated Privileges | Mechanism of Attack1000 |
Choose a language which is not subject to this flaw.
Do not use the Syslog() in your implementation.
Use manual or automated code review to spot potential format string vulnerability in functions such as Syslog(), Vsyslog(), snprintf(), etc.
Verify that input is of a limited size.
If the message is coming from an outside source, check for %s type parameters and ensure that bounds will not be overwritten.
Don't use text from an outside source as a format string.
CWE - Buffer Errors
Exploiting Format String Vulnerabilities, scut / team teso, http://doc.bughunter.net/format-string/exploit-fs.html
Halvar Flake, "Auditing binaries for security vulnerabilities", http://www.blackhat.com/presentations/bh-europe-00/HalvarFlake/HalvarFlake.ppt
Fortify Taxonomy of Vulnerabilities : http://vulncat.fortifysoftware.com/1/FS.html - Fortify Software (www.fortifysoftware.com)
Syslog man page : http://www.rt.com/man/syslog.3.html
Submissions | ||||
---|---|---|---|---|
Submitter | Organization | Date | ||
G. Hoglund and G. McGraw. Exploiting Software: How to Break Code. Addison-Wesley, February 2004. | Cigital, Inc | 2007-03-01 |
Modifications | |||||
---|---|---|---|---|---|
Modifier | Organization | Date | Comments | ||
Eric Dalci | Cigital, Inc | 2007-02-13 | Fleshed out content to CAPEC schema from the original descriptions in "Exploiting Software" | ||
Sean Barnum | Cigital, Inc | 2007-03-05 | Review and revise | ||
Richard Struse | VOXEM, Inc | 2007-03-26 | Review and feedback leading to changes in Related Attack Patterns | ||
Sean Barnum | Cigital, Inc | 2007-04-13 | Modified pattern content according to review and feedback |