Grabbing Captcha

Posts 1–15 of 15 · Page 1 of 1
Grabbing Captcha
Hey guys doing another one of my account creators, have everything finished except the captcha hopefully one of you can save my a*s lol you will get creds of course.

So heres the captcha source
Code:
<img src="/captcha/?n=register&amp;t=4dda987287daf" id="keycode" alt="keycode" width="208"></td>
			<td class="reg_form_msg"></td>
And heres my code.
Code:
PictureBox1.ImageLocation = WebBrowser1.Document.GetElementById("keycode").GetAttribute("src")
Basically it shows show a little X in the picturebox like it cant load the image, im trying to do this for the gamerfirst website btw incase you need to check the whole page source. doing it this way has always worked for me so im alittle confused.
Quote Originally Posted by hustelboy View Post
@silentrunner2

because the captcha is protected
is there no way around it?
idk so,
bacause if u change the url and the Id
url nexon.net register
Then it works
I gonna look, maby just a wrong ID u have
Wait, I can access the image from my web browser, so yea, just try to get the image using IO.Stream ...
Code:
        Dim req As Net.HttpWebRequest = Net.HttpWebRequest.Create("http://www.gamersfirst.com/captcha/?n=register&amp;t=4dda987287daf")
        Dim res As Net.HttpWebResponse = req.GetResponse()
        Dim Sr As IO.Stream = res.GetResponseStream()
        Dim i As Image = Image.FromStream(Sr)
        PictureBox1.Image = i
Quote Originally Posted by user590177 View Post
Wait, I can access the image from my web browser, so yea, just try to get the image using IO.Stream ...
Code:
        Dim req As Net.HttpWebRequest = Net.HttpWebRequest.Create("http://www.gamersfirst.com/captcha/?n=register&amp;t=4dda987287daf")
        Dim res As Net.HttpWebResponse = req.GetResponse()
        Dim Sr As IO.Stream = res.GetResponseStream()
        Dim i As Image = Image.FromStream(Sr)
        PictureBox1.Image = i
U will always get the same captcha then
Quote Originally Posted by hustelboy View Post
U will always get the same captcha then
It will work?
Captcha is just for verifying that you aren't a bot, if the image is the same doesn't matter.
Quote Originally Posted by user590177 View Post
Wait, I can access the image from my web browser, so yea, just try to get the image using IO.Stream ...
Code:
        Dim req As Net.HttpWebRequest = Net.HttpWebRequest.Create("http://www.gamersfirst.com/captcha/?n=register&amp;t=4dda987287daf")
        Dim res As Net.HttpWebResponse = req.GetResponse()
        Dim Sr As IO.Stream = res.GetResponseStream()
        Dim i As Image = Image.FromStream(Sr)
        PictureBox1.Image = i
does not work, just says the server returned an error (500) :/ thanks for helping so far buddy.
Quote Originally Posted by user590177 View Post


It will work?
Captcha is just for verifying that you aren't a bot, if the image is the same doesn't matter.
Of course it won't work |:


Quote Originally Posted by silentrunner2 View Post
Hey guys doing another one of my account creators, have everything finished except the captcha hopefully one of you can save my a*s lol you will get creds of course.

So heres the captcha source
Code:
<img src="/captcha/?n=register&amp;t=4dda987287daf" id="keycode" alt="keycode" width="208"></td>
			<td class="reg_form_msg"></td>
And heres my code.
Code:
PictureBox1.ImageLocation = WebBrowser1.Document.GetElementById("keycode").GetAttribute("src")
Basically it shows show a little X in the picturebox like it cant load the image, im trying to do this for the gamerfirst website btw incase you need to check the whole page source. doing it this way has always worked for me so im alittle confused.
You've got a relative URL there. an imagebox will try to load the captcha at "/captcha/?n=register&amp;t=4dda987287daf"... Which is nowhere, an invalid URL, so the red box with a cross comes up.

Fix this by adding the root info. For example, rather than just
Code:
"/captcha/?n=register&amp;t=4dda987287daf";
, you'd add
Code:
"http://example.com" + "/captcha/?n=register&amp;t=4dda987287daf"
Quote Originally Posted by freedompeace View Post


Of course it won't work |:




You've got a relative URL there. an imagebox will try to load the captcha at "/captcha/?n=register&amp;t=4dda987287daf"... Which is nowhere, an invalid URL, so the red box with a cross comes up.

Fix this by adding the root info. For example, rather than just
Code:
"/captcha/?n=register&amp;t=4dda987287daf";
, you'd add
Code:
"http://example.com" + "/captcha/?n=register&amp;t=4dda987287daf"
As far as I can remember the webbrowser control usually returns an absolute URL when you access any attributes containing a relative URL, but then again, I could be thinking of something completely different
yes is does..
Everytime u generator a new account.
The page should be reloaded of webbbrowser
then a new captcha will come and the new 1 and the 1 that is always the same wont match
So then the captcha will be wrong
Cause of this : /captcha/?n=register&amp;t=4dda987287daf


The picture box image must be = website + /captcha/?n=register&amp;t=4dda987287daf

Its something like:

Code:
PictureBox1.ImageLocation = "Websitehere" & WebBrowser1.Document.GetElementById("keycode").GetAttribute("src")
None of these codes will work as everytime you load the links it will generate a new image. In this case however, it seems to generate the same letters but in a different pattern I guess. I had a problem with ReCaptcha where it'd generate a new image all the time and here is how to get the image object with the usage of a web browser control:

[highlight=vb.net]'You must add a reference to Microsoft.mshtml from the .NET tab
'If you are smart, you would know what goes in the stars. MPGH seems to be censoring some words.
Imports System****ntime.InteropServices

<ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown ), Guid("3050F669-98B5-11CF-BB82-00AA00BDCE0B")> _
Interface IHTMLElementRenderFixed
Sub DrawToDC(ByVal hdc As IntPtr)
Sub SetDocumentPrinter(<MarshalAs(UnmanagedType.BStr)> ByVal bstrPrinterName As String, ByVal hdc As IntPtr)
End Interface

Private Function GetCaptchaImage(ByRef wb As WebBrowser, ByVal captchaSubString As String, ByRef imageLocation As String, ByRef foundCaptchaImage As Boolean) As Image
For Each imgElem As HtmlElement In WebBrowser1.Document.Images
Dim currentImageURL As String = imgElem.GetAttribute("src")
If currentImageURL.Contains(captchaSubString) Then
Dim bmp As Image = HTMLElementToImage(imgElem)
imageLocation = currentImageURL
foundCaptchaImage = True
Return bmp
End If
Next
foundCaptchaImage = False
Return Nothing
End Function

Private Function HTMLElementToImage(ByVal elem As HtmlElement) As Image
Dim imgElem As mshtml.IHTMLImgElement = CType(elem.DomElement, mshtml.IHTMLImgElement)
Dim imgRender As IHTMLElementRenderFixed = CType(imgElem, IHTMLElementRenderFixed)
Dim bmp As New Bitmap(imgElem.width, imgElem.height)
Dim g As Graphics = Graphics.FromImage(bmp)
Dim hdc As IntPtr = g.GetHdc
imgRender.DrawToDC(hdc)
g.ReleaseHdc(hdc)
g.Dispose()
Return bmp
End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim captchaSucess As Boolean
Dim imageLocation As String = String.Empty
Dim captchaImage As Image = GetCaptchaImage(WebBrowser1, "recaptcha/api", imageLocation, captchaSucess)
If captchaSucess = False Then
MsgBox("Captcha image could not be found!")
Else
MsgBox("Captcha image found: " & imageLocation)
PictureBox1.Image = captchaImage
End If
End Sub[/highlight]

It should be self explanatory.
wb is the reference to your WebBrowser control.
The captchaSubString is a String which contains the substring of the image link. In this example, all ReCaptcha captcha image links contained 'recpatcha/api' in all of them so I used that there. In your case it'd probably be: 'captcha/?n=register&amp;t=' but you can use whatever you want.
imageLocation is a reference to a String where the image link location will be stored after the function has completed.
foundCaptchaImage is a reference to a Boolean where a value which tells whether the function suceeded or not which will be stored after the function has completed.

Why this code is different is because it reads the image links dynamically from what is being seen on the document. I'm still trying to find a way to directly convert the HTMLElement to an Image without having to download the image from the 'src' value.

EDIT - Found a way, code updated. This will convert the image element seen on screen DIRECTLY ensuring that the image matches the one seen and not something that is different. Spent ages looking for methods and found one example in managed C++ but it was pretty easy to convert. I've split the code into two parts so the HTMLElementToImage function can be reused for you guys. Just make sure the element is actually an image otherwise it'd screw up. You can use it like this and it will return the Image:
[highlight=vb.net]Dim someLogo As Image = HTMLElementToImage(WebBrowser1.Document.GetElement ByID("some-image"))[/highlight]

If you use this code, please give credits to me and ildjarn. I know this uses unsafe code @Jason so don't rage at me.
For Each imgElem As HtmlElement In WebBrowser1.Document.Images

That should be: For Each imgElem As HtmlElement In wb.Document.Images

Sorry for double post btw.
Release yo COM objects
[highlight=vb.net]
Private Sub releaseCOM(ByVal comObject As Object)
Try
comObject = Nothing
System****ntime.InteropServices.Marshal.ReleaseCom Object(comObject)
Catch ex As Exception
Finally
GC.Collect()
End Try
End Sub
[/highlight]
Posts 1–15 of 15 · Page 1 of 1

Post a Reply

Tags for this Thread

None

Need help?