在 Node.js 上代理 MCBE 服务器并中间人(MITM)攻击(基于 bedrock-protocol)

你需要一个安装了 Node.js 20 及以上版本的终端,可以是命令提示符、PowerShell、SSH 或是 Termux(对于 Android),以及一个代码编辑器

首先,创建一个工作目录,并进入这个目录

安装 bedrock-protocol

以 npm 包管理器为例,运行

1
npm install bedrock-protocol

终端回显

1
2
3
4
5
6
7
8
9
10
11
12
npm warn deprecated [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated [email protected]: Rimraf versions prior to v4 are no longer supported
npm warn deprecated [email protected]: Glob versions prior to v9 are no longer supported
npm warn deprecated [email protected]: This package is no longer supported.
npm warn deprecated [email protected]: This package is no longer supported.
npm warn deprecated [email protected]: This package is no longer supported.
npm warn deprecated [email protected]: This package is no longer supported.

added 156 packages in 8s

8 packages are looking for funding
run `npm fund` for details

过程中可能会有一些警告,看到 added 156 packages in 8s 等提示大概是安装成功了

代理一个服务器并中间人攻击

创建一个 js 文件,比如说 myproxy.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
const { Relay } = require('bedrock-protocol')
// 从 bedrock-protocol 导入 Relay

const relay = new Relay({
version: '26.10', // 版本一般是全覆盖的,从 1.7 到最新的都行
host: '0.0.0.0', // 监听的地址,一般填 0.0.0.0
port: 19133, // 监听的端口,这是本地代理开放的端口
destination: {
host: 'example.com', // 被代理服务器的地址
port: 19132 // 被代理服务器的端口
}
})
relay.listen()
// 开始监听端口

relay.on('connect', player => {
// 玩家连接到代理
player.on('clientbound', ({ name, params }) => {
// 代理收到来自上游服务器的数据包(S -> C)
if (name === 'disconnect') { // 以断开连接数据包为例
params.message = 'Intercepted'
// 可以直接通过访问 params 的属性来读取和修改数据包(以修改踢出游戏的提示为例)
}
})
player.on('serverbound', ({ name, params }) => {
// 代理收到来自下游玩家的数据包(C -> S)
if (name === 'text') { // 以发送信息数据包为例
params.message += `, from MITM`
// 修改玩家发往服务器的聊天信息
}
})
})

运行这个 js

1
node myproxy.js

此时代理服务器会启动,使用 MCBE 进入 127.0.0.1 19133 就可以代理数据包了

更多请参考 PrismarineJS/bedrock-protocol: Minecraft Bedrock protocol library, with authentication and encryption

关于作弊功能的实现

参考本博客其他博文或其他教程

参考文献