Magento Template Engine, A Story Of CVE-2022-24086
The Magento template engine allowed user-supplied content in emails to be interpreted as template directives, and by abusing the LegacyResolver and afterFilter callbacks an attacker could execute arbitrary system commands. This could lead to remote code execution when an unauthenticated user triggered an email such as sharing a wishlist.
Published on synacktiv.com
Rédigé par Antoine Gicquel - 16/11/2023 - dans Pentest - Téléchargement
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
The template engine recursively filtered user-supplied content, allowing injected directives to be evaluated, and the LegacyResolver plus afterFilter callbacks enabled calling arbitrary PHP functions.
Impact
An attacker could execute arbitrary system commands on the server, leading to remote code execution, though the text notes the email may be buggy due to inline CSS cleaning.
What the attacker needed
Ability to share a wishlist with a message; no authentication required
The fix
The fix removed the LegacyResolver, changed the filter method to replace directives after processing, and introduced signed deferred directives to prevent user-supplied tags from being interpreted.
How it was found
- Share a wishlist and include a crafted message containing template directives.
- The message is placed into the email template and the filter method processes it.
- The first directive calls filter on a dummy input, which clears the afterFilterCallbacks array.
- The second directive adds system as an afterFilter callback and then calls filter on the command string.
- The afterFilter method executes the system call with the provided command.
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.
Magento is an online store platform. Its template engine builds emails by replacing special placeholders like {{var message}} with actual values. The bug was that if a user put such placeholders into a message, the engine would process them as instructions, and a clever combination could make the server run a command chosen by the attacker.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.