Skip to content

Commit 73dabe0

Browse files
committed
fix: hook
1 parent 1a1bd83 commit 73dabe0

File tree

9 files changed

+89
-76
lines changed

9 files changed

+89
-76
lines changed
Lines changed: 53 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,104 @@
11
/**
2-
* 分析参数加密
2+
* 参数加密分析器类,用于检测输入参数的加密类型。
33
*/
44
class ParamEncryptionAnalyzer {
55

66
/**
7-
*
8-
* @param param {Param}
7+
* 分析参数的加密类型。
8+
* @param {Param} param - 需要分析的参数对象,包含一个 `value` 属性。
9+
* @returns {string|null} 返回检测到的加密类型,如果无法识别则返回 `null`。
910
*/
1011
analyze(param) {
1112
return this.detectEncryptionType(param.value);
1213
}
1314

15+
/**
16+
* 检测输入字符串的加密类型。
17+
* @param {string} input - 需要检测的输入字符串。
18+
* @returns {string|null} 返回检测到的加密类型,如果无法识别则返回 `null`。
19+
*/
1420
detectEncryptionType(input) {
15-
// Base64
16-
const base64Regex = /^[A-Za-z0-9+/]+={0,2}$/;
17-
if (base64Regex.test(input) && input.length % 4 === 0) {
18-
return "Base64";
21+
22+
// 如果输入为空,直接返回 null
23+
if (!input) {
24+
return null;
1925
}
2026

21-
// MD5
27+
// // Base64 编码检测
28+
// const base64Regex = /^[A-Za-z0-9+/]+={0,2}$/;
29+
// if (base64Regex.test(input) && input.length % 4 === 0) {
30+
// return "Base64";
31+
// }
32+
33+
// MD5 哈希检测
2234
const md5Regex = /^[a-f0-9]{32}$/i;
2335
if (md5Regex.test(input)) {
2436
return "MD5";
2537
}
2638

27-
// SHA-1
39+
// SHA-1 哈希检测
2840
const sha1Regex = /^[a-f0-9]{40}$/i;
2941
if (sha1Regex.test(input)) {
3042
return "SHA-1";
3143
}
3244

33-
// SHA-256
45+
// SHA-256 哈希检测
3446
const sha256Regex = /^[a-f0-9]{64}$/i;
3547
if (sha256Regex.test(input)) {
3648
return "SHA-256";
3749
}
3850

39-
// SHA-512
51+
// SHA-512 哈希检测
4052
const sha512Regex = /^[a-f0-9]{128}$/i;
4153
if (sha512Regex.test(input)) {
4254
return "SHA-512";
4355
}
4456

45-
// bcrypt
57+
// bcrypt 哈希检测
4658
const bcryptRegex = /^\$2[aby]\$\d{2}\$[.\/A-Za-z0-9]{53}$/;
4759
if (bcryptRegex.test(input)) {
4860
return "bcrypt";
4961
}
5062

51-
// URL编码
52-
const urlEncodedRegex = /%[0-9A-Fa-f]{2}/;
53-
if (urlEncodedRegex.test(input)) {
54-
return "URL Encoded";
55-
}
56-
57-
// Hex编码
58-
const hexRegex = /^[0-9A-Fa-f]+$/;
59-
if (hexRegex.test(input) && input.length % 2 === 0) {
60-
return "Hex Encoded";
61-
}
62-
63-
// ROT13
64-
const rot13Regex = /^[A-Za-z]+$/;
65-
if (rot13Regex.test(input) && input === input.replace(/[A-Za-z]/g, function (c) {
66-
return String.fromCharCode(c.charCodeAt(0) + (c.toLowerCase() < 'n' ? 13 : -13));
67-
})) {
68-
return "ROT13";
69-
}
70-
71-
// JWT
72-
const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
73-
if (jwtRegex.test(input)) {
74-
return "JWT";
75-
}
76-
77-
// UUID
63+
// // URL 编码检测
64+
// const urlEncodedRegex = /%[0-9A-Fa-f]{2}/;
65+
// if (urlEncodedRegex.test(input)) {
66+
// return "URL Encoded";
67+
// }
68+
//
69+
// // Hex 编码检测
70+
// const hexRegex = /^[0-9A-Fa-f]+$/;
71+
// if (hexRegex.test(input) && input.length % 2 === 0) {
72+
// return "Hex Encoded";
73+
// }
74+
75+
// // ROT13 编码检测
76+
// const rot13Regex = /^[A-Za-z]+$/;
77+
// if (rot13Regex.test(input) && input === input.replace(/[A-Za-z]/g, function (c) {
78+
// return String.fromCharCode(c.charCodeAt(0) + (c.toLowerCase() < 'n' ? 13 : -13));
79+
// })) {
80+
// return "ROT13";
81+
// }
82+
83+
// // JWT (JSON Web Token) 检测
84+
// const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
85+
// if (jwtRegex.test(input)) {
86+
// return "JWT";
87+
// }
88+
89+
// UUID 检测
7890
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
7991
if (uuidRegex.test(input)) {
8092
return "UUID";
8193
}
8294

83-
// 如果都不匹配,返回未知
95+
// 如果以上所有加密类型都不匹配,返回 null 表示未知加密类型
8496
return null;
8597
}
8698

87-
// // 测试示例
88-
// console.log(detectEncryptionType("SGVsbG8gV29ybGQ=")); // Base64
89-
// console.log(detectEncryptionType("5d41402abc4b2a76b9719d911017c592")); // MD5
90-
// console.log(detectEncryptionType("2fd4e1c67a2d28fced849ee1bb76e7391b93eb12")); // SHA-1
91-
// console.log(detectEncryptionType("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")); // SHA-256
92-
// console.log(detectEncryptionType("$2a$10$N9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJZdL17lhWy")); // bcrypt
93-
// console.log(detectEncryptionType("Hello%20World")); // URL Encoded
94-
// console.log(detectEncryptionType("48656c6c6f20576f726c64")); // Hex Encoded
95-
// console.log(detectEncryptionType("Uryyb Jbeyq")); // ROT13
96-
// console.log(detectEncryptionType("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c")); // JWT
97-
// console.log(detectEncryptionType("550e8400-e29b-41d4-a716-446655440000")); // UUID
98-
// console.log(detectEncryptionType("randomstring")); // Unknown Encryption Type
99-
10099
}
101100

102-
101+
// 导出 ParamEncryptionAnalyzer 类
103102
module.exports = {
104103
ParamEncryptionAnalyzer
105104
}

src/analyzer/request-analyzer.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const {getUnsafeWindow} = require("../utils/scope-util");
2+
const {ParamEncryptionAnalyzer} = require("./param-encryption-analyzer");
23

34
/**
45
* 分析请求中的jsonp情况,主要是看一下是否存在jsonp参数,并将其识别出来
@@ -10,16 +11,24 @@ class RequestAnalyzer {
1011
* @param requestContext {RequestContext}
1112
*/
1213
analyze(requestContext) {
14+
1315
if (!requestContext.params) {
1416
return null;
1517
}
16-
requestContext.params = this.computeParamsJsonpCallbackScore(requestContext.params);
1718

19+
// 自动推断出jsonp参数
20+
requestContext.params = this.computeParamsJsonpCallbackScore(requestContext.params);
1821
// 选出其中可能性最大的一个参数作为jsonp callback参数
1922
if (requestContext.params && requestContext.params.length && requestContext.params[0].jsonpCallbackScore > 0) {
2023
requestContext.params[0].isJsonpCallback = true;
2124
}
2225

26+
// 推断参数加密方式
27+
const paramEncryptionAnalyzer = new ParamEncryptionAnalyzer();
28+
for (let param of requestContext.params) {
29+
param.encryptType = paramEncryptionAnalyzer.analyze(param);
30+
}
31+
2332
}
2433

2534
/**

src/config/ui/component/configuration-component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const {getGlobalConfig} = require("../../config");
44
const {getLanguage} = require("./language");
55

66
/**
7-
* 使用之前要签署用户协议
7+
* 配置组件
88
*/
99
class ConfigurationComponent {
1010

src/context/request/param.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class Param {
2424
// 此参数是 JSONP 的 callback 参数的可能性有多大(用于评分)
2525
this.jsonpCallbackScore = 0;
2626

27+
// 参数的加密类型
28+
this.encryptType = null;
2729
}
2830

2931
/**

src/context/request/request-context.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const {repeat} = require("../../utils/string-util");
2+
const {Param} = require("./param");
23

34
/**
45
* 用于封装请求的上下文,包含从 URL 中解析出的各种信息。

src/formatter/request-formatter.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,24 +70,32 @@ class RequestFormatter {
7070

7171
// 示例数据
7272
const data = [
73-
['名称', '值'],
74-
[language.console.time, new Date().toLocaleString()],
75-
[language.console.requestId, scriptContext.requestId],
76-
[language.console.isJsonpRequest, scriptContext.isJsonp()],
77-
[language.console.hostname, requestContext.hostname],
78-
[language.console.path, requestContext.path],
79-
[language.console.hash, requestContext.hash],
73+
// TODO 2025-01-08 01:28:26 国际化
74+
["名称", "值", "备注"],
75+
[language.console.time, new Date().toLocaleString(), ""],
76+
[language.console.requestId, scriptContext.requestId, ""],
77+
[language.console.isJsonpRequest, scriptContext.isJsonp(), ""],
78+
[language.console.hostname, requestContext.hostname, ""],
79+
[language.console.path, requestContext.path, ""],
80+
[language.console.hash, requestContext.hash, ""],
8081
// [language.console.param, requestContext.params.length],
8182
];
8283

8384
let index = 1;
8485
for (let param of requestContext.params) {
86+
8587
const name = `${language.console.param}(${index++}) ${param.name}`;
88+
8689
let value = `${param.value}`;
90+
91+
let attribute = "";
8792
if (param.isJsonpCallback) {
88-
value += "(jsonp callback)"
93+
attribute = "jsonp callback";
94+
} else if (param.encryptType) {
95+
attribute = param.encryptType;
8996
}
90-
data.push([name, value]);
97+
98+
data.push([name, value, attribute]);
9199
}
92100

93101
// 示例样式

src/hook/jsonp-callback-hook.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ class JsonpCallbackHook {
4646
const hook = new ObjectFunctionHook(getUnsafeWindow(), jsonpCallbackFunctionName);
4747
if (getGlobalConfig().hookType === "use-redeclare-function") {
4848
hook.hookType = hookTypeUseDeclareFunction;
49-
hook.addHook(this.callbackForDeclareFunction(_this), true);
49+
hook.addHook(this.callbackForDeclareFunction(_this));
5050
} else if (getGlobalConfig().hookType === "use-proxy-function") {
5151
hook.hookType = hookTypeUseProxyFunction;
52-
hook.addHook(this.callbackForProxyFunction(_this), true);
52+
hook.callByHookCallbackFunction = true;
53+
hook.addHook(this.callbackForProxyFunction(_this));
5354
}
5455
}
5556

src/hook/object-function-hook.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ class ObjectFunctionHook {
3232
/**
3333
*
3434
* @param hookCallbackFunction
35-
* @param callByHookCallbackFunction {boolean}
3635
*/
37-
addHook(hookCallbackFunction, callByHookCallbackFunction = false) {
36+
addHook(hookCallbackFunction) {
3837

3938
// 要Hook的函数必须存在
4039
const functionHolder = this.object[this.functionName];

src/hook/script-hook.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
const Debugger = require("../debugger/debugger");
2-
const {JsonpCallbackFunctionAnalyzer} = require("../analyzer/response-analyzer");
31
const {ScriptContext} = require("../context/script/script-context");
42
const {RequestContext} = require("../context/request/request-context");
53
const {RequestAnalyzer} = require("../analyzer/request-analyzer");
64
const {getGlobalConfig} = require("../config/config");
75
const {RequestFormatter} = require("../formatter/request-formatter");
8-
const {getUnsafeWindow} = require("../utils/scope-util");
9-
const {ObjectFunctionHook} = require("./object-function-hook");
10-
const {ResponseContext} = require("../context/response/response-context");
11-
const {ResponseFormatter} = require("../formatter/response-formatter");
126
const {JsonpCallbackHook} = require("./jsonp-callback-hook");
137
const {formatScriptSrcToUrl} = require("../utils/url-util");
148
const {DebuggerTester} = require("../debugger/debugger-tester");
@@ -51,7 +45,7 @@ class ScriptHook {
5145
// 在请求发送之前测试断点
5246
if (new DebuggerTester().isNeedPrintToConsole(getGlobalConfig(), scriptContext)) {
5347
const requestFormatter = new RequestFormatter();
54-
console.log(requestFormatter.format(scriptContext));
48+
requestFormatter.format(scriptContext)
5549
}
5650

5751
const hitDebuggers = getGlobalConfig().testAll(scriptContext);

0 commit comments

Comments
 (0)