破解数美滑块验证码:详细步骤与实现

数美滑块验证码是一种常见的安全验证方式,用于防止自动化脚本和机器人进行恶意操作。本文将详细介绍如何通过抓包获取滑块图片信息、分析加密参数、生成滑动轨迹等步骤,成功破解数美滑块验证码。以下是我们要实现的主要步骤:

抓取滑块图片信息并计算滑动距离
分析加密参数
生成滑动轨迹并进行DES加密
验证破解结果
1. 抓取滑块图片信息并计算滑动距离
首先,进入数美滑块验证码的演示页面,进行抓包操作以获取滑块验证码的前景和背景图片。我们通过requests库从网站获取图片:

python

import requests
from io import BytesIO
import cv2
import numpy as np

def get_images(register_url):
    # 请求注册信息,获取图片URL
    response = requests.post(register_url, json={})
    data = response.json()
    fg_url = data['fg']  # 假设返回JSON包含前景和背景图片URL
    bg_url = data['bg']

    # 获取前景和背景图片
    fg_response = requests.get(fg_url, verify=False)
    bg_response = requests.get(bg_url, verify=False)

    fg_image = BytesIO(fg_response.content)
    bg_image = BytesIO(bg_response.content)

    return fg_image, bg_image
接下来,我们使用图像处理库cv2计算滑块需要滑动的距离:

python

def get_distance(fg, bg):
    target = cv2.imdecode(np.asarray(bytearray(fg.read()), dtype=np.uint8), 0)
    template = cv2.imdecode(np.asarray(bytearray(bg.read()), dtype=np.uint8), 0)
    result = cv2.matchTemplate(target, template, cv2.TM_CCORR_NORMED)
    _, distance = np.unravel_index(result.argmax(), result.shape)
    return distance
2. 分析加密参数
在滑动滑块的过程中,我们需要分析加密参数。抓包查看请求信息,可以看到有一个fverify的验证信息。如果正确的话,riskLevel返回值为PASS,失败为REJECT。

通过在浏览器中设置断点,我们可以找到参数aw等的生成函数,并确定这些参数的加密方式。使用断点调试后,发现是通过DES加密。

python

import base64
from pyDes import des, ECB

def pad(b):
    block_size = 8
    while len(b) % block_size:
        b += b'\0'
    return b

def get_encrypt_content(message, key, flag):
    des_obj = des(key.encode(), mode=ECB)
    if flag:
        content = pad(str(message).replace(' ', '').encode())
        return base64.b64encode(des_obj.encrypt(content)).decode('utf-8')
    else:
        return des_obj.decrypt(base64.b64decode(message)).decode('utf-8')
3. 生成滑动轨迹并进行DES加密
滑动轨迹可以通过模拟人的滑动行为来生成,包括一些随机的抖动和速度变化。以下是生成滑动轨迹的示例代码:   更多内容访问1436423940

python

import random

def get_random(distance):
    ge = [[0, 0, 0]]
    for i in range(10):
        x = 0
        y = random.randint(-1, 1)
        t = 100 * (i + 1) + random.randint(0, 2)
        ge.append([x, y, t])
    for items in ge[1:-5]:
        items[0] = distance // 2
    for items in ge[-5:-1]:
        items[0] = distance + random.randint(1, 4)
    ge[-1][0] = distance
    return "{}".format(ge).replace(" ", ""), ge[-1][2]
4. 验证破解结果
最后,结合前面的步骤,实现滑块破解。以下是完整的示例代码:

python

import json

register_url = "https://www.ishumei.com/trial/captcha.html"
fg_image, bg_image = get_images(register_url)
distance = get_distance(fg_image, bg_image)
nm, dy = get_random(distance)

# 假设已经获取了必要的key和flag
key = "your_key_here"
flag = True

encrypted_nm = get_encrypt_content(nm, key, flag)
encrypted_dy = get_encrypt_content(dy, key, flag)

verify_data = {
    "nm": encrypted_nm,
    "dy": encrypted_dy,
    "rid": "register_id_here",
    "dl": distance
}

response = requests.post("https://www.ishumei.com/trial/fverify", json=verify_data)
result = response.json()

if result['riskLevel'] == "PASS":
    print("验证成功")
else:
    print("验证失败")

  • 4
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值