Spaces:
Runtime error
Runtime error
File size: 4,772 Bytes
581b6d4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
package funcaptcha
import (
"WarpGPT/pkg/env"
"encoding/json"
http "github.com/bogdanfinn/fhttp"
tls_client "github.com/bogdanfinn/tls-client"
"github.com/bogdanfinn/tls-client/profiles"
"net/url"
"os"
"path"
"path/filepath"
"strings"
"time"
)
type arkVer int
const (
ArkVerAuth arkVer = 0
ArkVerReg arkVer = 1
ArkVerChat3 arkVer = 3
ArkVerChat4 arkVer = 4
)
type Solver struct {
initVer string
initHex string
arks map[arkVer][]arkReq
client *tls_client.HttpClient
}
type solverArg func(*Solver)
func NewSolver(args ...solverArg) *Solver {
var (
jar = tls_client.NewCookieJar()
options = []tls_client.HttpClientOption{
tls_client.WithTimeoutSeconds(360),
tls_client.WithClientProfile(profiles.Chrome_117),
tls_client.WithRandomTLSExtensionOrder(),
tls_client.WithNotFollowRedirects(),
tls_client.WithCookieJar(jar),
}
client, _ = tls_client.NewHttpClient(tls_client.NewNoopLogger(), options...)
)
s := &Solver{
arks: make(map[arkVer][]arkReq),
client: &client,
initVer: "1.5.4",
initHex: "cd12da708fe6cbe6e068918c38de2ad9",
}
for _, arg := range args {
arg(s)
}
return s
}
func WithInitVer(ver string) solverArg {
return func(s *Solver) {
s.initVer = ver
}
}
func WithProxy(proxy string) solverArg {
return func(s *Solver) {
(*s.client).SetProxy(proxy)
}
}
func WithInitHex(hex string) solverArg {
return func(s *Solver) {
s.initHex = hex
}
}
func WithClient(client *tls_client.HttpClient) solverArg {
return func(s *Solver) {
s.client = client
}
}
func WithHarData(harData HARData) solverArg {
return func(s *Solver) {
for _, v := range harData.Log.Entries {
if strings.HasPrefix(v.Request.URL, arkPreURL) || strings.HasPrefix(v.Request.URL, arkAuthPreURL) {
var tmpArk arkReq
tmpArk.arkURL = v.Request.URL
if v.StartedDateTime == "" {
println("Error: no arkose request!")
continue
}
t, _ := time.Parse(time.RFC3339, v.StartedDateTime)
bw := getBw(t.Unix())
fallbackBw := getBw(t.Unix() - 21600)
tmpArk.arkHeader = make(http.Header)
for _, h := range v.Request.Headers {
if !strings.EqualFold(h.Name, "content-length") && !strings.EqualFold(h.Name, "cookie") && !strings.HasPrefix(h.Name, ":") {
tmpArk.arkHeader.Set(h.Name, h.Value)
if strings.EqualFold(h.Name, "user-agent") {
tmpArk.userAgent = h.Value
}
}
}
tmpArk.arkCookies = []*http.Cookie{}
for _, cookie := range v.Request.Cookies {
expire, _ := time.Parse(time.RFC3339, cookie.Expires)
if expire.After(time.Now()) {
tmpArk.arkCookies = append(tmpArk.arkCookies, &http.Cookie{Name: cookie.Name, Value: cookie.Value, Expires: expire.UTC()})
}
}
var arkType string
tmpArk.arkBody = make(url.Values)
for _, p := range v.Request.PostData.Params {
if p.Name == "bda" {
cipher, err := url.QueryUnescape(p.Value)
if err != nil {
panic(err)
}
tmpArk.arkBx = Decrypt(cipher, tmpArk.userAgent+bw, tmpArk.userAgent+fallbackBw)
} else if p.Name != "rnd" {
query, err := url.QueryUnescape(p.Value)
if err != nil {
panic(err)
}
tmpArk.arkBody.Set(p.Name, query)
if p.Name == "public_key" {
if query == "0A1D34FC-659D-4E23-B17B-694DCFCF6A6C" {
arkType = "auth"
s.arks[ArkVerAuth] = append(s.arks[ArkVerAuth], tmpArk)
} else if query == "3D86FBBA-9D22-402A-B512-3420086BA6CC" {
arkType = "chat3"
s.arks[ArkVerChat3] = append(s.arks[ArkVerChat3], tmpArk)
} else if query == "35536E1E-65B4-4D96-9D97-6ADB7EFF8147" {
arkType = "chat4"
s.arks[ArkVerChat4] = append(s.arks[ArkVerChat4], tmpArk)
} else if query == "0655BC92-82E1-43D9-B32E-9DF9B01AF50C" {
arkType = "reg"
s.arks[ArkVerReg] = append(s.arks[ArkVerReg], tmpArk)
}
}
}
}
if tmpArk.arkBx != "" {
println("success read " + arkType + " arkose")
} else {
println("failed to decrypt HAR file")
}
}
}
}
}
func WithHarpool(s *Solver) {
dirPath := path.Join(path.Dir(env.EnvFile), "harPool")
var harPath []string
err := filepath.Walk(dirPath, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if !info.IsDir() {
ext := filepath.Ext(info.Name())
if ext == ".har" {
harPath = append(harPath, path)
}
}
return nil
})
if err != nil {
println("Error: please put HAR files in harPool directory!")
}
for _, path := range harPath {
file, err := os.ReadFile(path)
if err != nil {
return
}
var harFile HARData
err = json.Unmarshal(file, &harFile)
if err != nil {
println("Error: not a HAR file!")
return
}
WithHarData(harFile)(s)
}
}
|