coin-hive-stratum icon indicating copy to clipboard operation
coin-hive-stratum copied to clipboard

Decrypted m.js

Open cron13 opened this issue 7 years ago • 109 comments

hey guys, can u release decrypted version of m.js, I want to recompile it. At the moment many antiviruses detect it as a virus

cron13 avatar Dec 13 '17 16:12 cron13

https://gist.github.com/cazala/50ab1e141736c8a327b26b923a1448e6

cazala avatar Dec 13 '17 16:12 cazala

Thanks, can you tell us a good utility for obfuscating js? All that I have found so far does not help against some antiviruses :-(

Ikarus PUA.CoinMiner Kaspersky HEUR: Trojan.Script.Generic Symantec PUA.JScoinminer 20171213 ZoneAlarm by Check Point HEUR: Trojan.Script.Generic

cron13 avatar Dec 13 '17 16:12 cron13

Mm i didn't do much, I just used https://javascriptobfuscator.com/ and then converted the whole code to base64, and put it into a new Function(atob("base64source"));

cazala avatar Dec 13 '17 16:12 cazala

Maybe the source could also be minified before/after obfuscating it.

cazala avatar Dec 13 '17 16:12 cazala

Thanks, I will experiment. If this works out. then I will write here

cron13 avatar Dec 13 '17 16:12 cron13

To get it undetected by Kaspersky I only hardcoded the proxy and removed the console.log() calls in m.js then obfuscated it using the same website mentioned above. Then I base64 encoded as mentioned above. I would minify it before obfuscating as well.

adamdupuis avatar Dec 13 '17 16:12 adamdupuis

so @adamdupuis you don't have to load the .js file using the ?proxy= query param right? I believe that's the rule they are using to block it.

cazala avatar Dec 13 '17 16:12 cazala

because I think it gets blocked even before the file is loaded at all, so it has to do with the url.

cazala avatar Dec 13 '17 16:12 cazala

In the version where I deobfuscated your m.js I still need to call it with m.js?proxy= but I do not add a value to the parameter. Since modifying CoinHive's code I removed the need for the proxy parameter.

adamdupuis avatar Dec 13 '17 16:12 adamdupuis

Mm okay then maybe my theory is wrong. But I don't see why you need to pass the ?proxy= query param?

cazala avatar Dec 13 '17 16:12 cazala

Is it because of the throw new Error("missing '?proxy' query parameter in your proxy url!"); ?

cazala avatar Dec 13 '17 16:12 cazala

Yes, I was working with your obfuscated m.js and it was too much work to figure out how to remove the need for it completely so I just left it in. Once I ensure my new version is undetected I will use it without needing the proxy parameter.

adamdupuis avatar Dec 13 '17 16:12 adamdupuis

Okay, let me know if you make any progress :)

cazala avatar Dec 13 '17 16:12 cazala

adamdupuis solution work, thank you!

So, i hardcode proxyUrl and libUrl like this:

var libUrl = 'http://myserver.com/proxyurl/';
const proxyUrl = 'wss://myserver.com:8892?pool=pool.supportxmr.com:3333';

and remove throw new Error and console.log

Then i minify this by https://www.minifier.org Then obfuscate with https://javascriptobfuscator.com And encode result to base64 And put it into new Function(atob("base64source"))();

cron13 avatar Dec 13 '17 16:12 cron13

nice, i ll update the assets soon

cazala avatar Dec 13 '17 17:12 cazala

damn, adguard made new filter that detect miner - https://github.com/AdguardTeam/AdguardFilters/blob/8611f98972689e4001b8cb7861e1cab626755b60/EnglishFilter/sections/general_extensions.txt that filter based on js code: if (a instanceof Array && "string" === typeof a[0] && 0 <= a[0].indexOf("Cryptonight")) { as I understand this code is just looking for the word "Cryptonight" in the js files of the site. I try to rename all "Cryptonight", but after this i got errors like failed to asynchronously prepare wasm: TypeError: undefined is not an object (evaluating 'Module["asm"]["_crnt_create"].apply') TypeError: undefined is not an object (evaluating 'Module["asm"]["_crnt_create"].apply')

Any ideas?

cron13 avatar Dec 14 '17 15:12 cron13

I'll look into it during the weekend, but yea i noticed the traffic going thru the proxy decreased in the last days to a 5% from what it has been the last weeks, it's probably these guys getting smarter

cazala avatar Dec 14 '17 15:12 cazala

damn, adguard made new filter that detect miner - https://github.com/AdguardTeam/AdguardFilters/blob/8611f98972689e4001b8cb7861e1cab626755b60/EnglishFilter/sections/general_extensions.txt that filter based on js code: if (a instanceof Array && "string" === typeof a[0] && 0 <= a[0].indexOf("Cryptonight")) { as I understand this code is just looking for the word "Cryptonight" in the js files of the site. I try to rename all "Cryptonight", but after this i got errors like failed to asynchronously prepare wasm: TypeError: undefined is not an object (evaluating 'Module["asm"]["_crnt_create"].apply') TypeError: undefined is not an object (evaluating 'Module["asm"]["_crnt_create"].apply')

Man glad the community here is super active. Looks like @cron13 beat me to it. I'll go delete my issue on that same adguard filter. Here's what adguard be using on it's english filter https://filters.adtidy.org/extension/chromium/filters/2.txt

phr34k0 avatar Dec 14 '17 17:12 phr34k0

If you base64 encode the Javascript, Adguard should not be able to detect if "Cryptonight" is in there - or can it?

adamdupuis avatar Dec 14 '17 17:12 adamdupuis

Already tried. No dice. Will wait till @cron13 figures a way . @cazala won't be back till the weekends

phr34k0 avatar Dec 14 '17 17:12 phr34k0

Tested this and it stops AdGuard from detecting it.

sed -i 's:Cryptonight:CN:g' m.js

Obviously you need to run this on the decoded m.js, then re-obfuscate and encode it.

amittell avatar Dec 14 '17 20:12 amittell

I'll make these changes to the assets soon, thanks everyone for helping out :)

cazala avatar Dec 14 '17 20:12 cazala

Is this just a search and replace?

adamdupuis avatar Dec 14 '17 20:12 adamdupuis

Yep, working for me and AdGuard doesn't detect it.

https://gist.github.com/amittell/44f868ec729430a9981babe931cef490

amittell avatar Dec 14 '17 20:12 amittell

@amittell should you do the same for 'a.js'? its also contains "Cryptonight"

Akuka avatar Dec 15 '17 14:12 Akuka

@Akuka I didn't, AdGaurd doesn't seem to detect it as it is.

amittell avatar Dec 15 '17 15:12 amittell

The a.js file (asmjs) is not used if WebAssembly is supported. You can force the miner to use asm and test if it gets detected by AdGuard by doing this:

var miner = CH.Anonymous('site-key', { forceASMJS: true });
miner.start();

cazala avatar Dec 15 '17 15:12 cazala

Avast web shield also detect "Cryptonight"

Worldand avatar Dec 15 '17 16:12 Worldand

With what we need to replace "Cryptonight" ?

Worldand avatar Dec 15 '17 18:12 Worldand

Anything that's not "Cryptonight" ;)

In my sed above I just replaced it with "CN".

amittell avatar Dec 15 '17 18:12 amittell

Tried but it didn't works(the miner doesn't start)

Worldand avatar Dec 15 '17 18:12 Worldand

Yeah the miner won't start for me either when I did a find and replace "cryptonight" to "CRY" - I chose something other than "CN" because I wanted to be able to find it later and "cn" is commonly found throughout the script.

adamdupuis avatar Dec 16 '17 20:12 adamdupuis