-
Notifications
You must be signed in to change notification settings - Fork 250
Expand file tree
/
Copy pathHook_CryptoJS.js
More file actions
193 lines (172 loc) · 9.21 KB
/
Hook_CryptoJS.js
File metadata and controls
193 lines (172 loc) · 9.21 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// ==UserScript==
// @name Hook_CryptoJS
// @namespace https://github.com/0xsdeo/Hook_JS
// @version 2025-10-17
// @description Hook CryptoJS 对称&哈希&HMAC 所有算法
// @author 0xsdeo
// @run-at document-start
// @match *
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// ==/UserScript==
(function () {
'use strict';
let time = 0;
function hasEncryptProp(obj) {
const requiredProps = [
'ciphertext',
'key',
'iv',
'algorithm',
'mode',
'padding',
'blockSize',
'formatter'
];
// 检查对象是否存在且为对象类型
if (!obj || typeof obj !== 'object') {
return false;
}
// 检查所有必需属性是否存在
for (const prop of requiredProps) {
if (!(prop in obj)) {
return false;
}
}
return true;
}
function hasDecryptProp(obj) {
const requiredProps = [
'sigBytes',
'words'
];
// 检查对象是否存在且为对象类型
if (!obj || typeof obj !== 'object') {
return false;
}
// 检查所有必需属性是否存在
for (const prop of requiredProps) {
if (!(prop in obj)) {
return false;
}
}
return true;
}
function get_sigBytes(size) {
switch (size) {
case 8:
return "64bits";
case 16:
return "128bits";
case 24:
return "192bits";
case 32:
return "256bits";
default:
return "未获取到";
}
}
let temp_apply = Function.prototype.apply;
Function.prototype.apply = function () {
// CryptoJS 对称加密
if (arguments.length === 2 && arguments[0] && arguments[1] && typeof arguments[1] === 'object' && arguments[1].length === 1 && hasEncryptProp(arguments[1][0])) {
if (Object.hasOwn(arguments[0], "$super") && Object.hasOwn(arguments[1], "callee")) {
if (this.toString().indexOf('function()') !== -1 || /^\s*function(?:\s*\*)?\s+[A-Za-z_$][\w$]*\s*\([^)]*\)\s*\{/.test(this.toString()) || /^\s*function\s*\(\s*\)\s*\{/.test(this.toString())) {
console.log(...arguments);
let encrypt_text = arguments[0].$super.toString.call(arguments[1][0]);
if (encrypt_text !== "[object Object]") {
console.log("对称加密后的密文:", encrypt_text);
} else {
console.log("对称加密后的密文:由于toString方法并未获取到,请自行使用上方打印的对象进行toString调用输出密文。");
}
let key = arguments[1][0]["key"].toString();
if (key !== "[object Object]") {
console.log("对称加密Hex key:", key);
} else {
console.log("对称加密Hex key:由于toString方法并未获取到,请自行使用上方打印的对象进行toString调用输出key。");
}
let iv = arguments[1][0]["iv"];
if (iv) {
if (iv.toString() !== "[object Object]") {
console.log("对称加密Hex iv:", iv.toString());
} else {
console.log("对称加密Hex iv:由于toString方法并未获取到,请自行使用上方打印的对象进行toString调用输出iv。");
}
} else {
console.log("对称加密时未用到iv")
}
if (arguments[1][0]["padding"]) {
console.log("对称加密时的填充模式:", arguments[1][0]["padding"]);
}
if (arguments[1][0]["mode"] && Object.hasOwn(arguments[1][0]["mode"], "Encryptor")) {
console.log("对称加密时的运算模式:", arguments[1][0]["mode"]["Encryptor"]["processBlock"]);
}
if (arguments[1][0]["key"] && Object.hasOwn(arguments[1][0]["key"], "sigBytes")) {
console.log("对称加密时的密钥长度:", get_sigBytes(arguments[1][0]["key"]["sigBytes"]));
}
console.log("%c---------------------------------------------------------------------", "color: green;");
} else {
console.groupCollapsed("如果上方正常输出了对称加密的key、iv等加密参数可忽略本条信息。");
console.log(...arguments);
console.log("对称加密:由于一些必要因素导致未能输出key、iv等加密参数,请自行使用上方打印的对象进行toString调用输出key、iv等加密参数。");
console.log("%c---------------------------------------------------------------------", "color: green;");
console.groupEnd();
}
}
// CryptoJS 对称解密
} else if (arguments.length === 2 && arguments[0] && arguments[1] && typeof arguments[1] === 'object' && arguments[1].length === 3 && hasDecryptProp(arguments[1][1])) {
if (Object.hasOwn(arguments[0], "$super") && Object.hasOwn(arguments[1], "callee")) {
if (this.toString().indexOf('function()') === -1 && arguments[1][0] === 2) {
console.log(...arguments);
let key = arguments[1][1].toString();
if (key !== "[object Object]") {
console.log("对称解密Hex key:", key);
} else {
console.log("对称解密Hex key:由于toString方法并未获取到,请自行使用上方打印的对象进行toString调用输出key。");
}
if (Object.hasOwn(arguments[1][2], "iv") && arguments[1][2]["iv"]) {
let iv = arguments[1][2]["iv"].toString();
if (iv !== "[object Object]") {
console.log("对称解密Hex iv:", iv);
} else {
console.log("对称解密Hex iv:由于toString方法并未获取到,请自行使用上方打印的对象进行toString调用输出iv。");
}
} else {
console.log("对称解密时未用到iv")
}
if (Object.hasOwn(arguments[1][2], "padding") && arguments[1][2]["padding"]) {
console.log("对称解密时的填充模式:", arguments[1][2]["padding"]);
}
if (Object.hasOwn(arguments[1][2], "mode") && arguments[1][2]["mode"]) {
console.log("对称解密时的运算模式:", arguments[1][2]["mode"]["Encryptor"]["processBlock"]);
}
if (time === 0) {
console.log("可使用我的脚本进行fuzz加解密参数(算法、模式、填充方式等):https://github.com/0xsdeo/Fuzz_Crypto_Algorithms");
time += 1;
}
console.log("%c---------------------------------------------------------------------", "color: green;");
}
}
// CryptoJS 哈希 / HMAC
} else if (arguments.length === 2 && arguments[0] && arguments[1] && typeof arguments[0] === 'object' && typeof arguments[1] === 'object') {
if (arguments[0].__proto__ && Object.hasOwn(arguments[0].__proto__, "$super") && Object.hasOwn(arguments[0].__proto__, "_doFinalize") && arguments[0].__proto__.__proto__ && Object.hasOwn(arguments[0].__proto__.__proto__, "finalize")) {
if (arguments[0].__proto__.__proto__.finalize.toString().indexOf('哈希/HMAC') === -1) {
let temp_finalize = arguments[0].__proto__.__proto__.finalize;
arguments[0].__proto__.__proto__.finalize = function () {
if (!(Object.hasOwn(this, "init"))) {
let hash = temp_finalize.call(this, ...arguments);
console.log("哈希/HMAC 加密 原始数据:", ...arguments);
console.log("哈希/HMAC 加密 密文:", hash.toString());
console.log("哈希/HMAC 加密 密文长度:", hash.toString().length);
console.log("注:如果是HMAC加密,本脚本是hook不到密钥的,需自行查找。")
console.log("%c---------------------------------------------------------------------", "color: green;");
return hash;
}
return temp_finalize.call(this, ...arguments)
}
}
}
}
return temp_apply.call(this, ...arguments);
}
})();