Skip to content
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

Deserialization of Untrusted Data in spatie/image-optimizer #210

Open
Sonicrrrr opened this issue Feb 27, 2024 · 2 comments
Open

Deserialization of Untrusted Data in spatie/image-optimizer #210

Sonicrrrr opened this issue Feb 27, 2024 · 2 comments

Comments

@Sonicrrrr
Copy link
Contributor

Description
ImageOptimizer is vulnerable to PHAR deserialization due to a lack of checking the input 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 when ImageOptimizer is used with frameworks with documented POP chains like Laravel / vulnerable developer code.
Proof of Concept
Setup the following code in /var/www/html: vuln.php represents our use of ImageOptimizer functions and phar-poc.php represents code with a vulnerable POP chain.
image
image
As an attacker, we generate our PHAR payload using the following exploit script:
image
Generate with:
image
and execute vuln.php with php vuln.php, you should see whoami being executed
image
Note that after generating the PHAR exploit code, an attacker can rename it to whatever extension or filename they want, it is possible to rename it test.phar to test.png to bypass any file extension check by the developer and specify phar://test.png in the $pathToImage.

Impact
This vulnerability is capable of remote code execution if ImageOptimizer is used with frameworks or developer code with vulnerable POP chains.

Recommended Fix:
Filter the phar:// protocol.

@freekmurze
Copy link
Member

Thanks for reporting.

Could you PR a fix?

To prevent regressions, please also add a test.

@Sonicrrrr
Copy link
Contributor Author

I have submitted a pull request to fix the security vulnerability. Will you assign a CVE number to this vulnerability?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants