From 70e096a2325b1462ccc23b331c5fa219e4f27bc6 Mon Sep 17 00:00:00 2001 From: Harry-zklcdc Date: Thu, 25 Jan 2024 22:58:22 +0800 Subject: [PATCH] =?UTF-8?q?[Fix]=20=F0=9F=90=9B=20Bypass=20Repeat=20when?= =?UTF-8?q?=20Token=20haven?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/bypass.go | 11 +++++- api/challenge.go | 52 +++++++++++--------------- api/v1/chat.go | 4 +- api/v1/func.go | 4 +- api/v1/image.go | 2 +- api/verify.go | 50 +++++++++++++++++++++++++ frontend/public/js/bing/chat/global.js | 2 +- frontend/types/bing/index.d.ts | 1 + main.go | 1 + vercel.json | 6 ++- 10 files changed, 94 insertions(+), 39 deletions(-) create mode 100644 api/verify.go diff --git a/api/bypass.go b/api/bypass.go index 4ba8dc6403..ac5afc6abe 100644 --- a/api/bypass.go +++ b/api/bypass.go @@ -13,12 +13,16 @@ import ( ) type passRequestStruct struct { + IG string `json:"IG,omitempty"` Cookies string `json:"cookies"` Iframeid string `json:"iframeid,omitempty"` + ConvId string `json:"convId,omitempty"` + RId string `json:"rid,omitempty"` } type requestStruct struct { Url string `json:"url"` + IG string `json:"IG,omitempty"` } type PassResponseStruct struct { @@ -61,7 +65,7 @@ func BypassHandler(w http.ResponseWriter, r *http.Request) { request.Url = common.BypassServer } - resp, err := Bypass(request.Url, r.Header.Get("Cookie"), "local-gen-"+hex.NewUUID()) + resp, err := Bypass(request.Url, r.Header.Get("Cookie"), "local-gen-"+hex.NewUUID(), request.IG, "", "") if err != nil { helper.CommonResult(w, http.StatusInternalServerError, err.Error(), nil) return @@ -70,10 +74,13 @@ func BypassHandler(w http.ResponseWriter, r *http.Request) { w.Write(body) } -func Bypass(bypassServer, cookie, iframeid string) (passResp PassResponseStruct, err error) { +func Bypass(bypassServer, cookie, iframeid, IG, convId, rid string) (passResp PassResponseStruct, err error) { passRequest := passRequestStruct{ Cookies: cookie, Iframeid: iframeid, + IG: IG, + ConvId: convId, + RId: rid, } passResq, err := json.Marshal(passRequest) if err != nil { diff --git a/api/challenge.go b/api/challenge.go index 965eab086a..5733c8d8a3 100644 --- a/api/challenge.go +++ b/api/challenge.go @@ -2,17 +2,31 @@ package api import ( "adams549659584/go-proxy-bingai/api/helper" - "adams549659584/go-proxy-bingai/common" + "fmt" "net/http" - "strings" ) -const respHtml = ` +const respChallengeHtml = ` ` @@ -27,28 +41,6 @@ func ChallengeHandler(w http.ResponseWriter, r *http.Request) { return } - reqCookies := strings.Split(r.Header.Get("Cookie"), "; ") - bypassServer := common.BypassServer - for _, cookie := range reqCookies { - if strings.HasPrefix(cookie, "BingAI_Pass_Server") { - tmp := strings.ReplaceAll(cookie, "BingAI_Pass_Server=", "") - if tmp != "" { - bypassServer = tmp - } - } - } - - resp, err := Bypass(bypassServer, r.Header.Get("Cookie"), "") - if err != nil { - helper.CommonResult(w, http.StatusInternalServerError, err.Error(), nil) - return - } - - cookies := strings.Split(resp.Result.Cookies, "; ") - for _, cookie := range cookies { - w.Header().Add("Set-Cookie", cookie+"; path=/") - } - - // helper.CommonResult(w, http.StatusOK, "ok", resp) - w.Write([]byte(respHtml)) + w.Header().Set("Content-Type", "text/html; charset=utf-8") + w.Write([]byte(fmt.Sprintf(respChallengeHtml, r.URL.Query().Get("iframeid")))) } diff --git a/api/v1/chat.go b/api/v1/chat.go index b5eb12b27f..82c17638b0 100644 --- a/api/v1/chat.go +++ b/api/v1/chat.go @@ -135,7 +135,7 @@ func ChatHandler(w http.ResponseWriter, r *http.Request) { if tmp == "User needs to solve CAPTCHA to continue." && common.BypassServer != "" { go func(cookie string) { - t, _ := getCookie(cookie) + t, _ := getCookie(cookie, chat.GetChatHub().GetConversationId(), hex.NewUUID()) if t != "" { globalChat.SetCookies(t) } @@ -172,7 +172,7 @@ func ChatHandler(w http.ResponseWriter, r *http.Request) { if text == "User needs to solve CAPTCHA to continue." && common.BypassServer != "" { go func(cookie string) { - t, _ := getCookie(cookie) + t, _ := getCookie(cookie, chat.GetChatHub().GetConversationId(), hex.NewUUID()) if t != "" { globalChat.SetCookies(t) } diff --git a/api/v1/func.go b/api/v1/func.go index 6ce78c7c4b..222c9d8902 100644 --- a/api/v1/func.go +++ b/api/v1/func.go @@ -9,7 +9,7 @@ import ( "github.com/Harry-zklcdc/bing-lib/lib/request" ) -func getCookie(reqCookie string) (cookie string, err error) { +func getCookie(reqCookie, convId, rid string) (cookie string, err error) { cookie = reqCookie c := request.NewRequest() res := c.SetUrl(common.BingBaseUrl+"/search?q=Bing+AI&showconv=1&FORM=hpcodx&ajaxhist=0&ajaxserp=0&cc=us"). @@ -24,7 +24,7 @@ func getCookie(reqCookie string) (cookie string, err error) { } } cookie = strings.TrimLeft(strings.Trim(cookie, "; "), "; ") - resp, err := api.Bypass(common.BypassServer, cookie, "local-gen-"+hex.NewUUID()) + resp, err := api.Bypass(common.BypassServer, cookie, "local-gen-"+hex.NewUUID(), strings.ToUpper(hex.NewHex(32)), convId, rid) if err != nil { return } diff --git a/api/v1/image.go b/api/v1/image.go index 3abc7fd1a4..ac6a5e4cf4 100644 --- a/api/v1/image.go +++ b/api/v1/image.go @@ -38,7 +38,7 @@ func ImageHandler(w http.ResponseWriter, r *http.Request) { cookie = common.USER_TOKEN_LIST[rng.Intn(len(common.USER_TOKEN_LIST))] } else { if common.BypassServer != "" { - t, _ := getCookie(cookie) + t, _ := getCookie(cookie, "", "") if t != "" { cookie = t } diff --git a/api/verify.go b/api/verify.go new file mode 100644 index 0000000000..1a299abe7b --- /dev/null +++ b/api/verify.go @@ -0,0 +1,50 @@ +package api + +import ( + "adams549659584/go-proxy-bingai/api/helper" + "adams549659584/go-proxy-bingai/common" + "net/http" + "net/url" + "strings" +) + +func VerifyHandler(w http.ResponseWriter, r *http.Request) { + if !helper.CheckAuth(r) { + helper.UnauthorizedResult(w) + return + } + + if r.Method != "GET" { + helper.CommonResult(w, http.StatusMethodNotAllowed, "Method Not Allowed", nil) + return + } + + reqCookies := strings.Split(r.Header.Get("Cookie"), "; ") + bypassServer := common.BypassServer + for _, cookie := range reqCookies { + if strings.HasPrefix(cookie, "BingAI_Pass_Server") { + tmp := strings.ReplaceAll(cookie, "BingAI_Pass_Server=", "") + if tmp != "" { + bypassServer = tmp + } + } + } + + queryRaw := r.URL.Query() + iframeid, _ := url.QueryUnescape(queryRaw.Get("iframeid")) + IG, _ := url.QueryUnescape(queryRaw.Get("IG")) + convId, _ := url.QueryUnescape(queryRaw.Get("convId")) + rid, _ := url.QueryUnescape(queryRaw.Get("rid")) + resp, err := Bypass(bypassServer, r.Header.Get("Cookie"), iframeid, IG, convId, rid) + if err != nil { + helper.CommonResult(w, http.StatusInternalServerError, err.Error(), nil) + return + } + + cookies := strings.Split(resp.Result.Cookies, "; ") + for _, cookie := range cookies { + w.Header().Add("Set-Cookie", cookie+"; path=/") + } + + helper.CommonResult(w, http.StatusOK, "ok", resp) +} diff --git a/frontend/public/js/bing/chat/global.js b/frontend/public/js/bing/chat/global.js index f1c63e1d50..94b4306955 100644 --- a/frontend/public/js/bing/chat/global.js +++ b/frontend/public/js/bing/chat/global.js @@ -98,7 +98,7 @@ _G = { SUIH: randomString(22), adc: 'b_ad', // logsb 启用 sendBeacon 推送日志,并在 sendBeacon 阻止 - EF: { cookss: 1, bmcov: 1, crossdomainfix: 1, bmasynctrigger: 1, bmasynctrigger3: 1, newtabsloppyclick: 1, chevroncheckmousemove: 1, logsb: 1 }, + EF: { cookss: 1, bmcov: 1, crossdomainfix: 1, bmasynctrigger: 1, bmasynctrigger3: 1, getslctspt: 1, newtabsloppyclick: 1, chevroncheckmousemove: 1, sharepreview: 1, sharenewlayout: 1, cdxsugchip2: 1 }, gpUrl: '/fd/ls/GLinkPing.aspx?', }; _G.lsUrl = '/fd/ls/l?IG=' + _G.IG; diff --git a/frontend/types/bing/index.d.ts b/frontend/types/bing/index.d.ts index dfee78ddc0..f79c4cae52 100644 --- a/frontend/types/bing/index.d.ts +++ b/frontend/types/bing/index.d.ts @@ -116,6 +116,7 @@ interface BingConversation { conversationType: string; hashedSignature: string; id: string; + convId: string; isExpired: boolean; messages: TextMessageModel[]; state: string; diff --git a/main.go b/main.go index 07b43f76f2..d324475621 100644 --- a/main.go +++ b/main.go @@ -23,6 +23,7 @@ func main() { http.HandleFunc("/pass", api.BypassHandler) http.HandleFunc("/turing/captcha/challenge", api.ChallengeHandler) + http.HandleFunc("/challenge/verify", api.VerifyHandler) http.HandleFunc("/sydney/", api.Sydney) diff --git a/vercel.json b/vercel.json index abeee6d916..ac473b7def 100644 --- a/vercel.json +++ b/vercel.json @@ -3,7 +3,7 @@ "version": 2, "builds": [ { - "src": "/api/{index,web,sydney,sys-config,bypass,challenge}.go", + "src": "/api/{index,web,sydney,sys-config,bypass,challenge,verify}.go", "use": "@vercel/go" }, { @@ -24,6 +24,10 @@ "src": "/turing/captcha/challenge", "dest": "/api/challenge.go" }, + { + "src": "/challenge/verify", + "dest": "/api/verify.go" + }, { "src": "/v1/chat/completions", "dest": "/api/v1/chat.go"