forked from DiamondHunters/NodeInject_Hook_example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hook.js
132 lines (116 loc) · 4.04 KB
/
hook.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//this file is a little example of how to use injecting ability
//to hook a function and change its behavior
//in this case we hook the function that is responsible for the decryption of the license
//and we change the behavior to return a valid license
// JUST FOR LEARNING PURPOSES, DON'T USE THIS TO CRACK SOFTWARE
//Adding hook
const crypto = require("crypto");
const pubdec = crypto["publicDecrypt"];
delete crypto["publicDecrypt"];
let fingerprint, email, uuid, license, computerInfo = "";
let License = ""
crypto.publicDecrypt = function (key, buffer) {
log("PubDec Key:" + key);
log("buf: " + buffer.toString('base64'));
if (buffer.slice(0, 26).compare(Buffer.from("CRACKED_BY_DIAMOND_HUNTERS")) == 0) {
License = buffer.toString('base64');
let ret = buffer.toString().replace("CRACKED_BY_DIAMOND_HUNTERS", "");
log("backdoor data,return : " + ret);
return Buffer.from(ret);
}
return pubdec(key, buffer);
};
const fetch = require("electron-fetch")
fetch_bak = fetch['default'];
delete fetch['default'];
fetch.default = async function fetch(url, options) {
log('[fetch]fetch ' + url);
log('[fetch]Arg ' + JSON.stringify(options));
data = await fetch_bak(url, options);
if (url.indexOf('api/client/activate') != -1) {
params = JSON.parse(options.body);
fingerprint = params.f, email = params.email, uuid = params.u, license = params.license, computerInfo = params.l
log('[activate]Fingerprint ' + fingerprint);
log('[activate]Email ' + email);
log('[activate]UUID ' + uuid);
log('[activate]License ' + license);
log('[activate]ComputerInfo ' + computerInfo);
log('[fetch]RetCode ' + data.status);
ret = await data.buffer();
log('[fetch]Ret ' + ret.toString());
ret = Buffer.from('{"code":0,"retry":true,"msg":"' + Buffer.from("CRACKED_BY_DIAMOND_HUNTERS" + JSON.stringify(
{
"fingerprint": fingerprint,
"email": email,
"license": license,
"type": ""
})).toString('base64') + '"}');
log("replace ret: " + ret.toString());
data.text = () => {
return new Promise((resolve, reject) => {
resolve(ret.toString());
});
};
data.json = () => {
return new Promise((resolve, reject) => {
resolve(JSON.parse(ret.toString()));
});
};
}
if (url.indexOf('api/client/renew') != -1) {
ret = await data.buffer();
log('[fetch]Ret ' + ret.toString());
ret = Buffer.from('{"success":true,"code":0,"retry":true,"msg":"' + License + '"}');
log("replace ret: " + ret.toString());
data.text = () => {
return new Promise((resolve, reject) => {
resolve(ret.toString());
});
};
data.json = () => {
return new Promise((resolve, reject) => {
resolve(JSON.parse(ret.toString()));
});
};
}
return new Promise((resolve, reject) => {
resolve(data);
});
}
http = require("http")
function log(str) {
http.get('http://127.0.0.1:3000/log?str=' + str, res => {
}).on('error', err => {
console.log('Error: ', err.message);
});
}
log = console.log;
log('Hook Init')
var Module = require('module');
var originalRequire = Module.prototype.require;
Module.prototype.require = function () {
log('Require ' + arguments[0])
if (arguments[0] == 'crypto') {
log('Hooking crypto');
return crypto;
}
if (arguments[0] == 'electron-fetch') {
log('Hooking electron-fetch');
return fetch;
}
return originalRequire.apply(this, arguments);
};
console.log = log
let validator = {
set: function (target, key, value) {
if (key === 'log') {
log('console.log override blocked');
return;
}
target[key] = value;
}
}
let proxy = new Proxy(console, validator);
console = proxy
module.exports = fetch
//hook finished