daily pastebin goal
0%
SHARE
TWEET

Модуль для anti-captcha.com и rucaptcha.com

a guest Dec 20th, 2016 1,037 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. unit antigate;
  2.  
  3. interface
  4.  
  5. uses HTTPSend, SSL_OpenSSL, Classes, SysUtils, SynAUtil;
  6.  
  7. function Recognize(capa: TMemoryStream; Key:string; rucaptcha:boolean):string;
  8. function RecognizeRC(SiteKey, PageURL, APIKey:string; rucaptcha:boolean):string;
  9.  
  10. const
  11.   CRLF=#$0D#$0A;
  12.   sleep_ms = 5000;
  13.  
  14. implementation
  15.  
  16. function GetFormValue(Bound, Parametr, Value:String): String;
  17. begin
  18.   Result:='--'+Bound+CRLF+'Content-Disposition: form-data; name="'+Parametr+'"'+CRLF+CRLF+Value+CRLF;
  19. end;
  20.  
  21. function Recognize(capa: TMemoryStream; Key:string; rucaptcha:boolean):string;
  22. var Bound, ftype, s, CaptchaID, url:string; soft_id:integer;
  23.     i:Integer;
  24.     Resp:TStringList;
  25.     Image:TMemoryStream;
  26.     HTTP:THTTPSend;
  27. begin
  28.   ftype:='image/png';
  29.   if rucaptcha then begin
  30.     url:='http://rucaptcha.com/';
  31.     soft_id:=902;
  32.   end else begin
  33.     url:='http://antigate.com/';
  34.     soft_id:=362;
  35.   end;
  36.  
  37.   Resp:=TStringList.Create;
  38.   Image:=TMemoryStream.Create;
  39.   Image.LoadFromStream(capa);
  40.  
  41.   HTTP:=THTTPSend.Create;
  42.  
  43.   Randomize;
  44.   Bound:='-----' +IntToHex(random(65535), 8)+'_boundary';
  45.  
  46.   Resp.Text:=GetFormValue(Bound, 'method', 'post');
  47.   Resp.Text:=Resp.Text+GetFormValue(Bound, 'key', key);
  48.   Resp.Text:=Resp.Text+GetFormValue(Bound, 'soft_id', IntToStr(soft_id));
  49.   Resp.Text:=Resp.Text+'--'+Bound+CRLF;
  50.  
  51.   Resp.Text:=Resp.Text+'Content-Disposition: form-data; name="file"; filename="image.gif"'+CRLF+'Content-Type: '+ftype+CRLF+CRLF;
  52.   WriteStrToStream(HTTP.Document, Resp.Text);
  53.   HTTP.Document.CopyFrom(Image, 0);
  54.   Resp.Text:=CRLF+'--'+Bound+'--'+CRLF;
  55.   WriteStrToStream(HTTP.Document, Resp.Text);
  56.  
  57.   HTTP.MimeType:='multipart/form-data; boundary='+Bound;
  58.   if (HTTP.HTTPMethod('POST', url+'in.php')) then begin
  59.     Resp.LoadFromStream(HTTP.Document);
  60.     s:=Resp.Strings[0];
  61.     Result:=s;
  62.     CaptchaID:='';
  63.     if (Pos('ERROR_', s) < 1) then begin
  64.       if (Pos('OK|', s) > 0) then CaptchaID:=StringReplace(s, 'OK|', '', [rfReplaceAll]);
  65.       if (CaptchaID <> '') then begin
  66.         Result:=CaptchaID;
  67.         for i:=0 to 20 do begin
  68.           Sleep(sleep_ms);
  69.           HTTP.Clear;
  70.           if (HTTP.HTTPMethod('GET', url+'res.php?key='+key+'&action=get&id='+CaptchaID)) then begin
  71.             Resp.LoadFromStream(HTTP.Document);
  72.             s:=Resp.Strings[0];
  73.             if (Pos('ERROR_', s) > 0) then begin
  74.               result:= s;
  75.               break;
  76.             end;
  77.             if (Pos('OK|', s) > 0) then begin
  78.               result:=StringReplace(s, 'OK|', '', [rfReplaceAll]);
  79.               break;
  80.             end;
  81.           end;
  82.           result:= 'ERROR_TIMEOUT';
  83.         end;
  84.       end else result:= 'ERROR_BAD_CAPTCHA_ID';
  85.     end;
  86.   end else result:= 'ERROR_CONNECT';
  87.  
  88.   Resp.Free;
  89.   Image.Free;
  90.   HTTP.Free;
  91. end;
  92.  
  93.  
  94. function Pars(T_, ForS, _T:string):string;
  95. var a, b:integer;
  96. begin
  97.   Result := '';
  98.   if (T_='') or (ForS='') or (_T='') then Exit;
  99.   a:=Pos(T_, ForS);
  100.   if a=0 then Exit else a:=a+Length(T_);
  101.   ForS:=Copy(ForS, a, Length(ForS)-a+1);
  102.   b:=Pos(_T, ForS);
  103.   if b>0 then
  104.   Result:=Copy(ForS, 1, b - 1);
  105. end;
  106.  
  107. function RecognizeRC(SiteKey, PageURL, APIKey:string; rucaptcha:boolean):string;
  108. var page, CaptchaID:string; soft_id, i:integer;
  109.     Resp:TStringList; send:TStringStream; HTTP:THTTPSend;
  110. begin
  111.   if rucaptcha then begin
  112.     soft_id:=902;
  113.   end else begin
  114.     soft_id:=362;
  115.   end;
  116.  
  117.   case soft_id of
  118.     902:begin
  119.       HTTP:=THTTPSend.Create;
  120.       HTTP.Protocol:='1.1';
  121.       HTTP.HTTPMethod('GET', 'http://rucaptcha.com/in.php?soft_id='+IntToStr(soft_id)+'&key='+APIKey+'&method=userrecaptcha&googlekey='+SiteKey+'&pageurl='+PageURL);
  122.       Resp:=TStringList.Create;
  123.       Resp.LoadFromStream(HTTP.Document);
  124.       CaptchaID:=Copy(Resp[0], 4, Length(Resp[0]));
  125.       Resp.Free;
  126.       HTTP.Free;
  127.  
  128.       for i:=0 to 20 do begin
  129.         sleep(sleep_ms);
  130.  
  131.         HTTP:=THTTPSend.Create;
  132.         HTTP.Protocol:='1.1';
  133.         HTTP.HTTPMethod('GET', 'http://rucaptcha.com/res.php?key='+APIKey+'&action=get&id='+CaptchaID);
  134.         Resp:=TStringList.Create;
  135.         Resp.LoadFromStream(HTTP.Document);
  136.         result:=Resp[0];
  137.         Resp.Free;
  138.         HTTP.Free;
  139.         if pos('OK|', result)>0 then begin
  140.           Delete(result, 1, 3);
  141.           break;
  142.         end;
  143.       end;
  144.     end;
  145.  
  146.     362:begin
  147.       Resp:=TStringList.Create;
  148.       HTTP:=THTTPSend.Create;
  149.       HTTP.AddPortNumberToHost:=false;
  150.       HTTP.Protocol:='1.1';
  151.       HTTP.MimeType:='application/x-www-form-urlencoded';
  152.       send:=TStringStream.Create('');
  153.       send.WriteString('{'+
  154.         '"clientKey":"'+APIKey+'",'+
  155.         '"task":{'+
  156.           '"type":"NoCaptchaTaskProxyless",'+
  157.           '"websiteURL":"'+StringReplace(PageURL, '/', '\/', [rfReplaceAll])+'",'+
  158.           '"websiteKey":"'+SiteKey+'"'+
  159.         '},'+
  160.         '"softId":'+IntToStr(soft_id)+','+
  161.         '"languagePool":"en"'+
  162.       '}');
  163.       HTTP.Document.LoadFromStream(send);
  164.       send.Free;
  165.  
  166.       if (HTTP.HTTPMethod('POST', 'https://api.anti-captcha.com/createTask')) then begin
  167.         Resp.LoadFromStream(HTTP.Document);
  168.         page:=StringReplace(Resp[0], ' ', '', [rfReplaceAll]);
  169.  
  170.         if pos('"errorId":0', page)>0 then begin
  171.           CaptchaID:=Pars('"taskId":', page, '}');
  172.           send:=TStringStream.Create('');
  173.           send.WriteString('{"clientKey":"'+APIKey+'","taskId":'+CaptchaID+'}');
  174.  
  175.           for i:=0 to 20 do begin
  176.             sleep(sleep_ms);
  177.             HTTP.Document.Clear;
  178.             HTTP.Headers.Clear;
  179.  
  180.             HTTP.Document.LoadFromStream(send);
  181.  
  182.             HTTP.HTTPMethod('POST', 'https://api.anti-captcha.com/getTaskResult');
  183.             Resp:=TStringList.Create;
  184.             Resp.LoadFromStream(HTTP.Document);
  185.             page:=Resp.Text;
  186.             Resp.Free;
  187.  
  188.             if pos('"status":"ready"', page)>0 then begin
  189.               result:=Pars('"gRecaptchaResponse":"', page, '"');
  190.               break;
  191.             end;
  192.           end;
  193.           send.Free;
  194.         end else begin
  195.           result:= 'ERROR_'+Pars('"errorId":', page, ',');
  196.         end;
  197.       end else result:= 'ERROR_CONNECT';
  198.       HTTP.Free;
  199.     end;
  200.   end;
  201. end;
  202.  
  203. end.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top