-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Security] PHAR deserialization allowing remote code execution #193
Comments
Hello, Is this addressed by https://wiki.php.net/rfc/phar_stop_autoloading_metadata ? What version of PHP did you target for your POC ? I believe we can safely add some extra checks, since I believe reading images from PHAR archives doesn't seems very useful in legit applications |
(I am running |
Hello, starting from PHP version 8, the phar wrapper can no longer be used. You need to use a version of PHP earlier than 8 to complete this. https://php.watch/versions/8.0/phar-stream-wrapper-unserialize If you need the environment, I can send it to you via Gmail. |
You can update your project’s installation requirements to PHP >= 8.1. |
Just pushed an update to ignore PHARs on |
I am actually not sure. |
I strongly recommend implementing a whitelist for checks (only allowing approved file extensions for processing), and adding the requirement of PHP >= 8.1. This is because blacklist methods are easily bypassed. For example:
This code can easily be bypassed by inputting ' phar://' (with a leading space). |
And |
I added a |
Yes, I used this trick to bypass the checks for other projects. |
I also hope to remove the "return jpeg" from guesstype so that we can reject invalid file extensions. |
PHAR deserialization allowing remote code execution
Description
Gregwar\Image
is vulnerable to PHAR deserialization due to a lack of checking on the protocol before passing it into the file_exists() function. If an attacker can upload files of any type to the server he can pass in the phar:// protocol to unserialize the uploaded file and instantiate arbitrary PHP objects. This can lead to remote code execution especially whenGregwar\Image
is used with frameworks with documented POP chains like Laravel/Symfony vulnerable developer code. If the user can control the input file and protocol during the image conversion , it will invoke deserialization.Proof of Concept (PoC)
there is a vulnerable example with : GD.php
GD.php line 610~617
File.php line 29~61
create_phar.php
We obtain the file.:
/var/www/html
: vuln.php represents our use ofgregwar/image
functions and poc.php represents code with a vulnerable POP chain.poc.php
vuln.php
or
Mitigation
Reference
https://github.com/Gregwar/Image/tree/master
https://book.hacktricks.xyz/pentesting-web/file-inclusion/phar-deserialization
The text was updated successfully, but these errors were encountered: