CraftCMS RCE
CraftCMS's ConditionsController allowed unauthenticated users to create arbitrary objects from request body parameters, which could be chained through library gadgets to include files or write files. The authors chained this with an Imagick VID-scheme file write to achieve remote code execution on their target.
We recently encountered a target running CraftCMS in an engagement, and discovered a Remote Code Execution vulnerability (CVE-2023-41892) that allowed us to compromise the target. While the patch is now available, all CraftCMS users are strongly encouraged to apply the additional mitigation at the end of this post to…
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 ConditionsController's beforeAction passed user-supplied body parameters into Craft::configure and createObject, letting an unauthenticated user instantiate arbitrary classes with attacker-controlled properties.
Impact
An unauthenticated attacker could achieve remote code execution on a vulnerable CraftCMS instance, and knowing the CRAFT_SECURITY_KEY could also lead to unauthenticated RCE via a widely used plugin.
What the attacker needed
Network access to the CraftCMS site; no authentication needed
The fix
The vulnerability was fixed in CraftCMS 4.4.15, and users were also advised to rotate the CRAFT_SECURITY_KEY.
How it was found
- Send a request to the ConditionsController endpoint with a config body parameter naming a class to instantiate.
- Use a gadget such as GuzzleHttp FnStream or yii PhpManager to call methods or include files.
- When no log file was available, create an Imagick object using the VID scheme to write a file without knowing its name.
- Include or execute the written file to achieve remote code execution.
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.
CraftCMS is a website building system. A part of it accepted data from visitors and used that data to build internal objects without checking who was asking. By choosing the right object types, an attacker could make the server run their own code, which is called remote code execution.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.