Magento – RCE & Local File Read with low privilege admin rights
Two vulnerabilities in Magento required a low-privilege admin account: a path traversal in product layout XML allowed a .phtml file uploaded via custom options to be executed as PHP, and a path traversal in the email template CSS directive allowed reading arbitrary local files. An attacker with such an account could achieve remote code execution or read sensitive files.
Published on blog.scrt.ch
I regularly search for vulnerabilities on big services that allow it and have a Bug Bounty program. Here is a second paper which covers two vulnerabilities I discovered on Magento, a big ecommerce CMS that’s now part of Adobe Experience Cloud.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the file path validation only checked that the path string started with an allowed directory, without resolving '..' sequences, and the CSS directive did not sanitise path traversal characters.
Impact
An attacker with low-privilege admin rights could execute arbitrary commands on the server or read local files, potentially leading to full compromise.
What the attacker needed
Low-privilege admin account; ability to create products; ability to create email templates
The fix
The vulnerabilities were fixed in Magento 2.3.0, 2.2.7 and 2.1.16.
How it was found
- Log in with a low-privilege admin account that can create products.
- Create a product with a custom file option allowing .phtml uploads and stock to order one.
- On the frontend, upload a .phtml file and add the product to the cart.
- Retrieve the full application path by causing a cURL error in the product gallery image retrieval.
- In the product design tab, add layout XML that calls fetchView with a path traversal to the uploaded .phtml file.
- Visit the product page on the frontend to execute the code.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A low-privilege admin user could abuse two features: product layout settings and email templates. By tricking the system into loading files from outside the intended folders, they could run their own code on the server or read files that should be private.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.