Skip to content

Commit 998cda0

Browse files
author
cmd1152
committed
防dns污染
1 parent 0f7c6d3 commit 998cda0

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

HackChat-BotLib.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
let modules = {
2-
"WebSocket" : "ws"
2+
"WebSocket" : "ws",
3+
"https": "https"
34
}
5+
46
for (let module in modules) {
57
let module_name = module;
68
let module_path = modules[module_name];
79
try {
8-
require(module_path);
10+
global[module_name] = require(module_path);
911
} catch (e) {
1012
throw new Error(`导入${module_name}失败(位于${module_path})`)
1113
}
12-
global[module_name] = require(module_path);
1314
}
1415

1516
class Client {
1617
constructor(server_ip) {
17-
this._ws = new WebSocket(server_ip);
18+
this._ws = server_ip == "wss://hack.chat/chat-ws" ?
19+
new WebSocket('wss://104.131.138.176/chat-ws', {
20+
headers: {
21+
host: 'hack.chat' // 反DNS污染
22+
},
23+
rejectUnauthorized: false
24+
}):
25+
new WebSocket(server_ip)
1826
this._ws.onopen = () => {
1927
this.onjoin();
2028
}

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
这是一个一个用于使用Nodejs在 hack.chat 开发简单机器人的轻量框架
44
你可以查看[Wiki](https://github.com/cmd1152/hackchat-botlib/wiki)来了解用法
55

6+
**本框架通过伪造 SNI 请求头实现防 DNS 污染**
7+
68
使用这个框架,您就不必处理
9+
10+
- **DNS污染怎么办**
711
- 在线列表
812
- 机器人在用户手动改名(比如直接执行代码发送changeNick)后怎么知道新名称
913
- whisper和emote怎么提取用户原始内容

0 commit comments

Comments
 (0)