-
Notifications
You must be signed in to change notification settings - Fork 3
/
datadome-solution.go
169 lines (138 loc) · 3.69 KB
/
datadome-solution.go
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
package main
import (
"encoding/json"
"fmt"
"footlocker-bot/datadome"
"footlocker-bot/logger"
"io"
"math"
"math/rand"
"net/http"
"net/url"
"os"
"strings"
"time"
)
type Datadome struct {
Client http.Client
Log logger.Logger
}
func NewDatadome() Datadome {
return Datadome{}
}
func (d Datadome) GenCh(cid string, domain string, proxy string) (int, string, error) {
filename := "./internal/datadome_payload.json"
data, err := d.readJSONFile(filename)
if err != nil {
fmt.Println("Error reading JSON file:", err)
return 0, "", err
}
jsetNum := time.Now().Unix()
source := rand.NewSource(time.Now().UnixNano())
random := rand.New(source)
ttst := d.round(random.Float64()*(40-8)+8, 15)
tagGpu := d.round(ttst-(0.20*ttst), 14)
tagpu := math.Round((tagGpu-(0.20*tagGpu))*1e14) / 1e14
data.Tagpu = tagpu
data.Ttst = ttst
data.Jset = int(jsetNum)
j, _ := json.Marshal(data)
urlSearchParams := map[string]string{
"jsData": string(j),
"eventCounters": "[]",
"jsType": "ch",
"cid": cid,
"ddk": "A55FBF4311ED6F1BF9911EB71931D5",
"Referer": domain,
"request": "%2",
"responsePage": "origin",
"ddv": "4.8.1",
}
// Define the desired order of keys
urlSearchParamskeyOrder := []string{
"jsData",
"eventCounters",
"jsType",
"cid",
"ddk",
"Referer",
"request",
"responsePage",
"ddv",
}
// Create a URL values instance
values := url.Values{}
// Add the key-value pairs in the desired order
for _, key := range urlSearchParamskeyOrder {
if value, ok := urlSearchParams[key]; ok {
values.Add(key, value)
}
}
// Construct the query string
queryString := values.Encode()
// Define the Charles proxy URL
proxyURL, err := url.Parse(proxy)
if err != nil {
panic(err)
}
d.Log.Debug("current dd proxy: ", proxyURL)
// Create an http.Transport with the proxy configuration
transport := &http.Transport{
Proxy: http.ProxyURL(proxyURL),
}
// Create an http.Client with the transport
client := &http.Client{
Transport: transport,
}
req, err := http.NewRequest(http.MethodPost, "https://api-js.datadome.co/js/", strings.NewReader(queryString))
if err != nil {
d.Log.Debug("Failed to issue GenCh request: ", err)
return 0, "", err
}
req.Header = http.Header{
"accept": {"*/*"},
"accept-language": {"it-IT,it;q=0.9,en-IT;q=0.8,en;q=0.7,si-LK;q=0.6,si;q=0.5,en-US;q=0.4"},
"content-type": {"application/x-www-form-urlencoded"},
"sec-ch-ua": {`"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"`},
"sec-ch-ua-mobile": {"?0"},
"sec-fetch-dest": {"empty"},
"sec-fetch-mode": {"cors"},
"sec-fetch-site": {"cross-site"},
"Referer": {"https://www.footlocker.com/"},
"Referrer-Policy": {"strict-origin-when-cross-origin"},
}
res, err := client.Do(req)
if err != nil {
d.Log.Debug("GenCh response error: ", err)
return 0, "", err
}
if res.StatusCode != 200 {
d.Log.Debug("StatusCode: ", res.StatusCode)
return 0, "", nil
}
defer res.Body.Close()
var ddResponse datadome.DDresponse
resBody, _ := io.ReadAll(res.Body)
json.Unmarshal(resBody, &ddResponse)
ddCookie := strings.Split(strings.Split(ddResponse.Cookie, ";")[0], "=")[1]
return res.StatusCode, ddCookie, nil
}
// Helpers
func (d Datadome) readJSONFile(filename string) (*datadome.GenChPayload, error) {
file, err := os.Open(filename)
if err != nil {
return nil, err
}
defer file.Close()
decoder := json.NewDecoder(file)
data := &datadome.GenChPayload{}
err = decoder.Decode(data)
if err != nil {
return nil, err
}
return data, nil
}
func (d Datadome) round(f float64, n int) float64 {
shift := math.Pow(10, float64(n))
return math.Round(f*shift) / shift
}