Skip to content

Commit 3175ae2

Browse files
committed
fix: 适配认证网站 login.js 最新的指纹与加密逻辑
- 新增 `d_browser_md5` 和 `i` 字段提交,匹配后端新版校验规则 - 根据最新逻辑,对 `d_md5`、`d_browser_md5` 和 `i` 参数应用 `strEnc` 加密 - 移除之前存在异步 bug 的自定义 `hashString` 函数 - 改用网站原生的 `hex_md5` 全局函数进行同步哈希计算,确保数据生成正确
1 parent 7d96760 commit 3175ae2

1 file changed

Lines changed: 33 additions & 25 deletions

File tree

main.js

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// ==UserScript==
22
// @name Login Override
3-
// @version 0.3.1
3+
// @version 0.4.0
44
// @description Overrides the login function on a given website
55
// @match http://pass.sdu.edu.cn/cas/login*
66
// @match https://pass.sdu.edu.cn/cas/login*
@@ -20,24 +20,26 @@ const YOUR_CUSTOM_DEVICE_FINGERPRINT = "SOMETHING_UNIQUE";
2020

2121
(function () {
2222
"use strict";
23-
if (location.protocol === 'http:') {
24-
location.href = 'https:' + window.location.href.substring(window.location.protocol.length);
23+
if (location.protocol === "http:") {
24+
location.href =
25+
"https:" +
26+
window.location.href.substring(window.location.protocol.length);
2527
} // Redirect to HTTPS if not already
26-
if (location.href.startsWith('https://pass-sdu-edu-cn.atrust.sdu.edu.cn:81/')) {
27-
location.href = location.href.replace('https://pass-sdu-edu-cn.atrust.sdu.edu.cn:81/', 'https://pass-sdu-edu-cn-s.atrust.sdu.edu.cn:81/')
28+
if (
29+
location.href.startsWith("https://pass-sdu-edu-cn.atrust.sdu.edu.cn:81/")
30+
) {
31+
location.href = location.href.replace(
32+
"https://pass-sdu-edu-cn.atrust.sdu.edu.cn:81/",
33+
"https://pass-sdu-edu-cn-s.atrust.sdu.edu.cn:81/",
34+
);
2835
}
29-
if (location.href.startsWith('https://webvpn.sdu.edu.cn/http/')) {
30-
location.href = location.href.replace('https://webvpn.sdu.edu.cn/http/', 'https://webvpn.sdu.edu.cn/https/')
31-
}
32-
// Function to hash a string using SHA-256
33-
function hashString(str) {
34-
const encoder = new TextEncoder();
35-
const data = encoder.encode(str);
36-
const hashBuffer = crypto.subtle.digest('SHA-256', data);
37-
const hashArray = Array.from(new Uint8Array(hashBuffer));
38-
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
39-
return hashHex;
36+
if (location.href.startsWith("https://webvpn.sdu.edu.cn/http/")) {
37+
location.href = location.href.replace(
38+
"https://webvpn.sdu.edu.cn/http/",
39+
"https://webvpn.sdu.edu.cn/https/",
40+
);
4041
}
42+
4143
// Override the login function
4244
function login() {
4345
var $u = $("#un"),
@@ -67,15 +69,18 @@ const YOUR_CUSTOM_DEVICE_FINGERPRINT = "SOMETHING_UNIQUE";
6769
$("#pl").val(p.length);
6870
$("#rsa").val(strEnc(u + p + lt, "1", "2", "3"));
6971
var details_s = YOUR_CUSTOM_DEVICE_FINGERPRINT;
70-
var murmur = YOUR_CUSTOM_DEVICE_FINGERPRINT;
71-
var murmur_s = hashString(details_s);
72+
var details_browser_s = YOUR_CUSTOM_DEVICE_FINGERPRINT;
73+
var murmur_s = hex_md5(details_s);
7274
var murmur_md5 = hex_md5(details_s);
75+
var browser_md5 = hex_md5(details_browser_s);
7376
$.post(
7477
"device",
7578
{
7679
d: murmur,
7780
d_s: murmur_s,
78-
d_md5: murmur_md5,
81+
d_md5: strEnc(murmur_md5, "1", "2", "3"),
82+
d_browser_md5: strEnc(browser_md5, "1", "2", "3"),
83+
i: strEnc(details_s, "1", "2", "3"),
7984
m: "1",
8085
u: strEnc(u, "1", "2", "3"),
8186
p: strEnc(p, "1", "2", "3"),
@@ -84,23 +89,26 @@ const YOUR_CUSTOM_DEVICE_FINGERPRINT = "SOMETHING_UNIQUE";
8489
if (ret.info == "validErr" || ret.info == "notFound") {
8590
location.reload();
8691
} else if (ret.info == "bind") {
87-
//二次验证 绑定设备
92+
// 二次验证 绑定设备
8893
$("#phone").val(ret.m);
89-
phone(murmur_s, details_s);
94+
if (typeof phone === "function") {
95+
phone(murmur_s, details_s);
96+
}
9097
} else if (ret.info == "mobileErr") {
91-
//手机有误
98+
// 手机有误
9299
$("#errormsg2").show().text("尚未绑定手机");
93100
} else if (ret.info == "binded" || ret.info == "pass") {
94-
//直接提交
101+
// 直接提交
95102
$("#loginForm")[0].submit();
96103
}
97104
},
98-
"json"
105+
"json",
99106
).error(function (xhr, status, info) {
100-
if (is_weixin()) {
107+
if (typeof is_weixin === "function" && is_weixin()) {
101108
}
102109
});
103110
}
111+
104112
// Override the original login function with the modified one
105113
window.login = login;
106114
})();

0 commit comments

Comments
 (0)