Jump to content

  •  

  • iBotModz CBox


    Photo

    C# Loading reCaptcha into a imagebox


    • Please log in to reply
    26 replies to this topic

    #1 iBotPeaches

    iBotPeaches

      General Grade 6

    • Owner

    • 6,570 posts
    • Joined: 29-July 07
    • Gender:Male
    • Location:Kansas

    Posted 12 June 2009 - 06:14 PM

    I went through about a week of making bots, and when you make a bot you have to be able to download the image from the CAPTCHA (or in this case ReCaptcha) so you can display it to the user to be entered, or send it to decaptcher for them to crack it.

    If you don't understand what that meant, this tutorial isn't for you. I'm just going to walk through how to pull the image from the ReCaptcha field. This tutorial assumes you have a hidden web browser in which you are using to navigate some page. This is assuming the basic GetElementByID doesn't work, since its generated dynamically per pageload.

    code2.png


    This is our code.

    Were using a foreach loop to go through every image in the Webbrowser
    foreach (HtmlElement images in webBrowser1.Document.Images)

    Now were doing a quick if statement to see if that image path has the URL of the recaptcha in it.
    if (images.GetAttribute("src").Contains("http://api.recaptcha.net/image?c="))

    GetAttribute allows you to lots of things with a specific HTMLElement (in this case images)

    If it matches a simple line will dump that URL to an imagebox.
    string url = images.GetAttribute("src");

    Then dump the variable url to your imagebox. Ignore the code tCount++; in there, it was part of that application.

    So it starts as a picture box.
    precap.png
    Assuming you grabbed the URL of the image correctly, it should show the image like so.
    postcap.png

    #2 SmokiestGrunl

    SmokiestGrunl

      Australian Retired Staff

    • Retired Staff

    • 3,888 posts
    • Joined: 02-September 07
    • Gender:Male
    • Location:Australia

    Posted 12 June 2009 - 06:46 PM

    Nice tutorial, easy to follow, but I don't know when it will come in handy for me.

    #3 Dark Slipstream

    Dark Slipstream

      Blue Shadowz Owner

    • Members+

    • 2,829 posts
    • Joined: 19-April 08
    • Gender:Male
    • Location:Canada, ON

    Posted 12 June 2009 - 07:39 PM

    Nicely done, ;D

    #4 iKhaosmaster

    iKhaosmaster

      Yawn

    • Members+

    • 1,346 posts
    • Joined: 29-April 08
    • Gender:Male

    Posted 14 June 2009 - 12:00 AM

    Good tutorial Peaches.

    #5 Meonline

    Meonline

      Recruit

    • Members

    • 1 posts
    • Joined: 09-November 09

    Posted 09 November 2009 - 03:54 AM

    First of all , thanks for this good Method iBotPeaches , but what about if i am not using the web browser and requesting the register page with http web request how i can fetch the recaptcha image, tried to generate it with the site key but alwayz the response come back with : " Sorry but your captcha input was not correct. hope you can help,

    Thanks!
    Co

    #6 iBotPeaches

    iBotPeaches

      General Grade 6

    • Owner

    • 6,570 posts
    • Joined: 29-July 07
    • Gender:Male
    • Location:Kansas

    Posted 09 November 2009 - 05:58 AM

    I don't know how you navigate a httpwebrequest, but if you can do a simple foreach in it to grab the URL of the image box, then you can just declare your streams and grab the image.

     	HttpWebRequest Request;
     	HttpWebResponse Response;
    
     	Request = (HttpWebRequest)System.Net.WebRequest.Create(URL);
    
     	Response = (HttpWebResponse)(WebResponse)Request.GetResponse();
    
     	return System.Drawing.Image.FromStream(Response.GetResponseStream());
    


    #7 derekchrisp

    derekchrisp

      Apprentice Grade 1

    • Members+

    • 6 posts
    • Joined: 31-December 09

    Posted 06 January 2010 - 07:17 AM

    For me your code wont work throws an exeption :(

    #8 iBotPeaches

    iBotPeaches

      General Grade 6

    • Owner

    • 6,570 posts
    • Joined: 29-July 07
    • Gender:Male
    • Location:Kansas

    Posted 06 January 2010 - 08:30 AM

    Then you typed it wrong.

    Unless its the code directly above your post, because I just wrote that from memory.

    #9 derekchrisp

    derekchrisp

      Apprentice Grade 1

    • Members+

    • 6 posts
    • Joined: 31-December 09

    Posted 07 January 2010 - 06:56 AM

    I was talking about your first post. Maybe i am doing something wrong ( im still learning all that c# stuff)

    but tried like this


                foreach (HtmlElement images in webBrowser1.Document.Images)
                {
                    if (images.GetAttribute("src").Contains("http://api.recaptcha.net/image?c="))
                    {
                        string url = images.GetAttribute("src");
                        pictureBox1.ImageLocation = url;
                        break;
                    }
                }
    

    Picture box stays empty. Not sure what im doing wrong

    Edited by derekchrisp, 07 January 2010 - 06:57 AM.


    #10 derekchrisp

    derekchrisp

      Apprentice Grade 1

    • Members+

    • 6 posts
    • Joined: 31-December 09

    Posted 07 January 2010 - 07:49 AM

    I think it's probably because captcha is generated dynamically it's src is not actually in html source. To get captchas location you have to get access to DOM and grab images src from there.

    Edited by derekchrisp, 07 January 2010 - 07:49 AM.


    #11 iBotPeaches

    iBotPeaches

      General Grade 6

    • Owner

    • 6,570 posts
    • Joined: 29-July 07
    • Gender:Male
    • Location:Kansas

    Posted 07 January 2010 - 07:53 AM

    
                        foreach (HtmlElement images in webBrowser1.Document.Images)
                        {
                            if (images.GetAttribute("src").Contains("http://api.recaptcha.net/image?c="))
                            {
                                string url = images.GetAttribute("src");
                                title = webBrowser1.Document.Title;
                                capImage.ImageLocation = url;
                                break;
                            }
                        }
    

    Just tested this code and the recaptcha popped up. So it still works this way. Add me on MSN (ibotpeaches@ibotmodz.net), and I'll try and see whats up.

    #12 derekchrisp

    derekchrisp

      Apprentice Grade 1

    • Members+

    • 6 posts
    • Joined: 31-December 09

    Posted 07 January 2010 - 10:46 AM

    So ok i tested following tell me what a heck im doing wrong like i said im really new with this so it makes me bit headache :)

    Testing with mixx registration page https://www.mixx.com/register

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace test2
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            {
                foreach (HtmlElement images in webBrowser1.Document.Images)
                {
                    if (images.GetAttribute("src").Contains("http://api.recaptcha.net/image?c="))
                    {
                        string url = images.GetAttribute("src");
                        pictureBox1.ImageLocation = url;
                        break;
                    }
                }
            }
    
            private void goButton_Click(object sender, EventArgs e)
            {
                webBrowser1.Navigate(txtUrl.Text);
            }
    
            private void pictureBox1_Click(object sender, EventArgs e)
            {
    
            }
    
            private void txtUrl_TextChanged_1(object sender, EventArgs e)
            {
    
            }
        }
    }
    

    Edited by derekchrisp, 07 January 2010 - 10:47 AM.


    #13 iBotPeaches

    iBotPeaches

      General Grade 6

    • Owner

    • 6,570 posts
    • Joined: 29-July 07
    • Gender:Male
    • Location:Kansas

    Posted 07 January 2010 - 11:00 AM

    o, that site is using the recaptcha in an iframe, and it uses this url instead of the other one.

    https://api-secure.recaptcha.net/noscript?k=6LesGQMAAAAAAF0BRs_lsPUkSrYZ-qcgqgoiR-Mv

    Probably would take 10 minutes to adapt my script to make it work, so just catch me on MSN and I'll see if I can get yours working.

    #14 derekchrisp

    derekchrisp

      Apprentice Grade 1

    • Members+

    • 6 posts
    • Joined: 31-December 09

    Posted 07 January 2010 - 11:11 AM

    I can easily crack it through noscript solution with php . Thats not problem . But im trying to do it without noscript. Let's take Twitter https://twitter.com/signup . As you can see they don't offer noscript access so this is what makes me some headache.
    Hey i added you in msn im kaidoristm@

    Edited by derekchrisp, 07 January 2010 - 11:27 AM.


    #15 derekchrisp

    derekchrisp

      Apprentice Grade 1

    • Members+

    • 6 posts
    • Joined: 31-December 09

    Posted 09 January 2010 - 11:54 AM

    Hey iBotPeaches do you know how to post form data through multipart/form-data without messing boundaryes . Not trying to upload file just post fields values.

    #16 decrypT

    decrypT

      Recruit

    • Members+

    • 4 posts
    • Joined: 04-August 10

    Posted 04 August 2010 - 01:52 AM

    I need some help with the captcha's

    How would i make the application re-grab the captcha if the page is refreshed?

    Also, it seems like my app doesn't grab the captcha if my bot's forms are filled.

    Like, my bot has textboxes that submit a form on a webpage. If my bot's textboxes are filled and sent to the webpage, it won't grab the captcha, however if the boxes are left empty, the captcha is grabbed.

    Any help would be awesome!


    --decrypT

    #17 decrypT

    decrypT

      Recruit

    • Members+

    • 4 posts
    • Joined: 04-August 10

    Posted 07 August 2010 - 03:36 AM

    Quick bump.

    Still in need of some help.

    #18 iBotPeaches

    iBotPeaches

      General Grade 6

    • Owner

    • 6,570 posts
    • Joined: 29-July 07
    • Gender:Male
    • Location:Kansas

    Posted 07 August 2010 - 07:32 AM

    How would i make the application re-grab the captcha if the page is refreshed?


    Use the webbrowser event of like doneLoading, so anytime it is refreshed and re-loaded that portion of code will be re-ran so you then can call your reCaptcha code or just include it in there.

    Like, my bot has textboxes that submit a form on a webpage. If my bot's textboxes are filled and sent to the webpage, it won't grab the captcha, however if the boxes are left empty, the captcha is grabbed.


    Does your bot use getElementByID? I think it conflicts somewhere and there is one variable you have to re-init, but I can't remember why or which one.

    #19 decrypT

    decrypT

      Recruit

    • Members+

    • 4 posts
    • Joined: 04-August 10

    Posted 08 August 2010 - 02:08 AM

    Use the webbrowser event of like doneLoading, so anytime it is refreshed and re-loaded that portion of code will be re-ran so you then can call your reCaptcha code or just include it in there.



    Does your bot use getElementByID? I think it conflicts somewhere and there is one variable you have to re-init, but I can't remember why or which one.


    Yes, it uses getelementbyid and by name. Also, the doneLoading event, is that just like.

    if(webBrowser1.doneLoading)
    {
    Code for regrabbing the catpcha
    }
    ?

    Thanks for the reply.

    Edited by decrypT, 08 August 2010 - 02:10 AM.


    #20 iBotPeaches

    iBotPeaches

      General Grade 6

    • Owner

    • 6,570 posts
    • Joined: 29-July 07
    • Gender:Male
    • Location:Kansas

    Posted 08 August 2010 - 06:55 AM

    Posted Image

    • Click on your webBrowser (If its a hidden one select it from the dropdown)
    • Click the lightning bolt to bring up events
    • Double click on DocumentCompleted
    • That will move to your code and form the function
    Looks like this.

    Posted Image


    You cannot just type that out, you gotta do all the steps to insure the handler picks up the event.