-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Null Byte Interaction Error occurs when software incorrectly handles null bytes (\0) in strings, typically due to the ambiguity of:
C-style strings (which terminate at the first null byte), and higher-level language strings (which may contain embedded nulls).
If unvalidated or unsanitized input contains a null byte, it will result in: Premature string termination, truncating filenames or commands, and
skipping security checks or validation routines.
//Vulnerable C code
char filename[100];
strcpy(filename, user_input); // user_input = "config.php\0.jpg"
fopen(filename, "r");
Explanation:
The developer is anticipating filename to be "config.php.jpg".
But C will read the string only until the first null byte (\0) and will interpret it as "config.php".
As a result, the app might open or include an insecure file (for example, config.php) which was not intended to, leading to information leak or arbitrary file access.
Impact
Security validation bypass (e.g., file extension filters, path checks).
Buffer overflows or memory corruption (if null termination is incorrectly performed).
Inappropriate access to files or system commands.
Program crashes due to misinterpreted string boundaries.
Mitigation
Validate all input strings before use.
Avoid the use of raw C string functions like strcpy(), strcat(), etc.
Use safer alternatives like strncpy() or language-safe string libraries.
Use explicit string length checks and correct null termination.
Use static analysis tools to detect unsafe string operations.
References:
https://phrack.org/issues/55/7
http://www.security-assessment.com/Whitepapers/0x00_vs_ASP_File_Uploads.pdf
https://seclists.org/fulldisclosure/2006/Sep/185
Bhavitha Kodidala