GHSL-2020-042: Server-Side Template Injection in Crafter CMS
A user with privileges to edit a FreeMarker template could bypass the sandbox and execute arbitrary Java code or system commands. This was possible because exposed objects like the Servlet Context allowed instantiation of arbitrary classes.
Originally disclosed on GitHub Security Lab
A user with privileges to edit a FreeMarker template may execute arbitrary Java code or run arbitrary system commands with the same privileges as the account running Crafter CMS.
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 report has not been written yet. The Original tab links to the source.
How it worked
Impact
This issue may lead to Remote Code Execution.
What the attacker needed
Privileges to edit a FreeMarker template
The fix
The issue was fixed in version 3.1.7.
How it was found
- Access the Servlet Context via the exposed siteContext object.
- List Servlet Context attributes to find the Tomcat InstanceManager.
- Use the InstanceManager to instantiate a ScriptEngineManager or Execute class.
- Execute arbitrary Java code or system commands.
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 report has not been written yet. The Original tab links to the source.
FreeMarker is a template engine that lets you generate text with dynamic content. Crafter CMS tried to prevent dangerous template features, but a user who could edit templates could still access internal Java objects and run commands on the server. This means someone with template editing rights could take full control of the server.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.