Handlebars 4.1.2: Command Execution
Handlebars 4.1.2's sandbox could be bypassed to execute arbitrary commands by overriding propertyIsEnumerable and accessing the Function constructor. An attacker who can inject a template could run code on the server.
blog.tarq.io
Published on blog.tarq.io
#Security#Javascript
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 sandbox's check on property enumerability could be bypassed by redefining propertyIsEnumerable, allowing access to the Function constructor.
Impact
An attacker who can inject a template could execute arbitrary commands on the server.
What the attacker needed
Template injection already possible
How it was found
- Set the context to a string containing the payload and split it to create an array with the payload.
- Use __defineGetter__ to define a getter for 'undefined' that returns valueOf, then use #with __lookupGetter__ to set the context to a function.
- Override propertyIsEnumerable with a bound function that always returns 1 to bypass the patch.
- Access this.constructor to get the Function constructor and call it with the payload.
- Execute the constructed function to run the payload.
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.
Handlebars is a tool that lets you put placeholders in web pages that get filled in with data. It tries to stop you from running dangerous code, but the author found a way around that protection. If an attacker can insert their own template, they can run commands on 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.