How to save captcha as image (Python)

Captcha 1

darkcyber
7 years ago

0

I have a problem to save captcha as png.
Here is my code so far

import requests  
url_login = "https://www.hackthis.co.uk/?login"  
r_login = requests.post(url_login, {'username': 'darkcyber', 'password': 'secr3tp4s5'})  
print r_login.status_code  
if "Invalid login details" in r_login.text:  
        print "Failed to login"  
else:  
        print "Login success"  
url_captcha = "https://www.hackthis.co.uk/levels/extras/captcha1.php"  
r_captcha = requests.get(url_captcha)  
#print r_captcha.status_code << 401 instead 200  
#whats next?  
6replies
4voices
795views
1image
tl0tr
7 years ago

0

I don’t think it is this simple to get the captcha as an image. Python is complicated.

Maybe someone with more knowledge about Python can provide more information.

darkcyber
7 years ago

0

I hope someone help till save captcha as image, and the rest I will do.


0

You need a session where your login cookies will be stored

```sess = requests.Session()
sess.post(“https://www.hackthis.co.uk/?login”, data={“username”: “abc”, “password”: “xyz”})
cap = sess.get(“https://www.hackthis.co.uk/levels/extras/captcha1.php”)
cap = Image.open(StringIO(cap.content))

StringIO cuz argument 1 must be encoded string without null bytes, not string!

cap.save(“E:/cap.png”)```

darkcyber
7 years ago | edited 7 years ago

0

@agon
Thanks for the advice anyway.

@tl0tr Deleted

So far my code convert image to text with the basic OCR but the results seems not good, 70 attempt failed.

Any advice?

tl0tr
7 years ago

0

@darkcyber : Remove your code before the entire thread gets deleted.


0

@darkcyber look at my attempts

Image[/Spoiler]

So, keep calm and try captcha!

I was using tesseract, but yup the default OCR data didn’t help
<!- This is really a spoiler ->
[Spoiler]The font is unispace (bold)

-!>
So I trained my own tessdata (Tesseract OCR Data)
Level Complete :)

Reply has been removed
You must be logged in to reply to this discussion. Login
1 of 7

This site only uses cookies that are essential for the functionality of this website. Cookies are not used for tracking or marketing purposes.

By using our site, you acknowledge that you have read and understand our Privacy Policy, and Terms of Service.

Dismiss