From 485eef60ccd8df97c133f8803110be411db9fea9 Mon Sep 17 00:00:00 2001 From: Antonio Date: Mon, 26 Jun 2023 22:36:13 +0800 Subject: [PATCH] native funcaptcha by @flyingpot --- arkose.go | 109 ++++++++++++++++++++++++++++++++++++++++++----------- funcaptcha | 1 + go.mod | 1 + go.sum | 2 + 4 files changed, 90 insertions(+), 23 deletions(-) create mode 160000 funcaptcha diff --git a/arkose.go b/arkose.go index f64f651..5533540 100644 --- a/arkose.go +++ b/arkose.go @@ -1,38 +1,101 @@ package main -import "encoding/json" +import ( + "encoding/base64" + "encoding/json" + "errors" + "log" + "math/rand" + "net/url" + "strconv" + "strings" + "time" -// import ( -// arkose "github.com/flyingpot/funcaptcha" -// ) + http "github.com/bogdanfinn/fhttp" -// func get_arkose_token() (string, error) { -// options := arkose.GetTokenOptions{ -// PKey: "35536E1E-65B4-4D96-9D97-6ADB7EFF8147", -// SURL: "https://tcr9i.chat.openai.com", -// Headers: map[string]string{ -// "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36", -// }, -// Site: "https://chat.openai.com", -// } -// result, err := arkose.GetToken(&options) -// println(result.Token) -// return result.Token, err -// } + arkose "github.com/acheong08/funcaptcha" +) + +var ( + bx string = `[{"key":"api_type","value":"js"},{"key":"p","value":1},{"key":"f","value":"9711bd3695defe0844fb8fd8a722f38b"},{"key":"n","value":"MTY4Nzc4ODQyMw=="},{"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}"}]` + bv string = "Mozilla/5.0 (X11; Linux x86_64; rv:114.0) Gecko/20100101 Firefox/114.0" + bw string +) + +func init() { + // 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 get_arkose_token() (string, error) { - type arkose struct { - Token string `json:"token"` + 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)}, } - var result arkose - resp, err := client.Get("https://arkose-token.linweiyuan.com/backup") + 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") + 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") + req.Header.Set("Referer", "https://tcr9i.chat.openai.com/v2/1.5.2/enforcement.64b3a4e29686f93d52816249ecbf9857.html") + req.Header.Set("Sec-Fetch-Dest", "empty") + 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) if err != nil { return "", err } defer resp.Body.Close() - err = json.NewDecoder(resp.Body).Decode(&result) + 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 { return "", err } - return result.Token, nil + println(arkose.Token) + return arkose.Token, nil + } + +// func get_arkose_token() (string, error) { +// type arkose struct { +// Token string `json:"token"` +// } +// var result arkose +// resp, err := client.Get("https://arkose-token.linweiyuan.com/backup") +// if err != nil { +// return "", err +// } +// defer resp.Body.Close() +// err = json.NewDecoder(resp.Body).Decode(&result) +// if err != nil { +// return "", err +// } +// return result.Token, nil +// } diff --git a/funcaptcha b/funcaptcha new file mode 160000 index 0000000..adeab19 --- /dev/null +++ b/funcaptcha @@ -0,0 +1 @@ +Subproject commit adeab195a0b3e02babfbd49e743974bb284d99f6 diff --git a/go.mod b/go.mod index 5eb7581..a8ec648 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.20 require ( github.com/acheong08/OpenAIAuth v0.0.0-20230530050836-f2a06cd52911 github.com/acheong08/endless v0.0.0-20230529075213-74050cf641c8 + github.com/acheong08/funcaptcha v0.2.1-0.20230626140502-adeab195a0b3 github.com/bogdanfinn/fhttp v0.5.22 github.com/bogdanfinn/tls-client v1.3.12 github.com/gin-gonic/gin v1.9.0 diff --git a/go.sum b/go.sum index b3a804d..2fb0e35 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ github.com/acheong08/OpenAIAuth v0.0.0-20230530050836-f2a06cd52911 h1:KNdCGjt2Dk github.com/acheong08/OpenAIAuth v0.0.0-20230530050836-f2a06cd52911/go.mod h1:ES3Dh9hnbR2mDPlNTagj5e3b4nXECd4tbAjVgxggXEE= github.com/acheong08/endless v0.0.0-20230529075213-74050cf641c8 h1:mHtMoGlGNUfMRjsWcb5Kvd1mJfJG8Gr1TtIghE8iiN8= github.com/acheong08/endless v0.0.0-20230529075213-74050cf641c8/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.22 h1:U1jhZRtuaOanWWcm1WdMFnwMvSxUQgvO6berqAVTc5o=