- Joined
- 11 yrs. 6 mth. 27 days
- Messages
- 5,381
- Reaction score
- 18,380
- Age
- 45
- Wallet
- 11,590$
- [email protected]
[0x01] Copy Function Bypass:
The PHP copy function copies a file. The copy() function returns True on success and False on failure.
copy() Syntax:copy(source, destination)# source (required): Specifies the file to copy.# destination (required): Specifies the file to copy to.
[0x02] Walk through:
The PHP copy function suffers from a very common type of attack, know as the null byte injection. We see a lot of hackers, and pentesters using this method in LFI and various other types of PHP attacks. Null byte injection is used to bypass sanity checking filters in web infrastructure and applications by adding URL-encoded null byte characters to the user supplied data. Examples of null byte characters would be: %00 or 0x00 in hex. Null byte injections are quite under looked by most attackers, because of a lack of understanding what the null byte is capable of. The null byte injection can alter the intended logic of an application and allow malicious adversary to get access to the system files hosted on the target web server.
[0x03] Example Time:
Okay for this example, I will be giving a small php script to demonstrate how the vulnerability works. Say we have a php script (copy.php) which takes file name as input from the user and then copies the given file onto a destination.
<?php$source = $_GET['file'];$destination = 'mydest.txt';if (copy($source, $destination)){ echo "Successfully copied $source.\n";}else { echo "Failed to copy $source.\n";}?>
Okay as we can clearly see our user input "file" is not sanitized. Which leads this script vulnerable and the user able to apply anything typed to the $source string. A simple example of exploitation would be:
[*] Given this GET request on the server hosting copy.php:
If the above request passes and executed using copy() then instead of a .jpg file eval.php will be copied and whenever the file is read then the code in eval.php will be executed.
[0x04] Ethical Perspective:
Okay so we discussed a bit on exploiting copy() with null byte injection, now lets talk about securing the issue. The solution is to filter out null byte from the input string. Consider a copy_file function which will copy the given file by removing null bytes. Example code below:
function copy_file($source, $target){ $str = str_replace(chr(0), '', $source); $final = copy("$str","$target"); return $final}
The above code will return True on success and False when the code fails. Now we have a secure bit of code that isn't vulnerable to copy function bypass, looks clean, filtered, and can be reused since in a function.
[0x05] Conclusion:
Nothing really big, just something small but hopefully eye opening to most developers and pentesters. Thanks for viewing :>
The PHP copy function copies a file. The copy() function returns True on success and False on failure.
copy() Syntax:copy(source, destination)# source (required): Specifies the file to copy.# destination (required): Specifies the file to copy to.
[0x02] Walk through:
The PHP copy function suffers from a very common type of attack, know as the null byte injection. We see a lot of hackers, and pentesters using this method in LFI and various other types of PHP attacks. Null byte injection is used to bypass sanity checking filters in web infrastructure and applications by adding URL-encoded null byte characters to the user supplied data. Examples of null byte characters would be: %00 or 0x00 in hex. Null byte injections are quite under looked by most attackers, because of a lack of understanding what the null byte is capable of. The null byte injection can alter the intended logic of an application and allow malicious adversary to get access to the system files hosted on the target web server.
[0x03] Example Time:
Okay for this example, I will be giving a small php script to demonstrate how the vulnerability works. Say we have a php script (copy.php) which takes file name as input from the user and then copies the given file onto a destination.
<?php$source = $_GET['file'];$destination = 'mydest.txt';if (copy($source, $destination)){ echo "Successfully copied $source.\n";}else { echo "Failed to copy $source.\n";}?>
Okay as we can clearly see our user input "file" is not sanitized. Which leads this script vulnerable and the user able to apply anything typed to the $source string. A simple example of exploitation would be:
[*] Given this GET request on the server hosting copy.php:
If the above request passes and executed using copy() then instead of a .jpg file eval.php will be copied and whenever the file is read then the code in eval.php will be executed.
[0x04] Ethical Perspective:
Okay so we discussed a bit on exploiting copy() with null byte injection, now lets talk about securing the issue. The solution is to filter out null byte from the input string. Consider a copy_file function which will copy the given file by removing null bytes. Example code below:
function copy_file($source, $target){ $str = str_replace(chr(0), '', $source); $final = copy("$str","$target"); return $final}
The above code will return True on success and False when the code fails. Now we have a secure bit of code that isn't vulnerable to copy function bypass, looks clean, filtered, and can be reused since in a function.
[0x05] Conclusion:
Nothing really big, just something small but hopefully eye opening to most developers and pentesters. Thanks for viewing :>