Postfix, Null Terminate, and Backslash |
Attack Pattern ID: 53 (Detailed Attack Pattern Completeness: Complete) | Typical Severity: High | Status: Draft |
Summary
If a string is passed through a filter of some kind, then a terminal NULL may not be valid. Using alternate representation of NULL allows an attacker to embed the NULL midstring while postfixing the proper data so that the filter is avoided. One example is a filter that looks for a trailing slash character. If a string insertion is possible, but the slash must exist, an alternate encoding of NULL in midstring may be used.
Attack Execution Flow
An attacker first probes to figure out what restrictions on input are placed by filter, such as a specific characters on the end of the URL.
The attacker then injects a string of their choosing with a null terminator (using an alternate encoding such as %00), followed by a backslash (%5C), followed by some additional characters that are required to keep the filter happy
The malicious string then passes through the filter and passed to the underlying API. Everything after the null terminator is ignored. This may give an attacker the opportunity to access file system resources to which they should not have access and do other things.
Some popular forms in which this takes place:
PATH%00%5CPATH[0x00][0x5C]PATH[alternate encoding of the NULL][additional characters required to pass filter]
Description
A rather simple injection is possible in a URL:
This attack has appeared with regularity in the wild. There are many variations of this kind of attack. Spending a short amount of time injecting against Web applications will usually result in a new exploit being discovered.
Skill or Knowledge Level: Medium
An attacker needs to understand alternate encodings, what the filter looks for and the data format acceptable to the target API
Test the program with various inputs and observe the behavior of the filter. Overtime it should be possible to understand what the filter is expecting.
Null characters are observed by the filter. The filter needs to be able to understand various encodings of the Null character, or only canonical data should be passed to it.
Properly handle Null characters. Make sure canonicalization is properly applied. Do not pass Null characters to the underlying APIs.
Assume all input is malicious. Create a white list that defines all valid input to the software system based on the requirements specifications. Input that does not match against the white list should not be permitted to enter into the system.
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 | 52 | Embedding NULL Bytes | Mechanism of Attack1000 | |
ChildOf | Attack Pattern | 267 | Leverage Alternate Encoding | Mechanism of Attack (primary)1000 |
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 Related Attack Patterns | ||
Sean Barnum | Cigital, Inc | 2007-04-13 | Modified pattern content according to review and feedback |