From e32b8796fc749b01e325c85d7e77b561da1a23e3 Mon Sep 17 00:00:00 2001 From: Antonio Date: Mon, 26 Jun 2023 23:17:39 +0800 Subject: [PATCH] arkose --- go.mod | 1 + go.sum | 2 ++ internal/chatgpt/request.go | 62 ++++++++++++++++++++++++++++--------- 3 files changed, 51 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index 5979f1d..e60c103 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( ) require ( + github.com/acheong08/funcaptcha v0.2.1-0.20230626140502-adeab195a0b3 // indirect github.com/andybalholm/brotli v1.0.5 // indirect github.com/bogdanfinn/utls v1.5.16 // indirect github.com/bytedance/sonic v1.9.1 // indirect diff --git a/go.sum b/go.sum index d1efd78..dfb32ed 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ github.com/acheong08/OpenAIAuth v0.0.0-20230609193408-55a0f33f1057 h1:AmqKpClFTU github.com/acheong08/OpenAIAuth v0.0.0-20230609193408-55a0f33f1057/go.mod h1:ES3Dh9hnbR2mDPlNTagj5e3b4nXECd4tbAjVgxggXEE= github.com/acheong08/endless v0.0.0-20230615162514-90545c7793fd h1:oIpfrRhD7Jus41dotbK+SQjWSFRnf1cLZUYCZpF/o/4= github.com/acheong08/endless v0.0.0-20230615162514-90545c7793fd/go.mod h1:0yO7neMeJLvKk/B/fq5votDY8rByrOPDubpvU+6saKo= +github.com/acheong08/funcaptcha v0.2.1-0.20230626140502-adeab195a0b3 h1:3SiHkE69H/JWT19fpIvjRScPDx5DnWnzzZpR5V4vHkQ= +github.com/acheong08/funcaptcha v0.2.1-0.20230626140502-adeab195a0b3/go.mod h1:fKxNB5i7g9h6QDTIY1YZamwFmMpAJK++wMYij5NuMm4= github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= github.com/bogdanfinn/fhttp v0.5.23 h1:4Xb5OjYArB8GpnUw4A4r5jmt8UW0/Cvey3R9nS2dC9U= diff --git a/internal/chatgpt/request.go b/internal/chatgpt/request.go index 7a4b397..26ae4c0 100644 --- a/internal/chatgpt/request.go +++ b/internal/chatgpt/request.go @@ -3,13 +3,22 @@ package chatgpt import ( "bufio" "bytes" + "encoding/base64" "encoding/json" + "errors" + "fmt" "freechatgpt/typings" chatgpt_types "freechatgpt/typings/chatgpt" "io" + "log" "math/rand" + "net/url" "os" + "strconv" "strings" + "time" + + arkose "github.com/acheong08/funcaptcha" http "github.com/bogdanfinn/fhttp" tls_client "github.com/bogdanfinn/tls-client" @@ -60,33 +69,51 @@ func init() { proxies = append(proxies, proxy) } } + // generate timestamp in 1687790752 format + timestamp := fmt.Sprintf("%d", time.Now().UnixNano()/1000000000) + bx = fmt.Sprintf(`[{"key":"api_type","value":"js"},{"key":"p","value":1},{"key":"f","value":"9711bd3695defe0844fb8fd8a722f38b"},{"key":"n","value":"%s"},{"key":"wh","value":"80b13fd48b8da8e4157eeb6f9e9fbedb|5ab5738955e0611421b686bc95655ad0"},{"key":"enhanced_fp","value":[{"key":"webgl_extensions","value":null},{"key":"webgl_extensions_hash","value":null},{"key":"webgl_renderer","value":null},{"key":"webgl_vendor","value":null},{"key":"webgl_version","value":null},{"key":"webgl_shading_language_version","value":null},{"key":"webgl_aliased_line_width_range","value":null},{"key":"webgl_aliased_point_size_range","value":null},{"key":"webgl_antialiasing","value":null},{"key":"webgl_bits","value":null},{"key":"webgl_max_params","value":null},{"key":"webgl_max_viewport_dims","value":null},{"key":"webgl_unmasked_vendor","value":null},{"key":"webgl_unmasked_renderer","value":null},{"key":"webgl_vsf_params","value":null},{"key":"webgl_vsi_params","value":null},{"key":"webgl_fsf_params","value":null},{"key":"webgl_fsi_params","value":null},{"key":"webgl_hash_webgl","value":null},{"key":"user_agent_data_brands","value":null},{"key":"user_agent_data_mobile","value":null},{"key":"navigator_connection_downlink","value":null},{"key":"navigator_connection_downlink_max","value":null},{"key":"network_info_rtt","value":null},{"key":"network_info_save_data","value":null},{"key":"network_info_rtt_type","value":null},{"key":"screen_pixel_depth","value":24},{"key":"navigator_device_memory","value":null},{"key":"navigator_languages","value":"en-US,en"},{"key":"window_inner_width","value":0},{"key":"window_inner_height","value":0},{"key":"window_outer_width","value":0},{"key":"window_outer_height","value":0},{"key":"browser_detection_firefox","value":true},{"key":"browser_detection_brave","value":false},{"key":"audio_codecs","value":"{\"ogg\":\"probably\",\"mp3\":\"maybe\",\"wav\":\"probably\",\"m4a\":\"maybe\",\"aac\":\"maybe\"}"},{"key":"video_codecs","value":"{\"ogg\":\"probably\",\"h264\":\"probably\",\"webm\":\"probably\",\"mpeg4v\":\"\",\"mpeg4a\":\"\",\"theora\":\"\"}"},{"key":"media_query_dark_mode","value":false},{"key":"headless_browser_phantom","value":false},{"key":"headless_browser_selenium","value":false},{"key":"headless_browser_nightmare_js","value":false},{"key":"document__referrer","value":""},{"key":"window__ancestor_origins","value":null},{"key":"window__tree_index","value":[1]},{"key":"window__tree_structure","value":"[[],[]]"},{"key":"window__location_href","value":"https://tcr9i.chat.openai.com/v2/1.5.2/enforcement.64b3a4e29686f93d52816249ecbf9857.html#35536E1E-65B4-4D96-9D97-6ADB7EFF8147"},{"key":"client_config__sitedata_location_href","value":"https://chat.openai.com/"},{"key":"client_config__surl","value":"https://tcr9i.chat.openai.com"},{"key":"mobile_sdk__is_sdk"},{"key":"client_config__language","value":null},{"key":"audio_fingerprint","value":"35.73833402246237"}]},{"key":"fe","value":["DNT:1","L:en-US","D:24","PR:1","S:0,0","AS:false","TO:0","SS:true","LS:true","IDB:true","B:false","ODB:false","CPUC:unknown","PK:Linux x86_64","CFP:330110783","FR:false","FOS:false","FB:false","JSF:Arial,Arial Narrow,Bitstream Vera Sans Mono,Bookman Old Style,Century Schoolbook,Courier,Courier New,Helvetica,MS Gothic,MS PGothic,Palatino,Palatino Linotype,Times,Times New Roman","P:Chrome PDF Viewer,Chromium PDF Viewer,Microsoft Edge PDF Viewer,PDF Viewer,WebKit built-in PDF","T:0,false,false","H:2","SWF:false"]},{"key":"ife_hash","value":"2a007a5daef41ee943d5fc73a0a8c312"},{"key":"cs","value":1},{"key":"jsbd","value":"{\"HL\":2,\"NCE\":true,\"DT\":\"\",\"NWD\":\"false\",\"DOTO\":1,\"DMTO\":1}"}]`, + base64.StdEncoding.EncodeToString([]byte(timestamp))) + // var bt = new Date() ['getTime']() / 1000 + bt := time.Now().UnixMicro() / 1000000 + // bw = Math.round(bt - (bt % 21600) + bw = strconv.FormatInt(bt-(bt%21600), 10) + token, err := Get_arkose_token() + if err != nil { + log.Fatal(err) + } + println(token) } func random_int(min int, max int) int { return min + rand.Intn(max-min) } -type arkose_response struct { - Token string `json:"token"` -} +var ( + bx string + bv string = "Mozilla/5.0 (X11; Linux x86_64; rv:114.0) Gecko/20100101 Firefox/114.0" + bw string +) func Get_arkose_token() (string, error) { - resp, err := client.Get("http://bypass.churchless.tech/api/arkose") - if err != nil { - return "", err + bda := arkose.Encrypt(bx, bv+bw) + bda = base64.StdEncoding.EncodeToString([]byte(bda)) + form := url.Values{ + "bda": {bda}, + "public_key": {"35536E1E-65B4-4D96-9D97-6ADB7EFF8147"}, + "site": {"https://chat.openai.com"}, + "userbrowser": {bv}, + "capi_version": {"1.5.2"}, + "capi_mode": {"lightbox"}, + "style_theme": {"default"}, + "rnd": {strconv.FormatFloat(rand.Float64(), 'f', -1, 64)}, } - defer resp.Body.Close() - payload, _ := io.ReadAll(resp.Body) - // println(string(payload)) - url := "https://tcr9i.chat.openai.com/fc/gt2/public_key/35536E1E-65B4-4D96-9D97-6ADB7EFF8147" - req, _ := http.NewRequest(http.MethodPost, url, bytes.NewReader(payload)) + req, _ := http.NewRequest(http.MethodPost, "https://tcr9i.chat.openai.com/fc/gt2/public_key/35536E1E-65B4-4D96-9D97-6ADB7EFF8147", strings.NewReader(form.Encode())) req.Header.Set("Host", "tcr9i.chat.openai.com") req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; rv:114.0) Gecko/20100101 Firefox/114.0") req.Header.Set("Accept", "*/*") req.Header.Set("Accept-Language", "en-US,en;q=0.5") req.Header.Set("Accept-Encoding", "gzip, deflate, br") - // form - req.Header.Set("Content-Type", "application/x-www-form-urlencoded") + req.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8") req.Header.Set("Origin", "https://tcr9i.chat.openai.com") req.Header.Set("DNT", "1") req.Header.Set("Connection", "keep-alive") @@ -95,11 +122,17 @@ func Get_arkose_token() (string, error) { req.Header.Set("Sec-Fetch-Mode", "cors") req.Header.Set("Sec-Fetch-Site", "same-origin") req.Header.Set("TE", "trailers") - resp, err = client.Do(req) + resp, err := client.Do(req) if err != nil { return "", err } defer resp.Body.Close() + if resp.StatusCode != 200 { + return "", errors.New("status code " + resp.Status) + } + type arkose_response struct { + Token string `json:"token"` + } var arkose arkose_response err = json.NewDecoder(resp.Body).Decode(&arkose) if err != nil { @@ -107,6 +140,7 @@ func Get_arkose_token() (string, error) { } println(arkose.Token) return arkose.Token, nil + } func POSTconversation(message chatgpt_types.ChatGPTRequest, access_token string) (*http.Response, error) {