2 ms·
I gave it a 10 minute poke just for fun. My main enemy for the first few minutes was the browser trying to tell me I can't do things like eval/etc. Once I got t
by zamadatix 4y ago
I gave it a 10 minute poke just for fun. My main enemy for the first few minutes was the browser trying to tell me I can't do things like eval/etc. Once I got that out of the way with some policy the next issue was the console not really being used to non-printable characters catching me up. In the end those two tricks (both I'm sure being a pain on purpose not by accident) netted me not getting very far as expected, I was only a couple iterations into the first method of obfuscation.
I'm not sure how many levels it was applied but my general strategy on it was the first obfuscation method seemed to be an IIFE that triggers eval on a big string that has had some transformations applied which then calls eval on the next level and so on so I would take the IIFE, turn it into a function definition stuck in a variable like "decodeFunction1" so I could just recursively call directly and change the ending to return the string instead of eval it directly. There is probably something that could be done with debugger breakpoints here but I don't know enough about how that plays out inside eval. Anyways if I were evil I'd make sure at some point in this chain there is a subtle change in what's happening that breaks this approach so I wouldn't be surprised if someone told me that was the case :).
It'd be interesting to see what some real JS devs could get to, both from a "how hard is it" perspective but also just to see what different obfuscations are used in the real world.
- kekebo 4y agoJSNice[0] often does a good job deobfuscating js, the statistical renaming isn't foolproof but often useful. With it I get https://ghostbin.me/62d52999cc217 https://ghostbin.me/62d52999cc217 , from there it's decoding UTF-16 and at least one more decoding step (parts of decoded UTF-16 are mangled) to get the string j and the function o and resolving the original function with it. [0] http://jsnice.org/ http://jsnice.org/
- vitus 4y agoEven easier: open up Chrome DevTools, add a breakpoint at the eval, step into function. Repeat a couple of times. Comment at the top also points to https://freeslots.com/libs/mersenne-twister.js https://freeslots.com/libs/mersenne-twister.js Using those two together to decode the RNG function, and searching around for some more local pointers (with some judicious renaming of functions for legibility, and some comments): // polyfill for IE?? function trunc(a) { return a < 0 ? Math.ceil(a) : Math.floor(a) } var genrand_res53 = function() { var a = new MersenneTwister((new Date).getTime() + Math.floor(Math.random() * Math.pow(2, 32))); return function() { // Generate a random float by varying the 53-bit mantissa. var b = genrand_int32(a) >>> 5, c = genrand_int32(a) >>> 6; // (b << 26 | c) / 2 ** 53 return (b * 67108864 + c) * 1.1102230246251565E-16 } }(); function rand_int(a, b) { var c = genrand_res53(); if (a === undefined) return c; if (b === undefined) return trunc(c * a); if (b > a) return a + trunc(c * (b - a)); return a; } function Kma() { // credits is `Lma`; if you want to cheat, you can edit that variable directly credits < 500 && (Ika = Ika - Ika % 1E6 + rand_int(890001) + 1E5) } So, we're generating a random integer from 0 to 890,000 (inclusive, with negligible chance of generating 890001) with each spin, and using that to update the state (seeded with current time; the top 1e6 of the value is determined via mixing of Date.now() and Math.random() and is fixed for a given session). There's then more to determine whether your state is a winner (based on the game mode), but I didn't feel like looking into that specifically.