Embedding NULL Bytes |
Attack Pattern ID: 52 (Detailed Attack Pattern Completeness: Complete) | Typical Severity: High | Status: Draft |
Summary
An attacker embeds one or more null bytes in input to the target software. This attack relies on the usage of a null-valued byte as a string terminator in many environments. The goal is for certain components of the target software to stop processing the input when it encounters the null byte(s).
Attack Execution Flow
Identify a place in the program where user input may be used to escalate privileges by for instance accessing unauthorized file system resources through directory browsing.
An attacker realizes that there is a postfix data that gets in the way of getting to the desired resources
An attacker then ads a postfix NULL terminator to the supplied input in order to "swallow" the postfixed data when the insertion is taking place. With the postfix data that got in the way of the attack gone, the doors are opened for accessing the desired resources.
Description
Directory Browsing
Assume a Web application allows a user to access a set of reports. The path to the reports directory may be something like web/username/reports. If the username is supplied via a hidden field, an attacker could insert a bogus username such as ../../../../../WINDOWS. If the attacker needs to remove the trailing string /reports, then he can simply insert enough characters so the string is truncated. Alternatively the attacker might apply the postfix NULL character (%00) to determine whether this terminates the string.
Different forms of NULL to think about include
Description
Exploitation of a buffer overflow vulnerability in the ActiveX component packaged with Adobe Systems Inc.'s Acrobat/Acrobat Reader allows remote attackers to execute arbitrary code.
The problem specifically exists upon retrieving a link of the following form:
Where [long string] is a malicious crafted long string containing acceptable URI characters. The request must be made to a web server that truncates the request at the null byte (%00), otherwise an invalid file name is specified and a "file not found" page will be returned. Example web servers that truncate the requested URI include Microsoft IIS and Netscape Enterprise. Though the requested URI is truncated for the purposes of locating the file the long string is still passed to the Adobe ActiveX component responsible for rendering the page. This in turn triggers a buffer overflow within RTLHeapFree() allowing for an attacker to overwrite an arbitrary word in memory. The responsible instructions from RTLHeapFree() are shown here:
The register EDI contains a pointer to a user-supplied string. The attacker therefore has control over both the ECX and EAX registers used in the shown MOV instruction.
Successful exploitation allows remote attackers to utilize the arbitrary word overwrite to redirect the flow of control and eventually take control of the affected system. Code execution will occur under the context of the user that instantiated the vulnerable version of Adobe Acrobat.
An attacker does not need to establish a malicious web site as exploitation can occur by adding malicious content to the end of any embedded link and referencing any Microsoft IIS or Netscape Enterprise web server. Clicking on a direct malicious link is also not required as it may be embedded within an IMAGE tag, an IFRAME or an auto-loading script.
Successful exploitation requires that a payload be written such that certain areas of the input are URI acceptable. This includes initial injected instructions as well as certain overwritten addresses. This increases the complexity of successful exploitation. While not trivial, exploitation is definitely plausible [iDefense].
Related Vulnerabilities
CVE-2004-0629
Description
Consider the following PHP script:
A malicious attacker might open the following URL, disclosing the boot.ini file:
Skill or Knowledge Level: Medium
Directory traversal
Skill or Knowledge Level: High
Execution of arbitrary code
Properly handle the NULL characters supplied as part of user input prior to doing anything with the data.
- Data Modification
- Information Leakage
- Privilege Escalation
- Run Arbitrary Code
CWE-ID | Weakness Name | Weakness Relationship Type |
---|---|---|
158 | Improper Neutralization of Null Byte or NUL Character | Targeted |
172 | Encoding Error | Targeted |
173 | Failure to Handle Alternate Encoding | Targeted |
171 | Cleansing, Canonicalization, and Comparison Errors | Targeted |
74 | Failure to Sanitize Data into a Different Plane ('Injection') | Targeted |
20 | Improper Input Validation | Targeted |
697 | Insufficient Comparison | Targeted |
707 | Improper Enforcement of Message or Data Structure | Targeted |
Nature | Type | ID | Name | Description | View(s) this relationship pertains to |
---|---|---|---|---|---|
ChildOf | Attack Pattern | 267 | Leverage Alternate Encoding | Mechanism of Attack (primary)1000 | |
ChildOf | Category | 361 | WASC Threat Classification 2.0 - WASC-28 - Null Byte Injection | WASC Threat Classification 2.0333 | |
ParentOf | Attack Pattern | 53 | Postfix, Null Terminate, and Backslash | Mechanism of Attack1000 |
Bugtraq mailing list archive: PHP Input Validation Vulnerabilities
Available at: http://msgs.securepoint.com/bugtraq/
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 | ||
Eugene Lebanidze | Cigital, Inc | 2007-02-26 | 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 Name, Description and Context Description | ||
Sean Barnum | Cigital, Inc | 2007-04-13 | Modified pattern content according to review and feedback |