From a28852360eb7e2706e4de3f4d7ccca5b64526348 Mon Sep 17 00:00:00 2001 From: xqdoo00o Date: Wed, 1 May 2024 16:45:09 +0800 Subject: [PATCH] same hardware in chatrequire and conversation --- handlers.go | 2 +- internal/chatgpt/request.go | 40 +++++++++++++++++++------------------ 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/handlers.go b/handlers.go index a6cbb4b..d3b6c38 100644 --- a/handlers.go +++ b/handlers.go @@ -145,7 +145,7 @@ func nightmare(c *gin.Context) { } var proofToken string if chat_require.Proof.Required { - proofToken = chatgpt.CalcProofToken(chat_require.Proof.Seed, chat_require.Proof.Difficulty, proxy_url) + proofToken = chatgpt.CalcProofToken(chat_require, proxy_url) } // Convert the chat request to a ChatGPT request translated_request := chatgpt_request_converter.ConvertAPIRequest(original_request, account, &secret, deviceId, chat_require.Arkose.Required, chat_require.Arkose.DX, proxy_url) diff --git a/internal/chatgpt/request.go b/internal/chatgpt/request.go index e1a781f..a06d9f3 100644 --- a/internal/chatgpt/request.go +++ b/internal/chatgpt/request.go @@ -53,7 +53,6 @@ var ( FILES_REVERSE_PROXY = os.Getenv("FILES_REVERSE_PROXY") connPool = map[string][]*connInfo{} userAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36" - answers = map[string]string{} cores = []int{8, 12, 16, 24} screens = []int{3000, 4000, 6000} timeLocation, _ = time.LoadLocation("Asia/Shanghai") @@ -272,28 +271,29 @@ func getDpl(proxy string) bool { }) return len(cachedScripts) != 0 } -func getConfig() []interface{} { - rand.New(rand.NewSource(time.Now().UnixNano())) - core := cores[rand.Intn(4)] - rand.New(rand.NewSource(time.Now().UnixNano())) - screen := screens[rand.Intn(3)] +func getConfig(hardware int) []interface{} { + if hardware == 0 { + rand.New(rand.NewSource(time.Now().UnixNano())) + core := cores[rand.Intn(4)] + rand.New(rand.NewSource(time.Now().UnixNano())) + screen := screens[rand.Intn(3)] + hardware = core + screen + } rand.New(rand.NewSource(time.Now().UnixNano())) script := cachedScripts[rand.Intn(len(cachedScripts))] - return []interface{}{core + screen, getParseTime(), int64(4294705152), 0, userAgent, script, cachedDpl, "zh-CN", "zh-CN,en,en-GB,en-US"} + return []interface{}{hardware, getParseTime(), int64(4294705152), 0, userAgent, script, cachedDpl, "zh-CN", "zh-CN,en,en-GB,en-US"} } -func CalcProofToken(seed string, diff string, proxy string) string { - if answers[seed] != "" { - return "gAAAAAB" + answers[seed] - } - return "gAAAAAB" + generateAnswer(seed, diff, proxy) +func CalcProofToken(require *ChatRequire, proxy string) string { + proof, _ := generateAnswer(require.Proof.Seed, require.Proof.Difficulty, require.Hardware, proxy) + return "gAAAAAB" + proof } -func generateAnswer(seed string, diff string, proxy string) string { +func generateAnswer(seed string, diff string, hardware int, proxy string) (string, int) { if !getDpl(proxy) { - return "wQ8Lk5FbGpA2NcR9dShT6gYjU7VxZ4D" + base64.StdEncoding.EncodeToString([]byte(`"`+seed+`"`)) + return "wQ8Lk5FbGpA2NcR9dShT6gYjU7VxZ4D" + base64.StdEncoding.EncodeToString([]byte(`"`+seed+`"`)), 0 } - config := getConfig() + config := getConfig(hardware) diffLen := len(diff) / 2 hasher := sha3.New512() for i := 0; i < 1000000; i++ { @@ -304,11 +304,10 @@ func generateAnswer(seed string, diff string, proxy string) string { hash := hasher.Sum(nil) hasher.Reset() if hex.EncodeToString(hash[:diffLen]) <= diff { - answers[seed] = base - return answers[seed] + return base, config[0].(int) } } - return "wQ8Lk5FbGpA2NcR9dShT6gYjU7VxZ4D" + base64.StdEncoding.EncodeToString([]byte(`"`+seed+`"`)) + return "wQ8Lk5FbGpA2NcR9dShT6gYjU7VxZ4D" + base64.StdEncoding.EncodeToString([]byte(`"`+seed+`"`)), config[0].(int) } type ChatRequire struct { @@ -318,13 +317,15 @@ type ChatRequire struct { Required bool `json:"required"` DX string `json:"dx,omitempty"` } `json:"arkose"` + Hardware int } func CheckRequire(secret *tokens.Secret, deviceId string, proxy string) *ChatRequire { if proxy != "" { client.SetProxy(proxy) } - body := bytes.NewBuffer([]byte(`{"p":"` + "gAAAAAC" + generateAnswer(strconv.FormatFloat(rand.Float64(), 'f', -1, 64), "0", proxy) + `"}`)) + proof, hardware := generateAnswer(strconv.FormatFloat(rand.Float64(), 'f', -1, 64), "0", 0, proxy) + body := bytes.NewBuffer([]byte(`{"p":"` + "gAAAAAC" + proof + `"}`)) var apiUrl string if secret.Token == "" { apiUrl = "https://chat.openai.com/backend-anon/sentinel/chat-requirements" @@ -346,6 +347,7 @@ func CheckRequire(secret *tokens.Secret, deviceId string, proxy string) *ChatReq if err != nil { return nil } + require.Hardware = hardware return &require }