CGC_Codes

Captcha bypass

Jun 7th, 2017
686
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.37 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using RestSharp;
  5.  
  6. namespace TwoCaptchaSharp
  7. {
  8.  
  9.  
  10.  
  11.     enum Language { CaptchaDefault = 0, Russian = 1, English = 2 }
  12.     public class TwoCaptchaSharp
  13.     {
  14.  
  15.  
  16.         public string Key { get; set; }
  17.         public string RecaptchaTextInstructions { get; set; }
  18.         public int Language { get; set; }
  19.         public int GetIdCaptcha;
  20.         public TwoCaptchaSharpImage Image;
  21.  
  22.  
  23.  
  24.  
  25.         public Task<string> ExecuteAsync()
  26.         {
  27.             var t = new Task<string>(() =>
  28.             {
  29.  
  30.                 return this.Execute();
  31.  
  32.             });
  33.             return t;
  34.         }
  35.  
  36.  
  37.  
  38.         public string Execute()
  39.         {
  40.             string result = string.Empty;
  41.             if (String.IsNullOrEmpty(Key))
  42.                 throw new Exception("Key provided is empty of null");
  43.             if (string.IsNullOrEmpty(RecaptchaTextInstructions))
  44.                 throw new Exception("Instructions provided is empty of null");
  45.             if (!(new int[] { 0, 1, 2 }).ToList<int>().Contains(Language))
  46.                 throw new Exception("Unrecognizable language number. 0 is Default, Russian is 1 and English is 2");
  47.             if (!(new int[] { 0, 1 }).ToList<int>().Contains(GetIdCaptcha))
  48.                 throw new Exception("GetIdCaptcha value is not correct.");
  49.             if (Image == null)
  50.                 throw new System.NullReferenceException();
  51.  
  52.             var TwoCaptcha = new RestClient("http://rucaptcha.com");
  53.             var Request = new RestRequest("/in.php", Method.POST);
  54.            
  55.             if (Image.IsPathDefined)
  56.                 Request.AddFile("file", Image.Path, null);
  57.             else
  58.                 Request.AddFile("file", Image.ByteArr, null, null);
  59.            
  60.             Request.AddParameter("language", Language);
  61.             Request.AddParameter("2Captcha", 1);
  62.             Request.AddParameter("textinstructions", string.Format("%{0}%", RecaptchaTextInstructions));
  63.             Request.AddParameter("get_id", GetIdCaptcha);
  64.  
  65.  
  66.             return TwoCaptcha.Execute(Request).Content;
  67.  
  68.         }
  69.  
  70.  
  71.         public TwoCaptchaSharp(string key)
  72.         { Key = key; }
  73.  
  74.     }
  75.     public class TwoCaptchaSharpImage
  76.     {
  77.  
  78.  
  79.        
  80.  
  81.         public TwoCaptchaSharpImage(string path)
  82.         {
  83.             Extensions = new string[] { ".jpg", ".png", ".jpeg" };
  84.             var info = new System.IO.FileInfo(path);
  85.             if (!info.Directory.Exists)
  86.             { throw new System.IO.DirectoryNotFoundException(); }
  87.             else if (!info.Exists)
  88.             { throw new System.IO.FileNotFoundException(); }
  89.             else if (!Extensions.ToList<string>().Exists(x => x == info.Extension.ToLower()))
  90.             { throw new Exception("Incorrect extension. Image extension must be jpg, jpeg or png."); }
  91.             else
  92.             {
  93.                 Path = path;
  94.                 IsPathDefined = true;
  95.             }
  96.         }
  97.  
  98.  
  99.         public TwoCaptchaSharpImage(Byte[] bytearr)
  100.         {
  101.  
  102.             ByteArr = bytearr;
  103.             IsBytesDefined = true;
  104.         }
  105.  
  106.         public bool IsPathDefined { get; private set; }
  107.         public bool IsBytesDefined { get; private set; }
  108.         public string Path { get; private set; }
  109.         public Byte[] ByteArr { get; private set; }
  110.         string[] Extensions { get; set; }
  111.     }
  112.  
  113.  
  114. }
Advertisement
Add Comment
Please, Sign In to add comment