A user with privileges to edit a FreeMarker template (e.g. a Component) may execute arbitrary Java code or run arbitrary system commands with the same privileges as the account running Lithium CMS.
Even though Lithium CMS does a good job limiting what objects are available to FreeMarker templates and always wraps them with
TemplateModels, it is still possible to bypass the FreeMarker sandbox. Deep inspection of the exposed objects' object graph allows an attacker to get access to objects that allow them to instantiate arbitrary Java objects. In particular:
Will return an instance of
sun.misc.Launcher$AppClassLoader. Having access to a ClassLoader we can load arbitrary classes since FreeMarker list of unsafe methods does not disallow
ClassLoader.loadClass(). However, FreeMarker's deny list does disallow invoking
newInstance() on both
java.lang.reflect.Constructor, so there is no way for an attacker to instantiate arbitrary objects.
Even though FreeMarker also disallows setter methods on
java.lang.reflect.Field, it does not forbid getter ones. We can use this gap in the blocklist to get
static fields from any class which can be used to instantiate arbitrary objects.
This issue leads to
Remote Code Execution.
This report was subject to the GHSL coordinated disclosure policy.
This issue was discovered and reported by GHSL team member @pwntester (Alvaro Munoz).
You can contact the GHSL team at
firstname.lastname@example.org, please include a reference to
GHSL-2020-071 in any communication regarding this issue.