Unlocking ChatGPT with Brook Server and Cloudfare Warp

Updated at: 2025-01-02

Introduction

Because OpenAI is not available in some regions, and most VPS providers' IPs have been banned. The purpose of this article is to find an available landing IP to access ChatGPT.

cloudflare warp

Tested in Ubuntu 22.04

curl https://pkg.cloudflareclient.com/pubkey.gpg | sudo gpg --yes --dearmor --output /usr/share/keyrings/cloudflare-warp-archive-keyring.gpg
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/cloudflare-warp-archive-keyring.gpg] https://pkg.cloudflareclient.com/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/cloudflare-client.list
apt update
apt install cloudflare-warp -y
echo y | warp-cli registration new
warp-cli mode proxy
warp-cli proxy port 1080
warp-cli connect
sleep 3
warp-cli status

You have a socks5 now: 127.0.0.1:1080

brook

bash <(curl https://bash.ooo/nami.sh)
nami install joker brook

Test your socks5

brook testsocks5 -s 127.0.0.1:1080
Testing TCP: query http3.ooo A on 8.8.8.8:53
2023/05/13 09:17:14 Sent NegotiationRequest: 0x5 0x1 []byte{0x0}
2023/05/13 09:17:14 Got NegotiationReply: 0x5 0x0
2023/05/13 09:17:14 Sent Request: 0x5 0x1 0x0 0x1 []byte{0x8, 0x8, 0x8, 0x8} []byte{0x0, 0x35}
2023/05/13 09:17:14 Got Reply: 0x5 0x0 0x0 0x1 []byte{0x7f, 0x0, 0x0, 0x1} []byte{0x0, 0x0}
TCP: OK
Testing UDP: query http3.ooo A on 8.8.8.8:53
2023/05/13 09:17:14 Sent NegotiationRequest: 0x5 0x1 []byte{0x0}
2023/05/13 09:17:14 Got NegotiationReply: 0x5 0x0
2023/05/13 09:17:14 Sent Request: 0x5 0x3 0x0 0x1 []byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0} []byte{0x0, 0x0}
2023/05/13 09:17:14 unexpected EOF

It can be seen that this socks5 only supports TCP and cannot process UDP. So we can only let the brook server block OpenAI's UDP and then forward OpenAI's TCP to Warp's socks5.

brook --script /path/to/script.tengo server --listen :9999 -p hello
match_domain := func(m, domain){
    text := import("text")
    ss := text.split(text.to_lower(domain), ".")
    s := ""
    for i := len(ss) - 1; i >= 0; i-- {
        if s == "" {
            s = ss[i]
        } else {
            s = ss[i] + "." + s
        }
        if m[s] {
            return true
        }
    }
    return false
}
match_openai := func(domain){
    m := {
        "ai.com": true,
        "chatgpt.com": true,
        "chat.com": true,
        "oaistatic.com": true,
        "oaiusercontent.com": true,
        "openai.com": true,
        "sora.com": true,
        "openaiapi-site.azureedge.net": true,
        "openaicom-api-bdcpf8c6d2e9atf6.z01.azurefd.net": true,
        "openaicomproductionae4b.blob.core.windows.net": true,
        "production-openaicom-storage.azureedge.net": true,
        "chatgpt.livekit.cloud": true,
        "host.livekit.cloud": true,
        "turn.livekit.cloud": true,
        "o33249.ingest.sentry.io": true,
        "openaicom.imgix.net": true,
        "browser-intake-datadoghq.com": true
    }
    if match_domain(m, domain) {
        return true
    }
    text := import("text")
    if text.contains(domain, "chatgpt-async-webps-prod") {
        return true
    }
    return false
}
f := func() {
    if in_brooklinks {
        return {
            "warp": "brook://socks5?password=&socks5=socks5%3A%2F%2F127.0.0.1%3A1080"
        }
    }
    if in_address {
        m := in_address
        if m.domainaddress {
            brook := import("brook")
            r := brook.splithostport(m.domainaddress)
            if m.network == "udp" && match_openai(r.host) {
                return { block: true }
            }
            if m.network == "tcp" && match_openai(r.host) {
                return { brooklinkkey: "warp" }
            }
        }
    }
}
out := f()