j4k0xb / webcrack

Deobfuscate obfuscator.io, unminify and unpack bundled javascript
https://webcrack.netlify.app
MIT License
647 stars 73 forks source link

Segmentation fault on arm64 #97

Closed ViRb3 closed 1 week ago

ViRb3 commented 1 week ago

Describe the bug

Using a MacBook Pro M3 Max, macOS 14.5, I seem to get segmentation fault unless I run under Docker with x64 emulation.

Crash 1:

brew install node@20
npm install -g webcrack
nano test.js # put sample from https://obfuscator.io/
webcrack test.js

Crash 2:

docker run --rm -it node:20 bash
npm install -g webcrack
nano test.js # put sample from https://obfuscator.io/
webcrack test.js

Works:

docker run --rm --platform linux/amd64 -it node:20 bash
npm install -g webcrack
nano test.js # put sample from https://obfuscator.io/
webcrack test.js

Expected Behaviour

Works

Code

(function(_0x3c38ae,_0x257ca0){var _0x1e3a62=_0x3e7c,_0x3aed1f=_0x3c38ae();while(!![]){try{var _0x235d27=parseInt(_0x1e3a62(0x1c4))/0x1+parseInt(_0x1e3a62(0x1c7))/0x2*(parseInt(_0x1e3a62(0x1bf))/0x3)+parseInt(_0x1e3a62(0x1be))/0x4*(-parseInt(_0x1e3a62(0x1c1))/0x5)+-parseInt(_0x1e3a62(0x1c2))/0x6+-parseInt(_0x1e3a62(0x1bd))/0x7+-parseInt(_0x1e3a62(0x1c5))/0x8+parseInt(_0x1e3a62(0x1c0))/0x9;if(_0x235d27===_0x257ca0)break;else _0x3aed1f['push'](_0x3aed1f['shift']());}catch(_0x258f14){_0x3aed1f['push'](_0x3aed1f['shift']());}}}(_0x2bc4,0x7a037));function hi(){var _0x421681=_0x3e7c;console[_0x421681(0x1c6)](_0x421681(0x1c3));}hi();function _0x3e7c(_0x5e2698,_0xd7c7b3){var _0x2bc450=_0x2bc4();return _0x3e7c=function(_0x3e7cb6,_0x16f751){_0x3e7cb6=_0x3e7cb6-0x1bd;var _0x11de87=_0x2bc450[_0x3e7cb6];return _0x11de87;},_0x3e7c(_0x5e2698,_0xd7c7b3);}function _0x2bc4(){var _0x5ce9ee=['log','86090ZJVrvx','5113934sLXMER','3730616RHmWvu','21GOexsv','23663583iKhaKk','5LtiXIf','3490884jrxCzi','Hello\x20World!','333779AHuTpI','4156672RWUGSQ'];_0x2bc4=function(){return _0x5ce9ee;};return _0x2bc4();}

Logs

  webcrack:transforms prepare: started +0ms
  webcrack:transforms prepare: finished with 4 changes +3ms
  webcrack:transforms deobfuscate: started +0ms
  webcrack:deobfuscate String Array: 11 strings +0ms
  webcrack:deobfuscate String Array Rotate: yes +0ms
  webcrack:deobfuscate String Array Encodings: 1 +1ms
  webcrack:transforms inline-object-props: started +4ms
  webcrack:transforms inline-object-props: finished with 0 changes +0ms
  webcrack:transforms inline-decoder-wrappers: started +0ms
  webcrack:transforms inline-decoder-wrappers: finished with 14 changes +1ms
  webcrack:transforms inline-decoded-strings: started +2ms
[1]    98368 segmentation fault  npx webcrack test.js
j4k0xb commented 1 week ago

looks related to https://github.com/j4k0xb/webcrack/issues/83#issuecomment-2124128682 can you try the other command as well and make sure the global node version is correct?

ViRb3 commented 1 week ago

That particular issue you linked is webcrack failing compilation on node 22. I ran into that as well, but when I switched to node 20, it compiled and ran fine. It's just during deobfuscation that it hits the segmentation fault. If you look at the docker commands, they run the exact same node version, and one segfaults while the other doesn't, so this must be an arm64 issue. Has anyone ever confirmed this works on arm64?

j4k0xb commented 1 week ago

The crash happens in https://github.com/laverdet/isolated-vm It had an update recently, please try if the example works and otherwise it would be better to create an issue there

ViRb3 commented 1 week ago

Did some more testing and found out a few interesting things:

  1. The segmentation fault comes from isolated-vm as you mentioned; node@20 crashes with the example too.
  2. node@18 does not crash with either.
  3. With node@20, the --no-node-snapshot workaround actually works with both. The correct command is:
    NODE_OPTIONS=--no-node-snapshot webcrack ~/index.js

    You mentioned this workaround in #18, but you missed the -- prefix, which is why it didn't work before. You may want to edit it just in case someone else finds it.

  4. node@22 works with the latest version of isolated-vm. No crash and no workaround necessary.

It may be worthwhile updating isolated-vm and directing users to node@22, and/or documenting the node@20 workaround in README.

Anyway, I'm definitely unblocked now, thanks a lot!