fix: Use PoC method for captcha solving after PoW method
This commit is contained in:
1 parent
0b20a379fa
commit
ef01992613
3 files changed
+141
-37
No files matched your search
@@ -297,7 +297,7 @@ curl -L -o client https://github.com/cacggghp/vk-turn-proxy/releases/latest/down
|
|||||||
|
|
||||||
Для прохождения капчи вручную - `-manual-captcha`.
|
Для прохождения капчи вручную - `-manual-captcha`.
|
||||||
|
|
||||||
Для экспериментальной автопопытки решить пазл-слайдер можно добавить флаг `-auto-captcha-slider-poc`.
|
По умолчанию капча теперь проходит так: обычная автопопытка, затем автопопытка через пазл-слайдер POC, и только потом ручной режим.
|
||||||
|
|
||||||
## Яндекс телемост
|
## Яндекс телемост
|
||||||
|
|
||||||
|
|||||||
+79
-36
@@ -68,6 +68,49 @@ var (
|
|||||||
autoCaptchaSliderPOC bool
|
autoCaptchaSliderPOC bool
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type captchaSolveMode int
|
||||||
|
|
||||||
|
const (
|
||||||
|
captchaSolveModeAuto captchaSolveMode = iota
|
||||||
|
captchaSolveModeSliderPOC
|
||||||
|
captchaSolveModeManual
|
||||||
|
)
|
||||||
|
|
||||||
|
func captchaSolveModeForAttempt(attempt int, manualOnly bool, enableSliderPOC bool) (captchaSolveMode, bool) {
|
||||||
|
if manualOnly {
|
||||||
|
return captchaSolveModeManual, attempt == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
switch attempt {
|
||||||
|
case 0:
|
||||||
|
return captchaSolveModeAuto, true
|
||||||
|
case 1:
|
||||||
|
if enableSliderPOC {
|
||||||
|
return captchaSolveModeSliderPOC, true
|
||||||
|
}
|
||||||
|
return captchaSolveModeManual, true
|
||||||
|
case 2:
|
||||||
|
if enableSliderPOC {
|
||||||
|
return captchaSolveModeManual, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
|
||||||
|
func captchaSolveModeLabel(mode captchaSolveMode) string {
|
||||||
|
switch mode {
|
||||||
|
case captchaSolveModeAuto:
|
||||||
|
return "auto captcha"
|
||||||
|
case captchaSolveModeSliderPOC:
|
||||||
|
return "auto captcha slider POC"
|
||||||
|
case captchaSolveModeManual:
|
||||||
|
return "manual captcha"
|
||||||
|
default:
|
||||||
|
return "captcha"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type UDPPacket struct {
|
type UDPPacket struct {
|
||||||
Data []byte
|
Data []byte
|
||||||
N int
|
N int
|
||||||
@@ -297,8 +340,12 @@ func (e *VkCaptchaError) IsCaptchaError() bool {
|
|||||||
return e.ErrorCode == 14 && e.RedirectUri != "" && e.SessionToken != ""
|
return e.ErrorCode == 14 && e.RedirectUri != "" && e.SessionToken != ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func solveVkCaptcha(ctx context.Context, captchaErr *VkCaptchaError, streamID int, client tlsclient.HttpClient, profile Profile) (string, error) {
|
func solveVkCaptcha(ctx context.Context, captchaErr *VkCaptchaError, streamID int, client tlsclient.HttpClient, profile Profile, useSliderPOC bool) (string, error) {
|
||||||
log.Printf("[STREAM %d] [Captcha] Solving Not Robot Captcha...", streamID)
|
if useSliderPOC {
|
||||||
|
log.Printf("[STREAM %d] [Captcha] Solving captcha with slider POC...", streamID)
|
||||||
|
} else {
|
||||||
|
log.Printf("[STREAM %d] [Captcha] Solving captcha...", streamID)
|
||||||
|
}
|
||||||
|
|
||||||
if captchaErr.SessionToken == "" {
|
if captchaErr.SessionToken == "" {
|
||||||
return "", fmt.Errorf("no session_token in redirect_uri for auto-solve")
|
return "", fmt.Errorf("no session_token in redirect_uri for auto-solve")
|
||||||
@@ -318,7 +365,7 @@ func solveVkCaptcha(ctx context.Context, captchaErr *VkCaptchaError, streamID in
|
|||||||
log.Printf("[STREAM %d] [Captcha] PoW solved: hash=%s", streamID, hash)
|
log.Printf("[STREAM %d] [Captcha] PoW solved: hash=%s", streamID, hash)
|
||||||
|
|
||||||
var successToken string
|
var successToken string
|
||||||
if autoCaptchaSliderPOC {
|
if useSliderPOC {
|
||||||
successToken, err = callCaptchaNotRobotWithSliderPOC(
|
successToken, err = callCaptchaNotRobotWithSliderPOC(
|
||||||
ctx,
|
ctx,
|
||||||
captchaErr.SessionToken,
|
captchaErr.SessionToken,
|
||||||
@@ -812,11 +859,12 @@ func getTokenChain(ctx context.Context, link string, streamID int, creds VKCrede
|
|||||||
urlAddr := fmt.Sprintf("https://api.vk.ru/method/calls.getAnonymousToken?v=5.275&client_id=%s", creds.ClientID)
|
urlAddr := fmt.Sprintf("https://api.vk.ru/method/calls.getAnonymousToken?v=5.275&client_id=%s", creds.ClientID)
|
||||||
|
|
||||||
var token2 string
|
var token2 string
|
||||||
maxAutoAttempts := 2
|
for attempt := 0; ; attempt++ {
|
||||||
if manualCaptcha {
|
solveMode, hasSolveMode := captchaSolveModeForAttempt(attempt, manualCaptcha, autoCaptchaSliderPOC)
|
||||||
maxAutoAttempts = 0
|
if !hasSolveMode {
|
||||||
}
|
break
|
||||||
for attempt := 0; attempt <= maxAutoAttempts+1; attempt++ {
|
}
|
||||||
|
|
||||||
resp, err = doRequest(data, urlAddr)
|
resp, err = doRequest(data, urlAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", "", err
|
return "", "", "", err
|
||||||
@@ -829,20 +877,27 @@ func getTokenChain(ctx context.Context, link string, streamID int, creds VKCrede
|
|||||||
var captchaKey string
|
var captchaKey string
|
||||||
var solveErr error
|
var solveErr error
|
||||||
|
|
||||||
if attempt < maxAutoAttempts {
|
switch solveMode {
|
||||||
// Auto Solve Attempts
|
case captchaSolveModeAuto:
|
||||||
if captchaErr.SessionToken != "" && captchaErr.RedirectUri != "" {
|
if captchaErr.SessionToken != "" && captchaErr.RedirectUri != "" {
|
||||||
successToken, solveErr = solveVkCaptcha(ctx, captchaErr, streamID, client, profile)
|
successToken, solveErr = solveVkCaptcha(ctx, captchaErr, streamID, client, profile, false)
|
||||||
if solveErr != nil {
|
if solveErr != nil {
|
||||||
log.Printf("[STREAM %d] [Captcha] Auto solve failed: %v", streamID, solveErr)
|
log.Printf("[STREAM %d] [Captcha] Auto captcha failed: %v", streamID, solveErr)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
solveErr = fmt.Errorf("missing fields for auto solve")
|
solveErr = fmt.Errorf("missing fields for auto solve")
|
||||||
}
|
}
|
||||||
} else if attempt == maxAutoAttempts {
|
case captchaSolveModeSliderPOC:
|
||||||
// Manual Solve Fallback with 60s Timeout
|
if captchaErr.SessionToken != "" && captchaErr.RedirectUri != "" {
|
||||||
log.Printf("[STREAM %d] [Captcha] Auto failed %d times. Triggering MANUAL fallback...", streamID, maxAutoAttempts)
|
successToken, solveErr = solveVkCaptcha(ctx, captchaErr, streamID, client, profile, true)
|
||||||
|
if solveErr != nil {
|
||||||
|
log.Printf("[STREAM %d] [Captcha] Auto captcha slider POC failed: %v", streamID, solveErr)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
solveErr = fmt.Errorf("missing fields for slider POC auto solve")
|
||||||
|
}
|
||||||
|
case captchaSolveModeManual:
|
||||||
|
log.Printf("[STREAM %d] [Captcha] Triggering manual captcha fallback...", streamID)
|
||||||
manualCtx, manualCancel := context.WithTimeout(ctx, 60*time.Second)
|
manualCtx, manualCancel := context.WithTimeout(ctx, 60*time.Second)
|
||||||
|
|
||||||
type manualRes struct {
|
type manualRes struct {
|
||||||
@@ -874,29 +929,15 @@ func getTokenChain(ctx context.Context, link string, streamID int, creds VKCrede
|
|||||||
solveErr = fmt.Errorf("manual captcha timed out after 60s")
|
solveErr = fmt.Errorf("manual captcha timed out after 60s")
|
||||||
}
|
}
|
||||||
manualCancel()
|
manualCancel()
|
||||||
} else {
|
|
||||||
solveErr = fmt.Errorf("max attempts reached")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If solving failed (auto or manual) or timed out
|
// If solving failed (auto or manual) or timed out
|
||||||
if solveErr != nil {
|
if solveErr != nil {
|
||||||
log.Printf("[STREAM %d] [Captcha] Failed to solve (attempt %d): %v", streamID, attempt+1, solveErr)
|
log.Printf("[STREAM %d] [Captcha] %s failed (attempt %d): %v", streamID, captchaSolveModeLabel(solveMode), attempt+1, solveErr)
|
||||||
|
|
||||||
if attempt < maxAutoAttempts-1 {
|
nextSolveMode, hasNextSolveMode := captchaSolveModeForAttempt(attempt+1, manualCaptcha, autoCaptchaSliderPOC)
|
||||||
log.Printf("[STREAM %d] [Captcha] Backing off for 10 seconds before next auto attempt...", streamID)
|
if hasNextSolveMode {
|
||||||
select {
|
log.Printf("[STREAM %d] [Captcha] Falling back to %s...", streamID, captchaSolveModeLabel(nextSolveMode))
|
||||||
case <-ctx.Done():
|
|
||||||
return "", "", "", ctx.Err()
|
|
||||||
case <-time.After(10 * time.Second):
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
} else if attempt == maxAutoAttempts-1 {
|
|
||||||
log.Printf("[STREAM %d] [Captcha] Backing off for 2 seconds before manual fallback...", streamID)
|
|
||||||
select {
|
|
||||||
case <-ctx.Done():
|
|
||||||
return "", "", "", ctx.Err()
|
|
||||||
case <-time.After(2 * time.Second):
|
|
||||||
}
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1675,7 +1716,7 @@ func main() {
|
|||||||
direct := flag.Bool("no-dtls", false, "connect without obfuscation. DO NOT USE")
|
direct := flag.Bool("no-dtls", false, "connect without obfuscation. DO NOT USE")
|
||||||
debugFlag := flag.Bool("debug", false, "enable debug logging")
|
debugFlag := flag.Bool("debug", false, "enable debug logging")
|
||||||
manualCaptchaFlag := flag.Bool("manual-captcha", false, "skip auto captcha solving, use manual mode immediately")
|
manualCaptchaFlag := flag.Bool("manual-captcha", false, "skip auto captcha solving, use manual mode immediately")
|
||||||
autoCaptchaSliderPOCFlag := flag.Bool("auto-captcha-slider-poc", false, "experimental: try local slider captcha solving before manual fallback")
|
autoCaptchaSliderPOCFlag := flag.Bool("auto-captcha-slider-poc", false, "compatibility flag: slider POC fallback is now enabled by default before manual fallback")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if *peerAddr == "" {
|
if *peerAddr == "" {
|
||||||
log.Panicf("Need peer address!")
|
log.Panicf("Need peer address!")
|
||||||
@@ -1690,9 +1731,11 @@ func main() {
|
|||||||
|
|
||||||
isDebug = *debugFlag
|
isDebug = *debugFlag
|
||||||
manualCaptcha = *manualCaptchaFlag
|
manualCaptcha = *manualCaptchaFlag
|
||||||
autoCaptchaSliderPOC = *autoCaptchaSliderPOCFlag && !manualCaptcha
|
autoCaptchaSliderPOC = !manualCaptcha
|
||||||
if *autoCaptchaSliderPOCFlag && manualCaptcha {
|
if *autoCaptchaSliderPOCFlag && manualCaptcha {
|
||||||
log.Printf("[Captcha] manual-captcha enabled, ignoring -auto-captcha-slider-poc")
|
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 link string
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestCaptchaSolveModeForAttempt(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
t.Run("default flow", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
mode, ok := captchaSolveModeForAttempt(0, false, true)
|
||||||
|
if !ok || mode != captchaSolveModeAuto {
|
||||||
|
t.Fatalf("expected first attempt to use auto captcha, got mode=%v ok=%v", mode, ok)
|
||||||
|
}
|
||||||
|
|
||||||
|
mode, ok = captchaSolveModeForAttempt(1, false, true)
|
||||||
|
if !ok || mode != captchaSolveModeSliderPOC {
|
||||||
|
t.Fatalf("expected second attempt to use slider POC, got mode=%v ok=%v", mode, ok)
|
||||||
|
}
|
||||||
|
|
||||||
|
mode, ok = captchaSolveModeForAttempt(2, false, true)
|
||||||
|
if !ok || mode != captchaSolveModeManual {
|
||||||
|
t.Fatalf("expected third attempt to use manual captcha, got mode=%v ok=%v", mode, ok)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok = captchaSolveModeForAttempt(3, false, true); ok {
|
||||||
|
t.Fatal("expected no fourth captcha attempt in default flow")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("manual only flow", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
mode, ok := captchaSolveModeForAttempt(0, true, true)
|
||||||
|
if !ok || mode != captchaSolveModeManual {
|
||||||
|
t.Fatalf("expected manual mode on first attempt, got mode=%v ok=%v", mode, ok)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok = captchaSolveModeForAttempt(1, true, true); ok {
|
||||||
|
t.Fatal("expected only one manual captcha attempt when manual mode is forced")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("flow without slider poc", func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
mode, ok := captchaSolveModeForAttempt(0, false, false)
|
||||||
|
if !ok || mode != captchaSolveModeAuto {
|
||||||
|
t.Fatalf("expected auto captcha first, got mode=%v ok=%v", mode, ok)
|
||||||
|
}
|
||||||
|
|
||||||
|
mode, ok = captchaSolveModeForAttempt(1, false, false)
|
||||||
|
if !ok || mode != captchaSolveModeManual {
|
||||||
|
t.Fatalf("expected manual captcha second when slider POC is disabled, got mode=%v ok=%v", mode, ok)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok = captchaSolveModeForAttempt(2, false, false); ok {
|
||||||
|
t.Fatal("expected only two attempts when slider POC is disabled")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in new issue
Block a user