-
Notifications
You must be signed in to change notification settings - Fork 2
/
resolve.go
195 lines (179 loc) · 6.42 KB
/
resolve.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package ouo_bypass_go
import (
"errors"
"fmt"
"github.com/PuerkitoBio/goquery"
http "github.com/bogdanfinn/fhttp"
tlsclient "github.com/bogdanfinn/tls-client"
"github.com/bogdanfinn/tls-client/profiles"
"io"
"log"
"net/url"
"regexp"
"strings"
"time"
)
// Resolve function to bypass ouo.io and ouo.press links
func Resolve(ouoURL string) (string, error) {
bypassed, err := OuoBypass(ouoURL)
if err != nil {
log.Default().Println("Resolve ouo short-link Error: ", err)
return "", err
}
return bypassed, nil
}
// OuoBypass function to bypass ouo.io and ouo.press links
func OuoBypass(ouoURL string) (string, error) {
tempURL := strings.Replace(ouoURL, "ouo.press", "ouo.io", 1)
var location string
u, err := url.Parse(tempURL)
if err != nil {
return "", err
}
id := tempURL[strings.LastIndex(tempURL, "/")+1:]
jar := tlsclient.NewCookieJar()
options := []tlsclient.HttpClientOption{
tlsclient.WithTimeoutSeconds(30),
tlsclient.WithClientProfile(profiles.Chrome_110),
tlsclient.WithNotFollowRedirects(),
tlsclient.WithCookieJar(jar), // create cookieJar instance and pass it as argument
}
client, err := tlsclient.NewHttpClient(tlsclient.NewNoopLogger(), options...)
if err != nil {
return "", err
}
getReq, err := http.NewRequest(http.MethodGet, tempURL, nil)
if err != nil {
return "", err
}
chrome110UserAgent := []string{"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36", "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Mobile Safari/537.36", "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"}
//s := rand.NewSource(time.Now().UnixNano())
//r := rand.New(s)
const accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"
const acceptEncoding = "gzip, deflate, br, zstd"
const acceptLang = "de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7"
getReq.Header = http.Header{
"accept": {accept},
"accept-encoding": {acceptEncoding}, // "gzip, deflate, br, zstd
"accept-language": {acceptLang},
//"user-agent": {chrome110UserAgent[r.Intn(len(chrome110UserAgent))]},
"upgrade-insecure-requests": {"1"},
"user-agent": {chrome110UserAgent[0]},
http.HeaderOrderKey: {
"accept",
"accept-language",
"user-agent",
},
}
resp, err := client.Do(getReq)
defer resp.Body.Close()
if resp.StatusCode == 403 {
return "", errors.New("ouo.io is blocking the request")
}
readBytes, _ := io.ReadAll(resp.Body)
data := url.Values{}
doc, _ := goquery.NewDocumentFromReader(strings.NewReader(string(readBytes)))
doc.Find("input").Each(func(i int, s *goquery.Selection) {
name, _ := s.Attr("name")
if strings.HasSuffix(name, "token") {
value, _ := s.Attr("value")
data.Add(name, value)
}
})
nextURL := fmt.Sprintf("%s://%s/go/%s", u.Scheme, u.Host, id)
recaptchaV3, err := RecaptchaV3()
if err != nil {
return "", err
}
data.Set("x-token", recaptchaV3)
for i := 0; i < 2; i++ {
time.Sleep(3 * time.Second)
log.Default().Println("ouo short-link next URL: ", nextURL)
postReq, err := http.NewRequest(http.MethodPost, nextURL, strings.NewReader(data.Encode()))
postReq.Header = http.Header{
"accept": {accept},
"content-type": {"application/x-www-form-urlencoded"},
"accept-encoding": {acceptEncoding}, // "gzip, deflate, br, zstd
"accept-language": {acceptLang},
"upgrade-insecure-requests": {"1"},
"user-agent": {chrome110UserAgent[0]},
}
resp, err := client.Do(postReq)
if err != nil {
log.Println(err)
}
defer resp.Body.Close()
if resp.StatusCode == 302 {
location = resp.Header.Get("Location")
log.Default().Println("ouo short-link target: ", location)
break
} else if resp.StatusCode == 403 {
return "", errors.New("ouo.io is blocking the request")
}
nextURL = fmt.Sprintf("%s://%s/xreallcygo/%s", u.Scheme, u.Host, id)
}
return location, nil
}
// RecaptchaV3 function to bypass reCAPTCHA v3
func RecaptchaV3() (string, error) {
AnchorUrl := "https://www.google.com/recaptcha/api2/anchor?ar=1&k=6Lcr1ncUAAAAAH3cghg6cOTPGARa8adOf-y9zv2x&co=aHR0cHM6Ly9vdW8ucHJlc3M6NDQz&hl=en&v=pCoGBhjs9s8EhFOHJFe8cqis&size=invisible&cb=ahgyd1gkfkhe"
urlBase := "https://www.google.com/recaptcha/"
matches := regexp.MustCompile(`([api2|enterprise]+)\/anchor\?(.*)`).FindStringSubmatch(AnchorUrl)
if len(matches) < 3 {
return "", fmt.Errorf("no matches found in ANCHOR_URL")
}
urlBase += matches[1] + "/"
params := matches[2]
tempUrl := urlBase + "anchor?" + params
client, err := tlsclient.NewHttpClient(tlsclient.NewNoopLogger())
if err != nil {
return "", err
}
req, err := http.NewRequest(http.MethodGet, tempUrl, nil)
resp, err := client.Do(req)
if err != nil {
return "", err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return "", errors.New("recaptcha status code is not 200")
}
body, _ := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
tokenMatches := regexp.MustCompile(`"recaptcha-token" value="(.*?)"`).FindStringSubmatch(string(body))
if len(tokenMatches) < 2 {
return "", errors.New("no token found in response")
}
token := tokenMatches[1]
paramsMap := make(map[string]string)
for _, pair := range strings.Split(params, "&") {
parts := strings.Split(pair, "=")
if len(parts) == 2 {
paramsMap[parts[0]] = parts[1]
}
}
postData := url.Values{}
postData.Set("v", paramsMap["v"])
postData.Set("c", token)
postData.Set("k", paramsMap["k"])
postData.Set("co", paramsMap["co"])
postData.Set("reason", "q")
postReq, err := http.NewRequest(http.MethodPost, urlBase+"reload?k="+paramsMap["k"], strings.NewReader(postData.Encode()))
postReq.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err = client.Do(postReq)
if err != nil {
return "", err
}
defer resp.Body.Close()
body, err = io.ReadAll(resp.Body)
if err != nil {
return "", err
}
answerMatches := regexp.MustCompile(`"rresp","(.*?)"`).FindStringSubmatch(string(body))
if len(answerMatches) < 2 {
return "", errors.New("no answer found in reCaptcha response")
}
return answerMatches[1], nil
}