The Null Byte

Man

Professional
Messages
3,066
Reaction score
593
Points
113
BITCHES OUT HERE GETTIN BLACKED IM OUT HERE GETTIN NULLED
(WE ARE NOT THE SAME)

It's important not to confuse the NULL byte with the numeral 0 (zero).
The NULL byte is represented in hexadecimal as "%00" and can also be denoted as "\\0".

In the context of PHP, the NULL Byte signifies a NULL character. However, PHP is developed in C, where the NULL Byte acts as a string terminator. This means that in C, a string is considered to end at the point where a NULL Byte is encountered.

Moreover, system calls that are passed to the operating system need to be meticulously filtered. Since UNIX is also written in C, the string termination character NULL could potentially cause issues.

A prime example of this is tricking a web application into believing that a file of a different type has been requested. Observe the following code for a clearer illustration:
PHP:
<?php
$file = $HTTP_GET_VARS["file"];
$file = $file .".txt";
fopen($file, "r");
?>

The script appears relatively harmless at first glance. It simply appends ".txt" to the end of the filename it receives. This approach seems to be the developer's attempt to ensure that only text files are accessible. However, consider a scenario with a filename like this:
Code:
phppage.php%00

It will try to get:
Code:
phppage.php%00.txt

In this case, does the fopen function open "phppage.php%00.txt"? Actually, it doesn't, and that's the crucial point. The fopen function ceases reading the filename at ".php", right before the NULL Byte, and ends up opening only "phppage.php". This means that, contrary to the intended restriction, any type of file could be accessed.

This vulnerability is particularly relevant for scripts that permit file uploads but are supposed to restrict the uploads to specific file types. They become potential targets for this kind of attack. For an additional insightful example involving the NULL byte, you might want to examine the use of /ereg()/.

Using the NULL byte vulnerability forhacking involves testing web applications to identify and exploit weaknesses related to improper handling of NULL bytes. This can help in assessing the security of the application. Here's how it can be used in penetration testing:
  1. Input Validation Testing: Test how the application handles inputs that include NULL bytes. For instance, if the application restricts file types for upload, try uploading a file with a forbidden extension but append a NULL byte followed by an allowed extension (e.g., malicious.exe%00.txt). If the application only processes the string up to the NULL byte, it might accept a dangerous file type.
  2. Path Traversal Attacks: Attempt to exploit path traversal vulnerabilities by including NULL bytes. For example, use paths like ../../../etc/passwd%00 to bypass filters that prevent accessing files outside the intended directory.
  3. Bypassing Security Checks: Some applications use string termination characters (like NULL bytes) to enforce security checks. By inserting a NULL byte, you might bypass these checks, allowing for unauthorized actions.
  4. Testing Database Interactions: If the application uses a database, test how it handles NULL byte injections. This can reveal SQL injection vulnerabilities or issues with data retrieval and storage.
  5. Exploiting Scripting Flaws: In languages like PHP, where NULL bytes can terminate strings, test how scripts handle such inputs. This can expose vulnerabilities in file handling, authentication mechanisms, and more.
  6. Using Automated Tools: Employ penetration testing tools that can automate NULL byte injection in various parts of the application, such as input fields, file uploads, and URL parameters.
  7. Reporting and Patching: Document any vulnerabilities found and report them to the development team. Provide recommendations for patching these issues, such as validating and sanitizing all inputs, updating the programming language or framework to a version that handles NULL bytes securely, and implementing proper error handling.

Thank you for reading and somebody please tell my (separated) wife i want to see the kids please
 
Top