3 ms·
Sadly JS has ways around it that is far from obvious since you can chain effects over multiple files that leads to running code. Like the following example (yo
by whizzter 7mo ago
Sadly JS has ways around it that is far from obvious since you can chain effects over multiple files that leads to running code.
Like the following example (you can paste it into node to verify), could be spread out over multiple source files to make it even harder to follow:
// prelude 1, obfuscate the constructor property name to avoid raising simple analyser alarms
const prefix = "construction".substring(0,7);
const suffix = "tractor".substring(3);
const obfuscatedConstructorName = prefix + suffix; // innocent looking, but we have the indexing name.
// prelude 2, get the Function class by indexing a function object with our constructor property name (that does not show up in source-code)
const existingFunction = ()=>"nothing here";
const InnocentLookingClass = existingFunction[obfuscatedConstructorName];
// payload decoding elsewhere (this is where we decode our nasty source)
const nastyPayloadDisguisedAsData = "console.log('sourced string that could be malicious')";
// Unrelated location where payload gets executed
const hardToMissFun = new InnocentLookingClass(nastyPayloadDisguisedAsData);
hardToMissFun(); // when this function is run somewhere.. the nasty things happen.
Unless you have a data-tracing verifier or a sandbox that is continiously run it's going to be very hard to even come close to determining that arbitrary code is being evaluated in this example. Not a single trace of eval or even that the property name constructor is used.
- smaudet 7mo agoAnd this is just the simple obfuscation case... I can easily imagine where we simply disable eval completely, (except in specific scenarios perhaps). At it's core the issue is dynamism itself. I don't think it should be forsaken, but the issue is, yes, JS does a terrible job of making it explicit. If the language itself required a matter of explicitly, then it would make the whole attack generally more difficult to pull off.