This is my seventh day of the August Genwen Challenge

preface

Record a practical process of decoding slider verification code using Python+Selenium. Let’s have a good time

The development tools

Python version: 3.6.4

Related modules:

Pillow module;

The selenium module;

Numpy module;

And some modules that come with Python.

Other:

chromedriver

Environment set up

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

Actual combat record

This paper will record the decoding process of the slider verification code used on the member registration page of Spring Airlines. The address is:

https://account.ch.com/NonRegistrations-Regist
Copy the code

Introduction to captcha

A CAPTCHA, or CAPTCHA, is a public Turing test that automatically distinguishes a computer from a human. In other words, a CAPTCHA is a test used to distinguish a human from a computer. Only after passing the CAPTCHA can a current user be considered a human.

Crack the slider verification code

Slider verification code, that is, the user uses the mouse to drag the slider from one location to another location, the server determines whether the current user is human by dragging the slider track. What this article will try to crack is a kind of schema slider captcha:

First, I manually completed a verification of the slider verification code to see which request to send to the server to pass the verification. I clicked on one randomly and found that the request required parameters were as follows:

It’s certainly possible to figure out each parameter, but on a quick thought, it should look something like this:

First, the distance between the slider and the notch is calculated by using image processing technology. The machine is then used to drag the slider to the notch in a manner similar to human behavior to complete the verification.

2.1 Calculate the distance between the slider and the notch

First, we use Selenium to enter the slider verification code interface:

Which is this interface:

So how do you calculate the distance between the slider and the notch?

I’ve seen a lot of people calculate this before:

When the slider verification code interface appears, take a screenshot of the screen (at this time the background image is complete), and then simulate clicking the slide ball to make the slider and the gap appear (at this time the background image is notched). At this time, take a screenshot again, and you can easily find the gap position by comparing the two screenshots.

However, the premise of this scheme is that the sliders and gaps appear only after the sliding ball is clicked, and the complete background image is displayed before clicking. This was possible not too long ago, but the slider captcha version was upgraded a few days ago!! Slider verification code directly shows slider and notch!! Which means I won’t show you the original.

Since preparing to use machine learning, algorithm first do not consider, always have training data first, so I manually refresh a few times, want to study how to obtain the verification code picture, it is not possible to manually save a few hundred. Can refresh, found a great thing, this site slider captcha background image only four!

No need to climb captcha, mark by hand, and train. Why, some may ask?

Because there are only four background pictures!! You can do this by taking a screenshot of the current slider captcha interface, comparing it with the full background image, and finding the gap location to calculate the slider’s distance to the gap (the initial x-coordinate of the slider is fixed).

The above scheme has the following two problems:

(1) How to obtain the complete background image?

Answer: When you complete the verification of the slider verification code, the corresponding background image will still appear. Use the screenshot software to capture the image.

The results are as follows:

(2) How to find the complete background image corresponding to the current slider verification code?

Answer: because there are only four picture, it is not necessary to use some of the image matching algorithm on the tall, look at the four vertices of the left upper corner of the image pixels, the R values are: 255217227100, apparently, by comparing the vertices of the left upper corner of the background pixels can find the current slider authentication code corresponding to the complete background, code implementation is as follows:

Notice, because the screenshot looks like this:

Therefore, the coordinates at the top left vertex of the captcha background map will change with the computer and the screenshot method. (Specifically, the location coordinates of the captcha background map taken by Selenium and the screenshot software on my computer are different and need to be determined by the drawing software.)

So if you can't use my code to complete the slider verification, please modify (787, 282) and (787, 293) to fit your own computer's actual situation.

Next, we can calculate the distance between the slider and the notch!

First intercept the current slider verification code interface, the code implementation is as follows:

Here, we first move the slider to the right end and then take the screenshot, otherwise the slider will affect the pixel comparison between the current captchas interface and the corresponding full background image (i.e. the larger pixel difference found at the first time is on the slider rather than on the expected gap).

Then compare the pixel value with the corresponding complete background image to find the notch position, and then calculate the distance between the slider and the notch (because the abscissa of the initial position of the slider is fixed) :

2.2 Drag the slider to the notch position

Next, we need to verify this by using the machine to drag the slider to the notch in a manner similar to human behavior.

Generally speaking, the trajectory of the manual drag slider looks like this:

Namely: first quickly drag to the right, fast to the gap, and then slow down. So how do you generate trajectories like this?

I came up with two solutions:

Scheme one is to simulate the track of dragging slider according to acceleration and deceleration in physics, and the code is as follows:

The second scheme is to directly construct some functions to simulate the track of dragging the slider, and the function code is as follows:

Finally, use Selenium to move the slider to the gap according to the set trajectory:

This is the end of the article, thanks for watching Python24 mini-games series, next article will share Python+Selenium decoding B station slider captchas

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

⑥ Two days of Python crawler boot camp live access

All done~ See personal home page for complete source code.

Review past

Simple implementation of entry level steganography