1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Login to website with cURL and DeathByCaptcha - PHP

Discussion in 'Other Languages' started by mhnpc, Aug 14, 2016.

  1. mhnpc

    mhnpc Newbie

    Joined:
    Aug 12, 2016
    Messages:
    1
    Likes Received:
    0
    Gender:
    Male
    Hello,

    I want to Login to website (there is address in the code below) with cURL and DeathByCaptcha, but when ro run this code I faced by messgae: Incorrect Captcha!
    If anybody knows my problem please help. Thanks

    I write this following code:

    PHP:
    <?php
    require_once ('deathbycaptcha.class.php');   //www.deathbycaptcha.com - github.com/Yanikore
    require_once ('simple_html_dom.php');        //Website: http://sourceforge.net/projects/simplehtmldom/


    $webiste 'https://ais.usvisa-info.com/en-ae/niv/users/sign_in';
    $html file_get_html($webiste);
    foreach(
    $html->find('input[name=authenticity_token]') as $element)
        
    $authenticity_token $element->value;

    $recaptcha 'http://www.google.com/recaptcha/api/noscript?k=6LeUjCcTAAAAADtvVaUpCp7vy6hLk73NT6zaHZos';
    $html file_get_html($recaptcha);
    foreach(
    $html->find('input[name=recaptcha_challenge_field]') as $element)
        
    $recaptcha_challenge_field =  $element->value;

    foreach(
    $html->find('img') as $element)
        
    $recaptcha_src $element->src;


        
    $uniqid 'captcha.png';
        
    $ch curl_init('http://www.google.com/recaptcha/api/'.$recaptcha_src.'');
        
    $fp fopen($uniqid'wb');
        
    curl_setopt($chCURLOPT_FILE$fp);
        
    curl_setopt($chCURLOPT_HEADER0);
        
    curl_setopt($chCURLOPT_HTTPHEADER, array(
            
    'Accept-Encoding: gzip, deflate, sdch'
            
    ));
        
    curl_exec($ch);
        
    curl_close($ch);
        
    fclose($fp);

    try {
        
    $dbc = new DeathByCaptcha('MyUser''MyPass');
        if(
    $dbc->getBalance() > 0){
            if(
    $dbc->setCaptchaFromImage($uniqid)){
                if(
    $dbc->submitCaptcha()){
                    
    $recaptcha_response_field $dbc->getCaptchaText();

                }
            }
        }
    } catch(
    Exception $ex) {
        echo 
    "<pre>$ex</pre>";
    }



    define('COOKIE''./cookie.txt');
    define('MYURL''https://ais.usvisa-info.com/en-ae/niv/users/sign_in');

    function 
    getUrl($url$method=''$vars=''$open=false) {

        static 
    $cookie false;
        if (!
    $cookie) {
            
    $cookie session_name() . '=' time();
        }
        
    $referer 'https://ais.usvisa-info.com/en-ae/niv/users/sign_in';
        
    $ch curl_init();
        if (
    $method == 'post') {
            
    curl_setopt($chCURLOPT_POST1);
            
    curl_setopt($chCURLOPT_POSTFIELDS"$vars");
        }
        
    curl_setopt($chCURLOPT_HEADER1);
        
    curl_setopt($chCURLOPT_URL$url);
        
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
        
    curl_setopt($chCURLOPT_FOLLOWLOCATION5);
        
    curl_setopt($chCURLOPT_MAXREDIRS10);
        
    curl_setopt($chCURLOPT_REFERER$referer);
        
    curl_setopt($chCURLOPT_COOKIE$cookie);
        
    curl_setopt($chCURLOPT_COOKIEJARCOOKIE);
        
    curl_setopt($chCURLOPT_COOKIEFILECOOKIE);
        
    curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
        
    curl_setopt($chCURLOPT_SSL_VERIFYHOST2);
        
    curl_setopt($chCURLOPT_VERBOSEtrue);
        
    curl_setopt($chCURLOPT_COOKIESESSIONtrue);
        
    curl_setopt($chCURLINFO_HEADER_OUTtrue);

    curl_setopt ($chCURLOPT_CAINFOdirname(__FILE__)."/cacert.pem");

    $request_headers = array();
    $request_headers[] = 'User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36';
    $request_headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
    $request_headers[] = 'Cookie: '.$cookie.'';
    $request_headers[] = 'Accept-Encoding: gzip, deflate';
    $request_headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8';
    $request_headers[] = 'Accept-Language: en-US,en;q=0.8';
    $request_headers[] = 'Host: ais.usvisa-info.com';
    $request_headers[] = 'Origin: https://ais.usvisa-info.com';
    $request_headers[] = 'Content-Type: application/x-www-form-urlencoded';
    $request_headers[] = 'Upgrade-Insecure-Requests: 1';

    curl_setopt($chCURLOPT_HTTPHEADER$request_headers);

        
    $buffer curl_exec($ch);
        if (
    curl_errno($ch)) {
            echo 
    "error " curl_error($ch);
            die;
        }
        
    curl_close($ch);
        return 
    $buffer;
    }


    echo 
    getUrl('https://ais.usvisa-info.com/en-ae/niv/users/sign_in''post''utf8=?&authenticity_token='.$authenticity_token.'&user[email][email protected]&user[password]=12345&recaptcha_challenge_field='.$recaptcha_challenge_field.'&recaptcha_response_field='.$recaptcha_response_field.'&commit=Sing In');

    ?>
     
  2. Henry Cooper

    Henry Cooper Regular Member

    Joined:
    Jun 27, 2016
    Messages:
    208
    Likes Received:
    91
    Gender:
    Male
    Home Page:
    Without reading all the code, did you check the file Transfered to the Captcha solving Service?

    Also what Kind of Captcha is it?
     
  3. amazzy

    amazzy Registered Member

    Joined:
    Oct 21, 2015
    Messages:
    58
    Likes Received:
    9
    Location:
    CA
    Whats the response you're receiving from DPC? I'm guessing your credentials are correct in the code you're running?

    Also look into using Guzzle instead of straight CURL for your requests... Code comes out a lot cleaner
     
  4. Round2and3

    Round2and3 Newbie

    Joined:
    Apr 18, 2017
    Messages:
    29
    Likes Received:
    22
    Gender:
    Male
    Occupation:
    Dirtbag
    Location:
    Texas
    Home Page:
    It's a recapatcha dude....

    SOL...use mech turk method or nothing