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

Deobfuscate control flow flattening with dead code injection #44

Open
821938089 opened this issue Jan 3, 2024 · 5 comments · May be fixed by #45
Open

Deobfuscate control flow flattening with dead code injection #44

821938089 opened this issue Jan 3, 2024 · 5 comments · May be fixed by #45
Labels
deobfuscate enhancement New feature or request

Comments

@821938089
Copy link

821938089 commented Jan 3, 2024

After deobfuscating of this code, some parts are still obfuscated.
obfuscated.txt

Obfuscation 1: An object stores a lot of simple functions and literals.
image

Obfuscation 2: An object references some literals or functions in another object.
image

@821938089 821938089 added the enhancement New feature or request label Jan 3, 2024
@j4k0xb
Copy link
Owner

j4k0xb commented Jan 3, 2024

In general it supports deobfuscating these objects, but often fails when dead code injection is enabled additionally:
image
Code in the red boxes is removed later and f = m.QMyUp(g, m.AuWjE); never runs but makes it much harder to distinguish from normal user code that should be ignored.
E.g.:

var m = {
  abcde: 'abc'
};
if (....) {
  m = {
    abcde: 'xyz'
  }
}
console.log(m.abcde);

@j4k0xb
Copy link
Owner

j4k0xb commented Jan 3, 2024

Here you can test a workaround but it's not guaranteed to be safe: https://deploy-preview-45--webcrack.netlify.app/

@821938089
Copy link
Author

I tested that the deobfuscated code runs fine.
While inspecting the code I found that some of the useless obfuscated code was not removed.

image

Regarding the above question, in general, it is possible to assume that the objects generated by the obfuscator are not reassigned. You also can try deobfuscate the if statement first to confirm that the branching code will not run.

@j4k0xb
Copy link
Owner

j4k0xb commented Jan 5, 2024

it is possible to assume that the objects generated by the obfuscator are not reassigned

Yes that's what was checked for previously

// Verify all references to make sure they match how the obfuscator
// would have generated the code (no reassignments, etc.)
const binding = path.scope.getBinding(varId.current!.name);
if (!binding) return changes;
if (!isConstantBinding(binding)) return changes;
if (!transformObjectKeys(binding)) return changes;
if (!isReadonlyObject(binding, memberAccess)) return changes;

You also can try deobfuscate the if statement first to confirm that the branching code will not run.

I tried..
image

its the messiest code ever and there are still so many edge cases left:

  • It might find a branch that calls fQUgr: function (p, q) { return f.zvlrc(p, q); but f hasn't been deobfuscated/inlined yet
  • f could also be initialized later:
    const _0x4421b9 = {};
    _0x4421b9[_0xbdaae1(0x1a6)] = function (_0x48317b, _0x3eb9bf) {
    return _0x48317b < _0x3eb9bf;
    };
    _0x4421b9[_0xbdaae1(0x1a2)] = _0xbdaae1(0x1ab);
  • The function in f could again reference another object instead of directly returning a === b, etc.

There's no way to do it "first" because of the order in which these objects are created

@821938089
Copy link
Author

I mean don't do these checks, just inline them.

It might find a branch that calls fQUgr: function (p, q) { return f.zvlrc(p, q); but f hasn't been deobfuscated/inlined yet

what is "f hasn't been deobfuscated/inlined yet" ?
Will the objects generated by the obfuscator be obfuscated?

@j4k0xb j4k0xb changed the title Support more obfuscated cracks Deobfuscate control flow flattening with dead code injection Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deobfuscate enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants