937 words
5 minutes
Telegram MTP Server
前言
在VPS上使用Systemd的方式部署搭建Mtproto服务器
1.Python实现版本
操作简单,部署快,默认fake-TLS模式
(本文内容基于Debian Linux 系统,其他Linux发行版请根据实际情况调整命令)
1.1安装软件包
apt update && \apt install -y git python3 python3-pip openssl xxd- openssl、xxd用于生成密钥和格式化
1.2克隆源代码
切换至一个合适的、易记的目录位置 cd /opt
# 下载源代码git clone https://github.com/Tychristine/mtprotoproxy.git# 切换到项目主目录cd mtprotoproxy1.3配置准备
主要是生成密钥和备选TLS模式的伪装域名
1.3.1选择TLS域名(重要)
选择的目标完整需要满足以下条件
- TLSv1.3 和 X25519MLKEM768加密和身份验证(非常重要)
浏览器按下F12,打开
浏览器开发者工具,选项卡调整为Prolicy and Security(隐私和安全),然后访问你的目标域名查看概览中的TLS版本和加密套件.
//推荐的域名valorant.secure.dyn.riotcdn.netfastcdn.hoyoverse.comlol.dyn.riotcdn.netendfield.gryphline.comlolesports.com1.3.2生成密钥(前半部分)
# 生成 32位16进制(HEX) 的字符串作为密钥openssl rand -hex 161.3.3生成密钥(后半部分)
# 引号内填入你选择的目标echo -n "目标域名" | xxd -p1.4填写配置
编辑文件 config.py
# 监听端口号PORT = 9090# 填入32位密钥USERS = { "tg": "32-bit-key",}# 填入目标域名TLS_DOMAIN = "domain"1.5服务单元
运行命令语法: python3 <主程序路径> <配置文件路径>
1.6编辑服务单元
编辑文件mtp.service
注意编辑第6行的ExecStart启动命令与你的实际路径相符.
[Unit] Description=Async MTProto proxy for Telegram After=network-online.target Wants=network-online.target[Service] ExecStart=python3 /opt/mtprotoproxy/mtprotoproxy.py /opt/mtprotoproxy/config.py AmbientCapabilities=CAP_NET_BIND_SERVICE LimitNOFILE=infinity User=root Group=root Restart=on-failure[Install] WantedBy=multi-user.target# 复制文件到系统服务,注册服务单元cp mtp.service /etc/systemd/system/mtp.service# 重载系统服务列表systemctl daemon-reload# 启动服务systemctl start mtp# 设置开机自启systemctl enable mtp# 查看服务状态systemctl status mtp# 出现🟢Active: active (running)则🆗1.7客户端配置
Server 主机地址,尽量使用IP
Port 端口号
Secret 完整密钥
Mtproto密钥组成结构: ee+{32位16进制字符串}+{目标域名的16进制表示}
按照此教程顺序则为:
ee+密钥前半+密钥后半
1.8TG客户端快捷链接
tg://proxy?server={Server}&port={Port}&secret={Sercret}
2.C语言原版实例
此仓库为继承原版仓库TelegramMessenger/MTProxy的社区维护分支
2.1从源代码构建
2.1.1安装软件包
apt install -y git curl build-essential libssl-dev zlib1g-dev2.1.2克隆源代码
选个便于整理的目录 cd /opt
git clone https://github.com/GetPageSpeed/MTProxycd MTProxy修改源代码中的不合理之处
编辑文件 common\pid.c
找到以下函数片段
void init_common_PID (void) { if (!PID.pid) { int p = getpid (); // assert (!(p & 0xffff0000)); PID.pid = p; }修改为
void init_common_PID (void) { if (!PID.pid) { pid_t p = getpid (); PID.pid = p; }2.1.3执行构建任务
make && cd objs/bin# 取出二进制文件 到 /opt/MTProxymv mtproto-proxy ../../# 授权运行权限chmod +x mtproto-proxy2.2安装
2.2.1下载密钥
curl -s https://core.telegram.org/getProxySecret -o proxy-secret2.2.2下载服务器列表
curl -s https://core.telegram.org/getProxyConfig -o proxy-multi.conf2.2.3生成32位16进制密钥
head -c 16 /dev/urandom | xxd -ps2.3运行
运行命令示例
./mtproto-proxy -u nobody -p 8888 -H 443 -S <secret> --http-stats --aes-pwd proxy-secret proxy-multi.conf -M 1- nobody is the username. calls to drop privilegies.mtproto-proxysetuid()
- 443 is the port, used by clients to connect to the proxy.
- 8888 is the local port for statistics (requires ). Like . You can only get this - stat via loopback.—http-statscurl http://localhost:8888/stats
is the secret generated at step 3. Also you can set multiple secrets: .- -S -S - proxy-secret and are obtained at steps 1 and 2.proxy-multi.conf
- 1 is the number of workers. You can increase the number of workers, if you have - a powerful server.
2.4systemd服务单元
[Unit]Description=MTProxyAfter=network.target
[Service]Type=simpleWorkingDirectory=/opt/MTProxyExecStart=/opt/MTProxy/mtproto-proxy -u nobody -p 8888 -H 443 -S <secret> --http-stats --aes-pwd proxy-secret proxy-multi.conf -M 1Restart=on-failure
[Install]WantedBy=multi-user.target编辑第8行的443端口和<secret>
然后就和1.6 一样了
客户端密码的组成为 dd+{32位密钥}
Telegram MTP Server
https://fuwari.vercel.app/posts/tg/