build: Bump dependencies
This commit is contained in:
1 parent
ef01992613
commit
f4091d0aa9
8 files changed
+178
-126
No files matched your search
+10
-16
@@ -8,7 +8,6 @@ import (
|
||||
"context"
|
||||
"crypto/md5"
|
||||
"crypto/sha256"
|
||||
"crypto/tls"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
@@ -486,7 +485,7 @@ func callCaptchaNotRobot(ctx context.Context, sessionToken, hash string, streamI
|
||||
|
||||
log.Printf("[STREAM %d] [Captcha] Step 2/4: componentDone", streamID)
|
||||
browserFp := generateBrowserFp(profile)
|
||||
deviceJSON := fmt.Sprintf(`{"screenWidth":1920,"screenHeight":1080,"screenAvailWidth":1920,"screenAvailHeight":1040,"innerWidth":1920,"innerHeight":969,"devicePixelRatio":1,"language":"en-US","languages":["en-US"],"webdriver":false,"hardwareConcurrency":8,"deviceMemory":8,"connectionEffectiveType":"4g","notificationsPermission":"default","userAgent":"%s","platform":"Win32"}`, profile.UserAgent)
|
||||
deviceJSON := buildCaptchaDeviceJSON(profile)
|
||||
componentDoneData := baseParams + fmt.Sprintf("&browser_fp=%s&device=%s", browserFp, neturl.QueryEscape(deviceJSON))
|
||||
|
||||
if _, err := vkReq("captchaNotRobot.componentDone", componentDoneData); err != nil {
|
||||
@@ -1314,13 +1313,6 @@ func dtlsFunc(ctx context.Context, conn net.PacketConn, peer *net.UDPAddr) (net.
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config := &dtls.Config{
|
||||
Certificates: []tls.Certificate{certificate},
|
||||
InsecureSkipVerify: true,
|
||||
ExtendedMasterSecret: dtls.RequireExtendedMasterSecret,
|
||||
CipherSuites: []dtls.CipherSuiteID{dtls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
|
||||
ConnectionIDGenerator: dtls.OnlySendCIDGenerator(),
|
||||
}
|
||||
|
||||
select {
|
||||
case handshakeSem <- struct{}{}:
|
||||
@@ -1331,7 +1323,15 @@ func dtlsFunc(ctx context.Context, conn net.PacketConn, peer *net.UDPAddr) (net.
|
||||
|
||||
ctx1, cancel := context.WithTimeout(ctx, 20*time.Second)
|
||||
defer cancel()
|
||||
dtlsConn, err := dtls.Client(conn, peer, config)
|
||||
dtlsConn, err := dtls.ClientWithOptions(
|
||||
conn,
|
||||
peer,
|
||||
dtls.WithCertificates(certificate),
|
||||
dtls.WithInsecureSkipVerify(true),
|
||||
dtls.WithExtendedMasterSecret(dtls.RequireExtendedMasterSecret),
|
||||
dtls.WithCipherSuites(dtls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256),
|
||||
dtls.WithConnectionIDGenerator(dtls.OnlySendCIDGenerator()),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1716,7 +1716,6 @@ func main() {
|
||||
direct := flag.Bool("no-dtls", false, "connect without obfuscation. DO NOT USE")
|
||||
debugFlag := flag.Bool("debug", false, "enable debug logging")
|
||||
manualCaptchaFlag := flag.Bool("manual-captcha", false, "skip auto captcha solving, use manual mode immediately")
|
||||
autoCaptchaSliderPOCFlag := flag.Bool("auto-captcha-slider-poc", false, "compatibility flag: slider POC fallback is now enabled by default before manual fallback")
|
||||
flag.Parse()
|
||||
if *peerAddr == "" {
|
||||
log.Panicf("Need peer address!")
|
||||
@@ -1732,11 +1731,6 @@ func main() {
|
||||
isDebug = *debugFlag
|
||||
manualCaptcha = *manualCaptchaFlag
|
||||
autoCaptchaSliderPOC = !manualCaptcha
|
||||
if *autoCaptchaSliderPOCFlag && manualCaptcha {
|
||||
log.Printf("[Captcha] manual-captcha enabled, ignoring -auto-captcha-slider-poc")
|
||||
} else if *autoCaptchaSliderPOCFlag {
|
||||
log.Printf("[Captcha] -auto-captcha-slider-poc is now enabled by default")
|
||||
}
|
||||
|
||||
var link string
|
||||
var getCreds getCredsFunc
|
||||
|
||||
@@ -74,6 +74,32 @@ func targetOrigin(targetURL *neturl.URL) string {
|
||||
return targetURL.Scheme + "://" + targetURL.Host
|
||||
}
|
||||
|
||||
func isSafeLocalRedirectPath(raw string) bool {
|
||||
if raw == "" || raw[0] != '/' {
|
||||
return false
|
||||
}
|
||||
if len(raw) > 1 && (raw[1] == '/' || raw[1] == '\\') {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func rewriteProxyRedirectLocation(raw string, targetURL *neturl.URL) (string, bool) {
|
||||
if isSafeLocalRedirectPath(raw) {
|
||||
return raw, true
|
||||
}
|
||||
|
||||
parsed, err := neturl.Parse(raw)
|
||||
if err != nil {
|
||||
return "", false
|
||||
}
|
||||
if !strings.EqualFold(parsed.Scheme, targetURL.Scheme) || !strings.EqualFold(parsed.Host, targetURL.Host) {
|
||||
return "", false
|
||||
}
|
||||
|
||||
return localCaptchaURLForTarget(parsed), true
|
||||
}
|
||||
|
||||
func rewriteProxyHeaderURL(raw string, targetURL *neturl.URL) string {
|
||||
if raw == "" {
|
||||
return raw
|
||||
@@ -442,10 +468,10 @@ func solveCaptchaViaProxy(redirectURI string, dialer *dnsdialer.Dialer) (string,
|
||||
|
||||
if res.StatusCode >= 300 && res.StatusCode < 400 {
|
||||
if loc := res.Header.Get("Location"); loc != "" {
|
||||
if strings.HasPrefix(loc, "/") {
|
||||
res.Header.Set("Location", loc)
|
||||
} else if strings.HasPrefix(loc, targetOrigin(targetURL)) {
|
||||
res.Header.Set("Location", strings.Replace(loc, targetOrigin(targetURL), localCaptchaOrigin(), 1))
|
||||
if rewritten, ok := rewriteProxyRedirectLocation(loc, targetURL); ok {
|
||||
res.Header.Set("Location", rewritten)
|
||||
} else {
|
||||
res.Header.Del("Location")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRewriteProxyRedirectLocation(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
targetURL, err := url.Parse("https://id.vk.ru/captcha")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to parse target URL: %v", err)
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
location string
|
||||
want string
|
||||
ok bool
|
||||
}{
|
||||
{
|
||||
name: "keeps safe relative path",
|
||||
location: "/captcha?step=2",
|
||||
want: "/captcha?step=2",
|
||||
ok: true,
|
||||
},
|
||||
{
|
||||
name: "rewrites same-origin absolute URL",
|
||||
location: "https://id.vk.ru/captcha?step=2",
|
||||
want: "http://localhost:8765/captcha?step=2",
|
||||
ok: true,
|
||||
},
|
||||
{
|
||||
name: "blocks scheme-relative redirect",
|
||||
location: "//evil.example/captcha",
|
||||
ok: false,
|
||||
},
|
||||
{
|
||||
name: "blocks slash-backslash redirect",
|
||||
location: `/\evil.example/captcha`,
|
||||
ok: false,
|
||||
},
|
||||
{
|
||||
name: "blocks lookalike absolute host",
|
||||
location: "https://id.vk.ru.evil.example/captcha",
|
||||
ok: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
tc := tc
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
got, ok := rewriteProxyRedirectLocation(tc.location, targetURL)
|
||||
if ok != tc.ok {
|
||||
t.Fatalf("rewriteProxyRedirectLocation() ok = %v, want %v", ok, tc.ok)
|
||||
}
|
||||
if got != tc.want {
|
||||
t.Fatalf("rewriteProxyRedirectLocation() = %q, want %q", got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
+15
-46
@@ -47,15 +47,13 @@ type captchaCheckResult struct {
|
||||
Status string
|
||||
SuccessToken string
|
||||
ShowCaptchaType string
|
||||
Redirect string
|
||||
}
|
||||
|
||||
type sliderCaptchaContent struct {
|
||||
Extension string
|
||||
Image image.Image
|
||||
Size int
|
||||
Steps []int
|
||||
Attempts int
|
||||
Image image.Image
|
||||
Size int
|
||||
Steps []int
|
||||
Attempts int
|
||||
}
|
||||
|
||||
type sliderCandidate struct {
|
||||
@@ -100,26 +98,12 @@ func (s *captchaNotRobotSession) baseValues() neturl.Values {
|
||||
|
||||
func (s *captchaNotRobotSession) request(method string, values neturl.Values) (map[string]interface{}, error) {
|
||||
reqURL := "https://api.vk.ru/method/" + method + "?v=5.131"
|
||||
parsedURL, _ := neturl.Parse(reqURL)
|
||||
domain := parsedURL.Hostname()
|
||||
|
||||
req, err := fhttp.NewRequestWithContext(s.ctx, "POST", reqURL, strings.NewReader(values.Encode()))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req.Host = domain
|
||||
applyBrowserProfileFhttp(req, s.profile)
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
req.Header.Set("Accept", "*/*")
|
||||
req.Header.Set("Origin", "https://id.vk.ru")
|
||||
req.Header.Set("Referer", "https://id.vk.ru/")
|
||||
req.Header.Set("Sec-Fetch-Site", "same-site")
|
||||
req.Header.Set("Sec-Fetch-Mode", "cors")
|
||||
req.Header.Set("Sec-Fetch-Dest", "empty")
|
||||
req.Header.Set("Sec-GPC", "1")
|
||||
req.Header.Set("Priority", "u=1, i")
|
||||
|
||||
httpResp, err := s.client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -169,24 +153,7 @@ func (s *captchaNotRobotSession) requestComponentDone() error {
|
||||
}
|
||||
|
||||
func (s *captchaNotRobotSession) requestCheckboxCheck() (*captchaCheckResult, error) {
|
||||
values := s.baseValues()
|
||||
values.Set("accelerometer", "[]")
|
||||
values.Set("gyroscope", "[]")
|
||||
values.Set("motion", "[]")
|
||||
values.Set("cursor", "[]")
|
||||
values.Set("taps", "[]")
|
||||
values.Set("connectionRtt", "[]")
|
||||
values.Set("connectionDownlink", "[]")
|
||||
values.Set("browser_fp", s.browserFp)
|
||||
values.Set("hash", s.hash)
|
||||
values.Set("answer", base64.StdEncoding.EncodeToString([]byte("{}")))
|
||||
values.Set("debug_info", captchaDebugInfo)
|
||||
|
||||
resp, err := s.request("captchaNotRobot.check", values)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("check failed: %w", err)
|
||||
}
|
||||
return parseCaptchaCheckResult(resp)
|
||||
return s.requestCheck("[]", base64.StdEncoding.EncodeToString([]byte("{}")))
|
||||
}
|
||||
|
||||
func (s *captchaNotRobotSession) requestSliderContent(sliderSettings string) (*sliderCaptchaContent, error) {
|
||||
@@ -208,11 +175,15 @@ func (s *captchaNotRobotSession) requestSliderCheck(activeSteps []int, candidate
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return s.requestCheck(generateSliderCursor(candidateIndex, candidateCount), answer)
|
||||
}
|
||||
|
||||
func (s *captchaNotRobotSession) requestCheck(cursor string, answer string) (*captchaCheckResult, error) {
|
||||
values := s.baseValues()
|
||||
values.Set("accelerometer", "[]")
|
||||
values.Set("gyroscope", "[]")
|
||||
values.Set("motion", "[]")
|
||||
values.Set("cursor", generateSliderCursor(candidateIndex, candidateCount))
|
||||
values.Set("cursor", cursor)
|
||||
values.Set("taps", "[]")
|
||||
values.Set("connectionRtt", "[]")
|
||||
values.Set("connectionDownlink", "[]")
|
||||
@@ -407,7 +378,7 @@ func parseCaptchaBootstrapHTML(html string) (*captchaBootstrap, error) {
|
||||
}
|
||||
|
||||
func parseCaptchaSettingsFromHTML(html string) (*captchaSettingsResponse, error) {
|
||||
initRe := regexp.MustCompile(`(?s)window\.init\s*=\s*(\{.*?\})\s*;\s*window\.lang`)
|
||||
initRe := regexp.MustCompile(`(?s)window\.init\s*=\s*(\{.*?})\s*;\s*window\.lang`)
|
||||
initMatch := initRe.FindStringSubmatch(html)
|
||||
if len(initMatch) < 2 {
|
||||
return &captchaSettingsResponse{SettingsByType: make(map[string]string)}, nil
|
||||
@@ -527,7 +498,6 @@ func parseCaptchaCheckResult(resp map[string]interface{}) (*captchaCheckResult,
|
||||
result.Status, _ = respObj["status"].(string)
|
||||
result.SuccessToken, _ = respObj["success_token"].(string)
|
||||
result.ShowCaptchaType, _ = respObj["show_captcha_type"].(string)
|
||||
result.Redirect, _ = respObj["redirect"].(string)
|
||||
if result.Status == "" {
|
||||
return nil, fmt.Errorf("check status missing: %v", resp)
|
||||
}
|
||||
@@ -578,11 +548,10 @@ func parseSliderCaptchaContentResponse(resp map[string]interface{}) (*sliderCapt
|
||||
}
|
||||
|
||||
return &sliderCaptchaContent{
|
||||
Extension: extension,
|
||||
Image: img,
|
||||
Size: size,
|
||||
Steps: swaps,
|
||||
Attempts: attempts,
|
||||
Image: img,
|
||||
Size: size,
|
||||
Steps: swaps,
|
||||
Attempts: attempts,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -96,10 +96,10 @@ func TestRenderSliderCandidateMatchesSwapLayout(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
src := image.NewRGBA(image.Rect(0, 0, 20, 20))
|
||||
fillRect(src, image.Rect(0, 0, 10, 10), color.RGBA{255, 0, 0, 255})
|
||||
fillRect(src, image.Rect(10, 0, 20, 10), color.RGBA{0, 255, 0, 255})
|
||||
fillRect(src, image.Rect(0, 10, 10, 20), color.RGBA{0, 0, 255, 255})
|
||||
fillRect(src, image.Rect(10, 10, 20, 20), color.RGBA{255, 255, 0, 255})
|
||||
fillRect(src, image.Rect(0, 0, 10, 10), color.RGBA{R: 255, A: 255})
|
||||
fillRect(src, image.Rect(10, 0, 20, 10), color.RGBA{G: 255, A: 255})
|
||||
fillRect(src, image.Rect(0, 10, 10, 20), color.RGBA{B: 255, A: 255})
|
||||
fillRect(src, image.Rect(10, 10, 20, 20), color.RGBA{R: 255, G: 255, A: 255})
|
||||
|
||||
mapping, err := buildSliderTileMapping(2, []int{0, 1})
|
||||
if err != nil {
|
||||
@@ -111,10 +111,10 @@ func TestRenderSliderCandidateMatchesSwapLayout(t *testing.T) {
|
||||
t.Fatalf("renderSliderCandidate returned error: %v", err)
|
||||
}
|
||||
|
||||
assertPixelEquals(t, rendered.At(2, 2), color.RGBA{0, 255, 0, 255})
|
||||
assertPixelEquals(t, rendered.At(12, 2), color.RGBA{255, 0, 0, 255})
|
||||
assertPixelEquals(t, rendered.At(2, 12), color.RGBA{0, 0, 255, 255})
|
||||
assertPixelEquals(t, rendered.At(12, 12), color.RGBA{255, 255, 0, 255})
|
||||
assertPixelEquals(t, rendered.At(2, 2), color.RGBA{G: 255, A: 255})
|
||||
assertPixelEquals(t, rendered.At(12, 2), color.RGBA{R: 255, A: 255})
|
||||
assertPixelEquals(t, rendered.At(2, 12), color.RGBA{B: 255, A: 255})
|
||||
assertPixelEquals(t, rendered.At(12, 12), color.RGBA{R: 255, G: 255, A: 255})
|
||||
}
|
||||
|
||||
func TestRankSliderCandidatesPrefersMostCoherentImage(t *testing.T) {
|
||||
@@ -228,7 +228,7 @@ func TestParseSliderCaptchaContentResponse(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
src := image.NewRGBA(image.Rect(0, 0, 20, 20))
|
||||
fillRect(src, src.Bounds(), color.RGBA{12, 34, 56, 255})
|
||||
fillRect(src, src.Bounds(), color.RGBA{R: 12, G: 34, B: 56, A: 255})
|
||||
|
||||
var buf bytes.Buffer
|
||||
if err := jpeg.Encode(&buf, src, nil); err != nil {
|
||||
|
||||
Reference in new issue
Block a user