Anyway to have web request run Javascript?

simpleonline12

New member
Sep 29, 2009
191
3
0
I am setting my app using web request but I need to call the captcha (which is a javascript). Any way to have the web request run the captcha javascript and download the challenge?
 


I am setting my app using web request but I need to call the captcha (which is a javascript). Any way to have the web request run the captcha javascript and download the challenge?

Pretty sure you can't do this with Javascript as it blocks making those kind of requests to domains that don't match yours for security reasons.

Piggy back it off of a php script, or other server side language.
 
  • Like
Reactions: simpleonline12
yes
g.gif
 
You need an actual javascript engine running. As far as I can tell, WebRequest is a simple way of downloading data over HTTP, it's not a web browser. Your best bet is to work out the requests that are being issued for the captcha, regex / xpath out the data you need, do the requests, solve the image, then add the captcha solution to your POST data (along with any tokens etc).

Rage9, I believe he's creating a bot, not accessing the target from another webpage, so the same origin policy shouldn't matter.
 
for the captcha, regex / xpath out the data you need

This is where I am stuck...the link for the captcha isn't in the source code of the request...the web browser control runs the Javascript and returns the captcha image url after it is ran.

In a simple httpwebrequest you are only going to get the raw source code. The captcha exist but in it's pre-ran state which doens't do me any good because if you run the captcha from the public key you will get an image however it is ran from the Google site and not the website you are trying to create an account for.

The only way that I know to work it to run the Javascript somehow that would give me the url of the actual image (like the web browser) and pop that into a picturebox.

If you know of another way to do this...please do tell.
 
This is where I am stuck...the link for the captcha isn't in the source code of the request...the web browser control runs the Javascript and returns the captcha image url after it is ran.

In a simple httpwebrequest you are only going to get the raw source code. The captcha exist but in it's pre-ran state which doens't do me any good because if you run the captcha from the public key you will get an image however it is ran from the Google site and not the website you are trying to create an account for.

The only way that I know to work it to run the Javascript somehow that would give me the url of the actual image (like the web browser) and pop that into a picturebox.

If you know of another way to do this...please do tell.

Pull up some sort of headers sniffing plugin, like live http headers for firefox. There will be an initial request to the captcha provider like google that passes some sort of site identifier. The returned data will contain an image code (or challenge whatever you want to call it) that you would append to a url to get the image. Then download the image, you may need cookies enabled for this. Then send the answer back to the captcha provider. It's not a super simple process. But you don't need to execute javascript to do it.

That's the basics. From the sounds of it you're trying to break Recaptchas and that process should work. Just break it down in to the process it is, simple web requests.
 
Last edited:
Thanks for your support Rage9.

What would you use as an equivalent to the Live Headers for use with purely http web request?

I'm thinking download the entire set of headers from the site and regex / Xpath the result to get the captcha url to pop into a picture box?

Thanks
 
Thanks for your support Rage9.

What would you use as an equivalent to the Live Headers for use with purely http web request?

Fucking shit man you're making my head hurt. Live Headers or an equivalent is how you start the reverse engineering process. You need to determine what the web requests are, what data is passed, and where you can find it. Your question alone doesn't seem to make any sense.

Do I need to teach you basic scraping theory also? I don't mean to be a prick but it's not exactly a couple of post subject.
 
No your right Rage9. I have a shit load of more stuff to learn before asking these type questions.

I'm thinking maybe I'm jumping the gun a bit and might need to hit the books again to get more knowledge out of it.

Maybe I would hit less road blocks once I'm done. But thanks for taking the time to shed some light on the solutions.
 
This is where I am stuck...the link for the captcha isn't in the source code of the request...the web browser control runs the Javascript and returns the captcha image url after it is ran.

So...you don't see something like this in the source?
Code:
<script type="text/javascript" src="http://api.recaptcha.net/challenge?k=6LfwKQQAAAAAAPFCNozXDIaf8GobTb7LCKQw54EA"></script>

Most of the recaptchas I have come across use that format.

There are some that really do require a javascript engine because the url
for the captcha is buried in 1,000 lines of JS. In those cases, I
automate a real browser.


Bompa
 
I do see the challenge code....do I just regex that out and pop it into a picturebox?

When I try to pop it in to a picturebox just using the Challenge code I get an error of "parameter not found"

I'm just using a simple url to load into a picturebox. This works if I try is with any other "internet picture" but not this particular one.

WebReqPic.Load(TextBox1.Text)

ux8xj.jpg


This is the error I get when I try to load the image code you gave me above

sp7vkn.jpg
 
Last edited:
Is WebReqPic a HttpWebRequest/Webrequest? If it is I don't think it can load an image file, only html files.

I do see the challenge code....do I just regex that out and pop it into a picturebox?

When I try to pop it in to a picturebox just using the Challenge code I get an error of "parameter not found"

I'm just using a simple url to load into a picturebox. This works if I try is with any other "internet picture" but not this particular one.

WebReqPic.Load(TextBox1.Text)

ux8xj.jpg


This is the error I get when I try to load the image code you gave me above

sp7vkn.jpg
 
WebReqPic is the Picturebox.

Yeah I'm trying to load the scr file into a picturebox so the user can solve the captcha and send it back to the website to create a new account for a social bookmarker.

Picturebox.Load("")

This was a slice of code that I found where you can load an img into the picture box via URL.

The only thing that I am having issues with is that the challenge code isn't an image but a src so I'm not to sure on how to load this up into the picturebox.
 
I do see the challenge code....do I just regex that out and pop it into a picturebox?

Follow/load that challenge url

http://api.recaptcha.net/challenge?k=6LfwKQQAAAAAAPFCNozXDIaf8GobTb7LCKQw54EA


You should see this:

Code:
var RecaptchaState = {
    site : '6LfwKQQAAAAAAPFCNozXDIaf8GobTb7LCKQw54EA',
    rtl : false,
    challenge : '03AHJ_VusYeOKuO-S3rJbgfvTXgu1CzlXgs8Qb8H_NwEjuyu2nFuuSkcWR-3CTpSHuFa48r2x7wJcY10Cdpp5F6-IPztQfjzDEYC7h5iPKh5W5H8dS4WbJ0NsUbl_LII_y1zOEDyJKKNSnDnLdoCfpA9EUIO9tckI3Lg',
    is_incorrect : false,
    programming_error : '',
    error_message : '',
    server : 'http://www.google.com/recaptcha/api/',
    lang : 'fil',
    timeout : 1800
};

document.write('<scr'+'ipt type="text/javascript" s'+'rc="' + RecaptchaState.server + 'js/recaptcha.js"></scr'+'ipt>');

The captcha url is made from the value of "server" followed by the
value of "challenge : "

Bompa
 
What's the url you are having trouble with?

And what do you mean by the challenge code is not an image but a src?

WebReqPic is the Picturebox.

Yeah I'm trying to load the scr file into a picturebox so the user can solve the captcha and send it back to the website to create a new account for a social bookmarker.

Picturebox.Load("")

This was a slice of code that I found where you can load an img into the picture box via URL.

The only thing that I am having issues with is that the challenge code isn't an image but a src so I'm not to sure on how to load this up into the picturebox.
 
Hey IMBotz..I'm trying to learn the ropes of how to grab a captcha into a picture box using web request and not a web browser.

The link I gave was just an example site so that I could learn how it was done.

Register at Nidokidos Official Forum

I'm all sorts of confused still..well from what I am getting now I need to parse the html of a site to grab the url of the captcha challenge.

Then I need to pop that challenge url into a webrequest to run the challenge.

From that I would get the information that Bompa pasted....I then would take that challenge string and combine it into the server api string to get the final challenge or captcha...that would be what I need to pop into a picturebox for the user to solve.

Does this sound correct?

Thanks
 
  1. This still doesn't work for me using webrequest. I have a web request setup that will give me the html of a website and placed into a rich textbox. (this part works fine).
Code:
[SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Button1_Click([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Button1.Click
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] postData [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]""
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] tempCookies [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] CookieContainer
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] encoding [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] UTF8Encoding
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] byteData [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Byte[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]() = encoding.GetBytes(postData)
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] postReq [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] HttpWebRequest = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]DirectCast[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](WebRequest.Create(TextBox1.Text), HttpWebRequest)
postReq.Method = [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"POST"
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]postReq.KeepAlive = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]postReq.CookieContainer = tempCookies
postReq.ContentType = [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"application/x-www-form-urlencoded"
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]postReq.Referer = TextBox1.Text
postReq.UserAgent = [/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)"
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]postReq.ContentLength = byteData.Length
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] postreqstream [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Stream = postReq.GetRequestStream()
postreqstream.Write(byteData, 0, byteData.Length)
postreqstream.Close()
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] postresponse [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] HttpWebResponse
postresponse = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]DirectCast[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](postReq.GetResponse(), HttpWebResponse)
tempCookies.Add(postresponse.Cookies)
logincookie = tempCookies
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] postreqreader [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] StreamReader(postresponse.GetResponseStream())
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] thepage [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = postreqreader.ReadToEnd
RichTextBox1.Text = thepage

[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE][/COLOR][/SIZE]

2. From this point I navigate into the html to find the recaptcha challenge.
I then take the recaptcha challenge link that is given to me in the html source code which is this:

http://api.recaptcha.net/challenge?k=6Lc4KcMSAAAAAIrokS2JikdI-x4ApVbh1xV2v_K1
I then exit the application and re-enter it again and this time I am using my challenge link above but rather than displaying the source code I choose to download the file (which is a text file). This part works fine.

When I attempt to combine the server response with the challenge response and put that entire url in the webrequest I get the error below. Here is the url that I put togehter

25tb8ds.jpg


Whenever I tried to just download a file from this link I get this error:

4pwnsl.jpg


This is the full link that I am trying to use.

'http://www.google.com/recaptcha/api/03AHJ_VuscqFJSuB8OQk_xWVpV0bfYX2z4mBpjrog95W2wbPq0QbQ5P9ziMqDkMERaBc80kx-i6WmKV8sZO0wRcGlWW1VlynbrXOwfSHyPh_POPsLkVIWGMEdL2uxheHrF5F5XKyuYe2-L9-3lbDJ0j91IbzAfsrP3sg
This is the challenge that was downloaded

Code:
var RecaptchaState = {
site : '6Lc4KcMSAAAAAIrokS2JikdI-x4ApVbh1xV2v_K1',
rtl : false,
challenge : '03AHJ_VuscqFJSuB8OQk_xWVpV0bfYX2z4mBpjrog95W2wbPq0QbQ5P9ziMqDkMERaBc80kx-i6WmKV8sZO0wRcGlWW1VlynbrXOwfSHyPh_POPsLkVIWGMEdL2uxheHrF5F5XKyuYe2-L9-3lbDJ0j91IbzAfsrP3sg',
is_incorrect : false,
programming_error : '',
error_message : '',
server : 'http://www.google.com/recaptcha/api/',
lang : 'en-US',
timeout : 1800
};
document.write('<scr'+'ipt type="text/javascript" s'+'rc="' + RecaptchaState.server + 'js/recaptcha.js"></scr'+'ipt>');

What the hell am I doing wrong here?

Thanks