This is my ninth day of the August Genwen Challenge


Today we use the HackCaptCHA library, in conjunction with the open source DecryptLogin package, to create a toolkit where captcha can be processed automatically rather than entered manually. Without further ado, let’s begin happily

The development tools

Python version: 3.6.4

Related modules:

Requests module;

Opencv – python module;

Numpy module;

Keras module;

Tensorflow module;

And some modules that come with Python.

Environment set up

Install Python and add it to the environment variables. PIP installs the required related modules.

Project introduction

Let’s start with a brief introduction to the DecryptLogin package that was previously open source. DecryptLogin is a Python third-party package that uses the Requests package to simulate login to various websites.
Copy the code

Project Documents:
Copy the code

With PIP installed, you can easily implement simulated login operations for various websites, such as simulated login zhihu:

from DecryptLogin import login

lg = login.Login()
infos_return, session = lg.zhihu(username='Your Username', password='Your Password')
Copy the code

Infos_return is a dictionary object that records information about the user after login, and session is the session after login. The significance of simulated login is that a lot of site data must be seen when the user is logged in, and many operations must be performed when the user is logged in (for example, daily check-ins, etc.).

The above code looks like this:

In other words, by default, the DecryptLogin library requires the user to manually enter the verification code encountered during login.

Can’t DecryptLogin process the verification code automatically?

The answer is yes, you just need to define a captcha function and pass it as a parameter when logging in.

from PIL import Image
from DecryptLogin import login

Define the captcha recognition function
def crackvcFunc(imagepath) :
    # Open captcha image
    img =
    # Identify captcha images
    result = IdentifyAPI(img)
    # return the recognition result (which is a digital verification code)
    return result

lg = login.Login()
infos_return, session = lg.zhihu(username='Your Username', password='Your Password', crackvcFunc=crackvcFunc)
Copy the code

All of these are explained in detail in the project documentation.

Hackcaptcha: Hackcaptcha: Hackcaptcha: Hackcaptcha: Hackcaptcha: Hackcaptcha
Copy the code

Since the main goal of open Source HackCaptCHA is to solve the DecryptLogin library’s DecryptLogin auto-processing problem, hackCaptCHA currently supports only two types of auto-processing, namely numeric (including English letters) captcha and 12306 click captcha. Of course, new support will be added gradually as the DecryptLogin library is updated. You only need PIP to install the library to start using it (it is recommended to install Keras and the corresponding version of TensorFlow on your computer before installing it) :

pip install hackcaptcha
Copy the code

For digital captcha, HackCaptcha calls Baidu’s text recognition API directly:
Copy the code

Because I looked at it:

Users can call it so many times a day, free of charge, that personal learning and play is sufficient

To be specific, you need to register an account on the website above and create a new app to get the API Key and Secret Key:

Captcha recognition can be achieved by writing a few lines of code:

from hackcaptcha.crackers import WebapisCracker
cracker = WebapisCracker()
infos_return ='CAPTCHA IMAGE PATH', webapi_type='baidu', app_id='AppID', api_key='API Key', secret_key='Secret Key') returns the result in the format: {'is_success': True.'result': 'AFD2'.'error_msg': ' '
Copy the code

For 12306 click verification code, I looked up the online practice, generally is the 12306 verification code to do a picture segmentation:

Then train a picture classifier and a text classifier respectively. So I just used it. Just call it like this:

from hackcaptcha.crackers import AlgorithmsCracker
cracker = AlgorithmsCracker()
infos_return ='CAPTCHA IMAGE PATH', algorithm_type='zt12306', text_model_path='text.h5', object_model_path='object.h5')
Copy the code

The returned result is in the following format:

    'is_success': True.'result': '1,2,5'
Copy the code

Text. h5 and Object. h5 can be downloaded here:
Copy the code

We can see this in conjunction with the DecryptLogin library (note that the following code only works when the DecryptLogin version is 0.1.29 or greater) :

from DecryptLogin import login
from hackcaptcha.crackers import AlgorithmsCracker

Define the captcha recognition function
def crackvcFunc(imagepath) :
    cracker = AlgorithmsCracker()
    infos_return =, algorithm_type='zt12306', text_model_path='text.h5', object_model_path='object.h5')
    return infos_return['result']

lg = login.Login()
infos_return, session = lg.zt12306(username='Username', password='password', crackvcFunc=crackvcFunc)
Copy the code

Operation effect:

It can be found that we no longer need to input their own headlong 12306 verification code, and directly call the trained model for automatic identification input can achieve 12306 simulated login operation ~

This is the end of the article, thank you for watching, Python information security, next article to share Python+Selenium decryption Taobao slider verification code cracking

To thank you readers, I’d like to share some of my recent programming favorites to give back to each and every one of you in the hope that they can help you.

Dry goods mainly include:

① Over 2000 Python ebooks (both mainstream and classic books should be available)

②Python Standard Library (Most Complete Chinese version)

③ project source code (forty or fifty interesting and classic practice projects and source code)

④Python basic introduction, crawler, Web development, big data analysis video (suitable for small white learning)

⑤ A Roadmap for Learning Python

All done~ see personal homepage introduction or private letter for complete source code.

Review past

Using Python+Selenium to crack spring Aviation network slider verification code, information security road

Using Python+Selenium to crack B station slider verification code, information security road

Simple implementation of entry level steganography