Example #1
0
 static protected void Decoded(Captcha captcha)
 {
     if (null != captcha)
     {
         Console.WriteLine("CAPTCHA {0:D} solved: {1}",
                           captcha.Id, captcha.Text);
     }
     else
     {
         Console.WriteLine("CAPTCHA was not solved");
     }
     ExampleAsync._ready.Set();
 }
Example #2
0
        /**
         * <see cref="M:DeathByCaptcha.Client.Upload(ext_data[])"/>
         * <param name="ext_data">Extra data used by special captchas types.</param>
         */
        public override Captcha Upload(Hashtable ext_data)
        {
            string boundary = BitConverter.ToString(
                (new SHA1CryptoServiceProvider()).ComputeHash(
                    Encoding.ASCII.GetBytes(DateTime.Now.ToString("G"))
                    )
                ).Replace("-", String.Empty);

            Hashtable args = this.Credentials;

            args["swid"] = Convert.ToString(Client.SoftwareVendorId);


            if (ext_data != null)
            {
                foreach (DictionaryEntry item in ext_data)
                {
                    args [Convert.ToString(item.Key)] = item.Value.ToString();
                }
            }

            string[] rawArgs = new string[args.Count + 2];
            int      i       = 0;

            foreach (DictionaryEntry e in args)
            {
                string v = (string)e.Value;
                rawArgs[i++] = String.Join("\r\n", new string[] {
                    "--" + boundary,
                    "Content-Disposition: form-data; name=\"" + (string)e.Key + "\"",
                    "Content-Length: " + v.Length,
                    "",
                    v
                });
            }

            byte[] hdr  = Encoding.ASCII.GetBytes(String.Join("\r\n", rawArgs));
            byte[] ftr  = Encoding.ASCII.GetBytes("\r\n--" + boundary + "--\r\n");
            byte[] body = new byte[hdr.Length + ftr.Length];
            hdr.CopyTo(body, 0);

            ftr.CopyTo(body, hdr.Length);

            Captcha c = new Captcha(this.Call(
                                        "captcha",
                                        body,
                                        "multipart/form-data; boundary=" + boundary
                                        ));

            return(c.Uploaded ? c : null);
        }
        private void DebugCaptcha(byte[] image, Captcha captchaResult)
        {
            var guid = Guid.NewGuid();

            var fileName = string.Format("{0}-{1}", guid, captchaResult.Text);

            File.WriteAllBytes(fileName + ".jpg", image);

            var captchaText = string.Format("Id={0}\nCorrect={1}\nText={2}\nSolved={3}\nUploaded={4}", captchaResult.Id, captchaResult.Correct,
                captchaResult.Text, captchaResult.Solved, captchaResult.Uploaded);

            File.WriteAllText(fileName + ".txt", captchaText);

        }
Example #4
0
        /**
         * <summary>Upload and wait for a CAPTCHA to be solved.</summary>
         * <param name="img">Raw CAPTCHA image.</param>
         * <param name="timeout">Solving timeout (in seconds).</param>
         * <returns>CAPTCHA if solved, null otherwise.</returns>
         */
        public Captcha Decode(byte[] img, int timeout)
        {
            DateTime deadline =
                DateTime.Now.AddSeconds(0 < timeout ? timeout : Client.DefaultTimeout);
            Captcha captcha = this.Upload(img);

            if (null != captcha)
            {
                while (deadline > DateTime.Now && !captcha.Solved)
                {
                    Thread.Sleep(Client.PollsInterval * 1000);
                    captcha = this.GetCaptcha(captcha);
                }
                if (captcha.Solved && captcha.Correct)
                {
                    return(captcha);
                }
            }
            return(null);
        }
Example #5
0
        public override Captcha Upload(Hashtable ext_data)
        {
            Hashtable args = new Hashtable();

            args["swid"] = Client.SoftwareVendorId;
            if (ext_data != null && ext_data.ContainsKey("type") && (int)ext_data["type"] > 0)
            {
                args["type"] = Convert.ToString(ext_data["type"]);
            }

            if (ext_data != null)
            {
                foreach (DictionaryEntry item in ext_data)
                {
                    args [Convert.ToString(item.Key)] = item.Value.ToString();
                }
            }


            Captcha c = new Captcha(this.Call("upload", args));

            return(c.Uploaded ? c : null);
        }
Example #6
0
        /**
         * <see cref="M:DeathByCaptcha.Client.Upload(byte[])"/>
         * <param name="ext_data">Extra data used by special captchas types.</param>
         */
        public override Captcha Upload(byte[] img, Hashtable ext_data = null)
        {
            string boundary = BitConverter.ToString(
                (new SHA1CryptoServiceProvider()).ComputeHash(
                    Encoding.ASCII.GetBytes(DateTime.Now.ToString("G"))
                    )
                ).Replace("-", String.Empty);

            Hashtable args = this.Credentials;

            args["swid"] = Convert.ToString(Client.SoftwareVendorId);

            byte[] banner = null;
            if (ext_data != null)
            {
                foreach (DictionaryEntry item in ext_data)
                {
                    if (Convert.ToString(item.Key) == "banner")
                    {
                        banner = this.Load(ext_data["banner"]);
                    }
                    else
                    {
                        args [Convert.ToString(item.Key)] = item.Value.ToString();
                    }
                }
            }

            string[] rawArgs = new string[args.Count + 2];
            int      i       = 0;

            foreach (DictionaryEntry e in args)
            {
                string v = (string)e.Value;
                rawArgs[i++] = String.Join("\r\n", new string[] {
                    "--" + boundary,
                    "Content-Disposition: form-data; name=\"" + (string)e.Key + "\"",
                    "Content-Length: " + v.Length,
                    "",
                    v
                });
            }
            rawArgs[i++] = String.Join("\r\n", new string[] {
                "--" + boundary,
                "Content-Disposition: form-data; name=\"captchafile\"; filename=\"captcha.jpeg\"",
                "Content-Type: application/octet-stream",
                "Content-Length: " + img.Length,
                ""
            });

            string banner_hdr = "";
            int    banner_len = 0;

            byte[] b_hdr = new byte[] {};
            if (banner != null)
            {
                banner_hdr = String.Join("\r\n", new string[] {
                    "\r\n--" + boundary,
                    "Content-Disposition: form-data; name=\"banner\"; filename=\"banner.jpeg\"",
                    "Content-Type: application/octet-stream",
                    "Content-Length: " + banner.Length,
                    "\r\n"
                });
                b_hdr      = Encoding.ASCII.GetBytes(banner_hdr);
                banner_len = b_hdr.Length + banner.Length;
            }
            else
            {
                banner = new byte[] {};
            }

            byte[] hdr  = Encoding.ASCII.GetBytes(String.Join("\r\n", rawArgs));
            byte[] ftr  = Encoding.ASCII.GetBytes("\r\n--" + boundary + "--\r\n");
            byte[] body = new byte[hdr.Length + img.Length + banner_len + ftr.Length];
            hdr.CopyTo(body, 0);
            img.CopyTo(body, hdr.Length);

            if (banner_len > 0)
            {
                b_hdr.CopyTo(body, hdr.Length + img.Length);
                banner.CopyTo(body, hdr.Length + img.Length + b_hdr.Length);
            }

            ftr.CopyTo(body, hdr.Length + img.Length + banner_len);

            Captcha c = new Captcha(this.Call(
                                        "captcha",
                                        body,
                                        "multipart/form-data; boundary=" + boundary
                                        ));

            return(c.Uploaded ? c : null);
        }
Example #7
0
        /**
         * <see cref="M:DeathByCaptcha.Client.Upload(byte[])"/>
         */
        public override Captcha Upload(byte[] img)
        {
            string boundary = BitConverter.ToString(
                (new SHA1CryptoServiceProvider()).ComputeHash(
                    Encoding.ASCII.GetBytes(DateTime.Now.ToString("G"))
                )
            ).Replace("-", String.Empty);

            Hashtable args = this.Credentials;
            args["swid"] = Convert.ToString(Client.SoftwareVendorId);
            string[] rawArgs = new string[args.Count + 2];
            int i = 0;
            foreach (DictionaryEntry e in args) {
                string v = (string)e.Value;
                rawArgs[i++] = String.Join("\r\n", new string[] {
                    "--" + boundary,
                    "Content-Disposition: form-data; name=\"" + (string)e.Key + "\"",
                    "Content-Length: " + v.Length,
                    "",
                    v
                });
            }
            rawArgs[i++] = String.Join("\r\n", new string[] {
                "--" + boundary,
                "Content-Disposition: form-data; name=\"captchafile\"; filename=\"captcha.jpeg\"",
                "Content-Type: application/octet-stream",
                "Content-Length: " + img.Length,
                ""
            });

            byte[] hdr = Encoding.ASCII.GetBytes(String.Join("\r\n", rawArgs));
            byte[] ftr = Encoding.ASCII.GetBytes("\r\n--" + boundary + "--\r\n");
            byte[] body = new byte[hdr.Length + img.Length + ftr.Length];
            hdr.CopyTo(body, 0);
            img.CopyTo(body, hdr.Length);
            ftr.CopyTo(body, hdr.Length + img.Length);

            Captcha c = new Captcha(this.Call(
                "captcha",
                body,
                "multipart/form-data; boundary=" + boundary
            ));
            return c.Uploaded ? c : null;
        }
Example #8
0
 /**
  * <summary>Report an incorrectly solved CAPTCHA.</summary>
  * <param name="captcha">CAPTCHA.</param>
  * <returns>true on success.</returns>
  */
 public bool Report(Captcha captcha)
 {
     return(this.Report(captcha.Id));
 }
Example #9
0
 /**
  * <param name="captcha">CAPTCHA.</param>
  * <returns>Uploaded CAPTCHA text, null if not found or not solved yet.</returns>
  */
 public string GetText(Captcha captcha)
 {
     return(this.GetCaptcha(captcha).Text);
 }
Example #10
0
 /**
  * <param name="captcha">CAPTCHA.</param>
  * <returns>Uploaded CAPTCHA text, null if not found or not solved yet.</returns>
  */
 public string GetText(Captcha captcha)
 {
     return this.GetCaptcha(captcha).Text;
 }
Example #11
0
 /**
  * <param name="captcha">CAPTCHA.</param>
  * <returns>Uploaded CAPTCHA if exists, null otherwise.</returns>
  */
 public Captcha GetCaptcha(Captcha captcha)
 {
     return this.GetCaptcha(captcha.Id);
 }
Example #12
0
 /**
  * <summary>Wait for a CAPTCHA to be solved.</summary>
  * <param name="captcha">Uploaded CAPTCHA.</param>
  * <param name="timeout">Solving timeout (in seconds).</param>
  * <returns>CAPTCHA if solved, null otherwise.</returns>
  */
 protected Captcha Poll(Captcha captcha, int timeout)
 {
     if (null != captcha) {
         DateTime deadline =
             DateTime.Now.AddSeconds(0 < timeout
                 ? timeout
                 : Client.DefaultTimeout);
         while (deadline > DateTime.Now && !captcha.Solved) {
             Thread.Sleep(Client.PollsInterval * 1000);
             try {
                 captcha = this.GetCaptcha(captcha);
             } catch (System.Exception e) {
                 if (this.Verbose) {
                     Console.WriteLine(DateTime.Now.Ticks + " POLL " + e.Message);
                 }
                 return null;
             }
         }
         if (captcha.Solved && captcha.Correct) {
             return captcha;
         }
     }
     return null;
 }
Example #13
0
 /**
  * <summary>Remove an unsolved CAPTCHA.  Deprecated!</summary>
  * <param name="captcha">CAPTCHA.</param>
  * <returns>true on success.</returns>
  */
 public bool Remove(Captcha captcha)
 {
     return(this.Remove(captcha.Id));
 }
Example #14
0
        static public void Main(string[] argv)
        {
            string dbcUsername = argv[0], dbcPassword = argv[1];

            // Put your DBC username & password here.
            //Client client = (Client)new HttpClient(dbcUsername, dbcPassword);
            Client client = (Client) new HttpClient(dbcUsername, dbcPassword);

            //Put your Proxy credentials and type here
            string proxy     = "http://*****:*****@127.0.0.1:1234";
            string proxyType = "HTTP";


            Console.WriteLine("Your balance is {0:F2} US cents", client.Balance);

            if (argv.Length == 4)
            {
                //Create the Json payload, Put the Site url and Sitekey here.
                string tokenParams = "{\"proxy\": \"" + proxy + "\"," +
                                     "\"proxytype\": \"" + proxyType + "\"," +
                                     "\"googlekey\": \"" + argv[3] + "\"," +
                                     "\"pageurl\": \"" + argv[2] + "\"}";

                // Upload a CAPTCHA and poll for its status.  Put the Token CAPTCHA
                // Json payload, CAPTCHA type and desired solving timeout (in seconds)
                // here. If solved, you'll receive a DeathByCaptcha.Captcha object.
                Captcha captcha = client.Decode(Client.DefaultTimeout,
                                                new Hashtable()
                {
                    { "type", 4 },
                    { "token_params", tokenParams }
                });

                if (null != captcha)
                {
                    Console.WriteLine("CAPTCHA {0:D} solved: {1}",
                                      captcha.Id, captcha.Text);

                    // Report an incorrectly solved CAPTCHA.  Make sure the
                    // CAPTCHA was in fact incorrectly solved, do not just
                    // report them all or at random, or you might be banned
                    // as abuser.
                    if (false /* put your CAPTCHA correctness check here */)
                    {
                        if (client.Report(captcha))
                        {
                            Console.WriteLine("Reported as incorrectly solved");
                        }
                        else
                        {
                            Console.WriteLine("Failed reporting as incorrectly solved");
                        }
                    }
                }
                else
                {
                    Console.WriteLine("CAPTCHA was not solved");
                }
            }

            Console.WriteLine("Your balance is {0:F2} US cents", client.Balance);
        }
Example #15
0
 /**
  * <summary>Report an incorrectly solved CAPTCHA.</summary>
  * <param name="captcha">CAPTCHA.</param>
  * <returns>true on success.</returns>
  */
 public bool Report(Captcha captcha)
 {
     return this.Report(captcha.Id);
 }
Example #16
0
        static public void Main(string[] argv)
        {
            string dbcUsername = argv[0], dbcPassword = argv[1];

            // Put your DBC username & password here.
            //Client client = (Client)new HttpClient(dbcUsername, dbcPassword);
            Client client = (Client) new HttpClient(dbcUsername, dbcPassword);

            Console.WriteLine("Your balance is {0:F2} US cents", client.Balance);

            for (int i = 2, l = argv.Length; i < l; i++)
            {
                Console.WriteLine("Solving CAPTCHA {0}", argv[i]);

                // Upload a CAPTCHA and poll for its status.  Put the CAPTCHA
                // image file name, file object, stream, or a vector of bytes,
                // and desired solving timeout (in seconds) here.  If solved,
                // you'll receive a DeathByCaptcha.Captcha object.
                Captcha captcha = client.Decode(argv[i], Client.DefaultTimeout);

                /*
                 * //Uploading captchas with type = 2 (Coordinates API)
                 * Captcha captcha = client.Decode(argv[i], Client.DefaultTimeout,
                 * new Hashtable (){
                 * { "type", 2 }
                 * });
                 *
                 * //Uploading captchas with type = 3 (Image Group API)
                 * Captcha captcha = client.Decode(argv[i], Client.DefaultTimeout,
                 * new Hashtable (){
                 *      { "type", 3 },
                 *      { "grid", "2x4" }, //optional grid parameter
                 *      {"banner_text", "Select all images with meat"},
                 *      {"banner", bannerFileName}
                 * });
                 */

                /*
                 * //Uploading captchas with type = 3 (Image Group API) and grid
                 * Captcha captcha = client.Decode(argv[i], Client.DefaultTimeout,
                 * new Hashtable (){
                 *      { "type", 3 },
                 *      {"banner_text", "Select all images with meat"},
                 *      {"banner", bannerFileName},
                 *      {"grid", "4x4"}
                 * });
                 */
                /*
                 * // Upload a CAPTCHA and poll for its status.  Put the Token CAPTCHA
                 * // Json payload, CAPTCHA type and desired solving timeout (in seconds)
                 * // here. If solved, you'll receive a DeathByCaptcha.Captcha object.
                 * Captcha captcha = client.Decode( Client.DefaultTokenTimeout,
                 *      new Hashtable (){
                 *              { "type", 4 },
                 *              {"token_params", "{\"proxy\": \"http://*****:*****@127.0.0.1:1234\",\"proxytype\": \"HTTP\",\"googlekey\": \"6Lc2fhwTAAAAAGatXTzFYfvlQMI2T7B6ji8UVV_f\",\"pageurl\": \"http://google.com\"}"}
                 *
                 *      });
                 */
                if (null != captcha)
                {
                    Console.WriteLine("CAPTCHA {0:D} solved: {1}",
                                      captcha.Id, captcha.Text);

                    // Report an incorrectly solved CAPTCHA.  Make sure the
                    // CAPTCHA was in fact incorrectly solved, do not just
                    // report them all or at random, or you might be banned
                    // as abuser.
                    if (false /* put your CAPTCHA correctness check here */)
                    {
                        if (client.Report(captcha))
                        {
                            Console.WriteLine("Reported as incorrectly solved");
                        }
                        else
                        {
                            Console.WriteLine("Failed reporting as incorrectly solved");
                        }
                    }
                }
                else
                {
                    Console.WriteLine("CAPTCHA was not solved");
                }
            }

            Console.WriteLine("Your balance is {0:F2} US cents", client.Balance);
        }
Example #17
0
 /**
  * <param name="captcha">CAPTCHA.</param>
  * <returns>Uploaded CAPTCHA if exists, null otherwise.</returns>
  */
 public Captcha GetCaptcha(Captcha captcha)
 {
     return(this.GetCaptcha(captcha.Id));
 }
Example #18
0
 /**
  * <see cref="M:DeathByCaptcha.Client.Upload(byte[])"/>
  */
 public override Captcha Upload(byte[] img)
 {
     Hashtable args = this.Credentials;
     args["swid"] = Client.SoftwareVendorId;
     args["captcha"] = Convert.ToBase64String(img);
     Captcha c = new Captcha(this.Call("upload", args));
     return c.Uploaded ? c : null;
 }
Example #19
0
 /**
  * <summary>Remove an unsolved CAPTCHA.  Deprecated!</summary>
  * <param name="captcha">CAPTCHA.</param>
  * <returns>true on success.</returns>
  */
 public bool Remove(Captcha captcha)
 {
     return this.Remove(captcha.Id);
 }