Shiliew GUI 工作原理

https://www.txthinking.com/talks/
Created at: 15 Nov 2021
Updated at: 12 Dec 2022
cloud@txthinking.com

Table of Contents

Shiliew

https://www.txthinking.com/shiliew.html

macOS 图形客户端 proxy 模式, Windows 图形客户端 proxy 模式

在图形客户端的左边菜单的 Proxy & Tun 里面可以看到 proxy 模式, 此模式下会忽略: Bypass IP, DNS, Fake DNS, Block list, Block 配置项.

此模式下, 会创建:

规则

数据流向

macOS 图形客户端 tun 模式, Windows 图形客户端 tun 模式, iOS 图形客户端, Android 图形客户端

规则

可以指定

数据流向

配置系统 DNS

Shiliew 客户端会根据当前网络 IPv4/IPv6 情况以及服务端 IPv4/IPv6 自动选择配置系统 v4 DNS 或 v6 DNS.

Fake DNS 关闭时

我们知道, 一个网络请求, 一般首先查询域名得到 IP, 然后再向 IP 发起请求.

  1. 某个应用准备发起网络请求
  2. 首先是 DNS 查询域名的 IP

  3. 已经查询到域名的 IP, 准备向此目标 IP 发起网络请求

Fake DNS 开启时

我们知道, 一个网络请求, 一般首先查询域名得到 IP, 然后再向 IP 发起请求.

  1. 某个应用准备发起网络请求
  2. 首先是 DNS 查询域名的 IP

  3. 已经查询到域名的 IP, 准备向此目标 IP 发起网络请求

为什么以及如何关闭系统和浏览器安全 DNS

目前 Android 系统内置 Private DNS(DoT), 以及桌面和手机版 Chrome 提供内置安全 DNS(DoH). 这对理想全量 Anycast 网络世界且未使用代理的普通用户的 DNS 查询在中间网络能达到加密作用. 但现实是不理想的.

假设一个域名针对多个地区提供不同的 IP,而最终解析出来的 IP 取决于:

  1. 使用的 DNS Server
  2. 发起 DNS 查询的网络

而当开启 DoT 或 DoH 时,无法拦截查询内容以进行针对不同域名使用不同的 DNS 解析的效果, 也无法使用 FakeDNS 进行服务端解析域名以避免多一次网络请求.

所以我们要关闭它:

关闭了会有降低安全性吗

不会. 你可以在 Shiliew GUI 开启 FakeDNS 或配置 DoH.

MITM

注意:此功能需要编程能力,会运行你的脚本来达到拦截并修改 HTTP 和 HTTPS 的目的。同时,如果如果写得复杂可能会占用更多资源和性能。

ROOT CA

https://txthinking.github.io/ca/ca.pem

要求

macOS

MITM 需要使用 tun 模式

nami install mad ca.txthinking
sudo mad install --ca ~/.nami/bin/ca.pem

Windows

MITM 需要使用 tun 模式

nami install mad ca.txthinking

用管理员打开 GitBash

mad install --ca ~/.nami/bin/ca.pem

iOS

https://www.youtube.com/watch?v=HSGPC2vpDGk

Android

Android 分系统 CA 和用户 CA,必须要 ROOT 后安装到系统 CA 里

规则

一行一个协议和地址

示例

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

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

response 代表一个 HTTP Response, 是一个 map

{
	"StatusCode": 200, // int, response status code
	"Body": bytes, // bytes, request body
	"...": "...",
	"Server": "txthinking", // string, all other keys are response header
	"...": "..."
}

流程

  1. Shiliew 先匹配到规则地址, 然后根据规则内地址对应的协议准备数据
  2. Shiliew 将 request 传递给脚本, response 此时为 undefined. 脚本可以选择:
  3. Shiliew 将脚本 return 的 request 发往服务端
  4. Shiliew 从目的地获取到 response
  5. Shiliew 将 response 传递给脚本, request 此时为第一步 return 的request, 脚本必须: 修改或不修改 response 并 return response

MITM with 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 helperWireshark Helper 抓包来确定要修改什么. 手机抓包软件的原理区别

使用 tun2brook 调试脚本, 这样你可以在脚本内打印数据

Log

macOS 和 Windows 需要开启 tun 模式

建议仅在必要时开启. 防止日志文件过大.

Apple 推送问题

要接收推送,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

Enjoy