https://www.txthinking.com/talks/
Created at: 15 Nov 2021
Updated at: 12 Dec 2022
cloud@txthinking.com
https://www.txthinking.com/shiliew.html
在图形客户端的左边菜单的 Proxy & Tun 里面可以看到 proxy 模式, 此模式下会忽略: Bypass IP, DNS, Fake DNS, Block list, Block 配置项.
此模式下, 会创建:
socks5://[::1]:1080
, IPv4 网络下可能会创建 socks5://127.0.0.1:1080
curl -x socks5://[::1]:1080 http3.ooo
或 curl -x socks5://127.0.0.1:1080 http3.ooo
http://[::1]:8010
, IPv4 网络下可能会创建 http://127.0.0.1:8010
curl -x http://[::1]:1080 http3.ooo
或 curl -x http://127.0.0.1:1080 http3.ooo
如果走系统代理, 比如 Chrome:
域名未匹配到 Bypass Domain 列表(域名解析会在服务端完成)
发起请求 --HTTP/HTTPS(TCP)--> pac server --> Shiliew 客户端 --(Brook协议)--> brook server/wsserver/wssserver --HTTP/HTTPS(TCP)--> 目的地
域名匹配到 Bypass Domain 列表(域名解析会在本地完成)
发起请求 --HTTP/HTTPS(TCP)--> pac server --> 本机 --HTTP/HTTPS(TCP)--> 目的地
如果不走系统代理, 比如在 Telegram 客户端单独配置了上面创建出来的 socks5 代理:
发起请求 --TCP/UDP--> socks5 代理 --TCP/UDP--> Shiliew 客户端 --(Brook协议)--> brook server/wsserver/wssserver --TCP/UDP--> 目的地
可以指定
8.8.8.8
2001:4860:4860::8888
223.5.5.5:53
https://dns.alidns.com/dns-query?address=223.5.5.5%3A443
[2400:3200::1]:53
https://dns.alidns.com/dns-query?address=%5B2400%3A3200%3A%3A1%5D%3A443
Shiliew 客户端会根据当前网络 IPv4/IPv6 情况以及服务端 IPv4/IPv6 自动选择配置系统 v4 DNS 或 v6 DNS.
我们知道, 一个网络请求, 一般首先查询域名得到 IP, 然后再向 IP 发起请求.
首先是 DNS 查询域名的 IP
向 系统 DNS 发起查询
如果系统 DNS 未匹配到 bypass (系统 DNS 也是一个 IP 呀)
发起 DNS 查询 --(DNS 协议)--> Shiliew 客户端 --(Brook 协议)--> brook server/wsserver/wssserver --(DNS 协议)--> 系统 DNS
如果系统 DNS 匹配到 bypass (系统 DNS 也是一个 IP 呀)
发起 DNS 查询 --(DNS 协议)--> Shiliew 客户端 --(DNS 协议)--> 系统 DNS
已经查询到域名的 IP, 准备向此目标 IP 发起网络请求
如果 IP 未匹配到 bypass
发起请求 --TCP/UDP--> Shiliew 客户端 --(Brook 协议)--> brook server/wsserver/wssserver --TCP/UDP--> 目标 IP
如果 IP 匹配到 bypass
发起请求 --TCP/UDP--> Shiliew 客户端 --TCP/UDP--> 目标 IP
我们知道, 一个网络请求, 一般首先查询域名得到 IP, 然后再向 IP 发起请求.
首先是 DNS 查询域名的 IP
域名匹配到 bypass 域名列表
向 bypass DNS 发起查询
如果 bypass DNS 未匹配到 bypass(bypass DNS 也是一个 IP 呀)
发起 DNS 查询 --(DNS 协议)--> Shiliew 客户端 --(Brook 协议)--> brook server/wsserver/wssserver --(DNS 协议)--> bypass DNS
如果 bypass DNS 匹配到 bypass(bypass DNS 也是一个 IP 呀)
发起 DNS 查询 --(DNS 协议)--> Shiliew 客户端 --(DNS 协议)--> bypass DNS
已经查询到域名的 IP, 准备向此目标 IP 发起网络请求
如果是 Fake IP(域名真实解析会在服务端完成)
Shiliew 客户端 --(将 Fake IP 转换成原始域名)--(Brook 协议)--> brook server/wsserver/wssserver --TCP/UDP--> 目的地
如果不是 Fake IP
如果 IP 未匹配到 bypass CIDR 列表
发起请求 --TCP/UDP--> Shiliew 客户端 --(Brook 协议)--> brook server/wsserver/wssserver --TCP/UDP--> 目标IP
如果 IP 匹配到 bypass CIDR 列表
发起请求 --TCP/UDP--> Shiliew 客户端 --TCP/UDP--> 目标 IP
目前 Android 系统内置 Private DNS(DoT), 以及桌面和手机版 Chrome 提供内置安全 DNS(DoH). 这对理想全量 Anycast 网络世界且未使用代理的普通用户的 DNS 查询在中间网络能达到加密作用. 但现实是不理想的.
假设一个域名针对多个地区提供不同的 IP,而最终解析出来的 IP 取决于:
而当开启 DoT 或 DoH 时,无法拦截查询内容以进行针对不同域名使用不同的 DNS 解析的效果, 也无法使用 FakeDNS 进行服务端解析域名以避免多一次网络请求.
所以我们要关闭它:
不会. 你可以在 Shiliew GUI 开启 FakeDNS 或配置 DoH.
注意:此功能需要编程能力,会运行你的脚本来达到拦截并修改 HTTP 和 HTTPS 的目的。同时,如果如果写得复杂可能会占用更多资源和性能。
https://txthinking.github.io/ca/ca.pem
MITM 需要使用 tun 模式
nami install mad ca.txthinking
sudo mad install --ca ~/.nami/bin/ca.pem
MITM 需要使用 tun 模式
nami install mad ca.txthinking
用管理员打开 GitBash
mad install --ca ~/.nami/bin/ca.pem
https://www.youtube.com/watch?v=HSGPC2vpDGk
Android 分系统 CA 和用户 CA,必须要 ROOT 后安装到系统 CA 里
一行一个协议和地址
http://
和 https://
示例
http://http3.ooo:80
https://http3.ooo:443
https://4.http3.ooo:443
https://6.http3.ooo:443
https://txthinking.github.io/bypass/mitm.txt
request
代表一个 HTTP Request, 是一个 map
{
"Method": "GET", // string, request method
"URL": "https://http3.ooo/", // string, request url
"Body": bytes, // bytes, request body
"...": "...",
"User-Agent": "...", // string, all other keys are request header
"...": "..."
}
response
代表一个 HTTP Response, 是一个 map
{
"StatusCode": 200, // int, response status code
"Body": bytes, // bytes, request body
"...": "...",
"Server": "txthinking", // string, all other keys are response header
"...": "..."
}
request
传递给脚本, response
此时为 undefined
. 脚本可以选择:
request
并 return request
response
. 流程结束request
发往服务端response
response
传递给脚本, request
此时为第一步 return 的request
, 脚本必须: 修改或不修改 response
并 return response
如果未开启
request["Body"]
为空。
request["Body"]
会被忽略. 仍使用原始 request 的 Body 发往服务端response["Body"]
也会被忽略. 仅响应给客户端 StatusCode
和 header 们response["Body"]
和 request["Body"]
为空。同时脚本返回的 response["Body"]
也会被忽略. 仍使用原始 response 的 body 响应给客户端如果开启. 会消耗更多内存
request["Body"]
不为空
request["Body"]
作为 request 的 Body 发往服务端response["Body"]
作为 response 的 Body 发往客户端response["Body"]
和 request["Body"]
不为空。同时脚本返回的 response["Body"]
会作为 response 的 Body 发往客户端text := import("text")
_ := (func(request, response) {
// Begin
if(!response){
if(text.has_prefix(request["URL"], "http://http3.ooo")){
return {
"StatusCode": 301,
"Location": text.replace(request["URL"], "http://", "https://", 1)
}
}
if(text.has_prefix(request["URL"], "https://http3.ooo")){
request["User-Agent"] = "curl/7.79.1"
return request
}
return request
}
if(text.has_prefix(request["URL"], "https://6.http3.ooo")){
response["Body"] = bytes("You hacked me :)")
return response
}
return response
// End
})(request, response)
你可以使用 App Privacy Report mitmproxy helper 和 Wireshark Helper 抓包来确定要修改什么. 手机抓包软件的原理区别
使用 tun2brook 调试脚本, 这样你可以在脚本内打印数据
macOS 和 Windows 需要开启 tun 模式
建议仅在必要时开启. 防止日志文件过大.
要接收推送,Apple Server 只允许 Ethernet, cellular data, Wi-Fi 连接. 所以你需要 Bypass 掉相关域名和 IP:
https://support.apple.com/en-us/HT210060
https://support.apple.com/en-us/HT210060
Domain
apple.com
icloud.com
cdn-apple.com
mzstatic.com
entrust.net
digicert.com
verisign.net
apple
CIDR4
17.0.0.0/8
103.81.148.0/22
103.81.148.0/24
103.81.149.0/24
CIDR6
2620:149:a44::/48
2403:300:a42::/48
2403:300:a51::/48
2a01:b740:a42::/48