I
I
issssrt2018-02-05 23:27:29
PHP
issssrt, 2018-02-05 23:27:29

How to pass authorization with recaptcha 2 (RUCAPTCHA)?

I use the rucaptcha service to bypass authorization.
Here is my code:

<?php
//echo $_SERVER['HTTP_USER_AGENT']; exit;
require_once $_SERVER['DOCUMENT_ROOT'] . '/vendor/autoload.php';

use jumper423\decaptcha\services\RuCaptchaReCaptcha;

$captcha = new RuCaptchaReCaptcha([
    RuCaptchaReCaptcha::ACTION_FIELD_KEY => 'xxx',
]);

if ($captcha->recognize([
    RuCaptchaReCaptcha::ACTION_FIELD_GOOGLEKEY => '6LeZhwoTAAAAAP51ukBEOocjtdKGRDei9wFxFSqs',
    RuCaptchaReCaptcha::ACTION_FIELD_PAGEURL   => 'https://fl.ru/login',
])) {
   echo $code = $captcha->getCode();
    $ch   = curl_init(); // инициализация CURL
    // Ввод пароля и идентификация
    curl_setopt($ch, CURLOPT_URL, "https://site/login/"); //адрес страницы лога

    
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // отключение сертификата
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // отключение сертификата

// отправка логина и пароля
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "login=testuser&passwd=zwd343rdgdf&singin=Войти&u_token_key=42921721c1674026259ef32ea76d7643&g-recaptcha-response=".$code);
//----------------------------------------------

//сохранение кукизов
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
    curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
    curl_setopt($ch, CURLOPT_HEADER, true);

    if ($ref != '') {
        curl_setopt($ch, CURLOPT_REFERER, $ref);
    }

    if ($cookie != '') {
        curl_setopt($ch, CURLOPT_COOKIE, $cookie);
    }

// прописывание броузера
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/64.0.3282.119 Chrome/64.0.3282.119 Safari/537.36');
//--------------------------------------------------------------
    curl_setopt($ch, CURLOPT_TIMEOUT, 50);
//----------------------------------------------------------------

// сдесь сохранение страницы которая загрузилась бы с URL
    $fp = fopen("proba.htm", "w"); // имя сохраняемого файла
    curl_setopt($ch, CURLOPT_FILE, $fp);
    curl_setopt($ch, CURLOPT_HEADER, 0);
// закрытие файла
    fclose($fp);

// выполнение запроса библиотеки CURL
    $content = curl_exec($ch);
//-------------------------------------------------------

///print_r(curl_getinfo($ch)); // вывод структуры запроса

// вывод ошибок при выполнении запроса
    if (curl_error($ch)) {
        echo "\n\ncURL error:" . curl_error($ch);
        echo "\n\ncURL error:" . curl_errno($ch);
//$flagerrcurl = true;
    }
//----------------------------------------------------------------
    // закрытие сессии запроса
    curl_close($ch);
//----------------------------------------------------------------

}

The problem is that if you display the result of the request to check if you are authorized or not, then where the recaptcha is, it says this - ERROR: invalid key domain . Maybe somehow you need to configure the curl more correctly to imitate the user?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dimonchik, 2018-02-05
@dimonchik2013

of course
1 in 1 should match the browser

A
Ainur Valiev, 2018-02-06
@vaajnur

Google recaptcha authorizes by the pair sessid - g-recaptcha-response. Try adding sessid to CURLOPT_POSTFIELDS

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question