Solve Recaptcha Challenges In IE Via 2Captcha API

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury, Rain

Post Reply
NickD
Junior Coder
Posts: 37
Joined: Fri Sep 23, 2016 2:17 pm

Solve Recaptcha Challenges In IE Via 2Captcha API

Post by NickD » Fri Oct 19, 2018 12:46 am

Here is a script I wrote to solve V2 Google Recaptcha Challenges in IE. Thought I would share it as someone else might find it useful as a starting point. You need to have a valid 2Captcha.com api key, and 2Captcha charge $2.99 per 1000 captchas solved.

After the script has run on the sample form, just click submit, and the form should validate.

Code: Select all

//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 2CAPTCHA API KEY
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


  Let>apikey=enter-your-api-key


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// LAUNCH IE
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


  IESetTimeout>10,ie_res
  IECreate>IE[0]
  IENavigate>%IE[0]%,https://www.google.com/recaptcha/api2/demo,ie_res
  IEWaitDocumentComplete>%IE[0]%,ie_res


//////////////////////////////////////////////////////
// SCRAPE HTML
//////////////////////////////////////////////////////


  Let>HTML0_SIZE=9999
  IEExtractTag>%IE[0]%,,HTML,0,1,PageDump


//////////////////////////////////////////////////////
// GET RECAPTCHA DATA-SITEKEY
//////////////////////////////////////////////////////


  Let>pattern=(?<=data-sitekey=")(.+?)(?=")
  RegEx>pattern,%PageDump%,0,GKeyArr,GKeyNum,0
  Let>PageDump=0
  If>GKeyNum>0
  Let>gkey=GKeyArr_1
  Endif
  If>GKeyNum<1
  MDL>data-sitekey not found!
  Exit>0
  Endif


//////////////////////////////////////////////////////
// BUILD "SEND" API QUERY
//////////////////////////////////////////////////////


  IEGetURL>%IE[0]%,currenturl
  Let>recaptcha=http://2captcha.com/in.php?key=
  Concat>%recaptcha%,%apikey%
  Concat>%recaptcha%,&method=userrecaptcha&googlekey=%gkey%
  Concat>%recaptcha%,&pageurl=%currenturl%


//////////////////////////////////////////////////////
// SEND QUERY & VALIDATE RESPONSE
//////////////////////////////////////////////////////


  HTTPRequest>%recaptcha%,,GET,,APIResponse
  GetTime>QuerySubTime


  Pos>OK,APIResponse,1,QueryResp
  If>QueryResp=0
  MDL>The API Query Was Not Valid:%CRLF%%APIResponse%
  Endif


//////////////////////////////////////////////////////
// PARSE CAPTCHA ID FROM API RESPONSE
//////////////////////////////////////////////////////


  Let>pattern=\d+
  RegEx>pattern,%APIResponse%,0,CapIDArr,CapIDNum,0


  If>CapIDNum=0
  MDL>Captcha ID Not Found!
  Exit>0
  Endif


  Let>capid=CapIDArr_1


//////////////////////////////////////////////////////
// BUILD "RESULT" API QUERY
//////////////////////////////////////////////////////


  Let>recaptcha=http://2captcha.com/res.php?key=
  Concat>%recaptcha%,%apikey%
  Concat>%recaptcha%,&action=get&id=
  Concat>%recaptcha%,%capid%


//////////////////////////////////////////////////////
// REQUEST RESULT
//////////////////////////////////////////////////////


  Label>SolveDelay
  GetTime>Now
  TimeDiff>Now,QuerySubTime,S,QuerySecs
  If>QuerySecs<15
  Wait>1
  Goto>SolveDelay
  Endif


  Label>GetResult
  HTTPRequest>%recaptcha%,,GET,,APIResult


  If>%APIResult%=CAPCHA_NOT_READY
  Wait>5
  Goto>GetResult
  Endif


  Pos>OK,%APIResult%,1,TokenRes
  If>TokenRes=0
  Goto>GetResult
  Endif


//////////////////////////////////////////////////////
// PARSE TOKEN
//////////////////////////////////////////////////////


  Let>pattern=(?<=OK\|)(.+)
  RegEx>pattern,%APIResult%,0,TokenArr,TokenNum,0
  If>TokenNum>0
  Let>Token=TokenArr_1
  Endif


  If>TokenNum=0
  MDL>Token Not Found
  Exit>0
  Endif

 
//////////////////////////////////////////////////////
// INJECT TOKEN
//////////////////////////////////////////////////////


  IEFormFill>%IE[0]%,,,g-recaptcha-response,%Token%,,Result

Post Reply