极验3.0滑验证码破解:selenium+计算滑动缺口坐标算法=80%正确率

极验3.0滑验证码破解:selenium+计算滑动缺⼝坐标算法=80%正确率
极滑2.0的破解思路:
 ⼀. 模拟点击验证按钮
  直接⽤Selenium模拟点击按钮
 ⼆. 识别滑动缺⼝的位置
  2.0旧版本: 利⽤原图和缺⼝图对⽐检测⽅式来识别缺⼝的位置,通过遍历俩张图⽚,出相同位置像素RGB差距超过此阀值的像素点,那么此像素点的位置就是缺⼝的位置。
  3.0新版本: 通过截屏获取带有缺⼝的验证码图⽚,通过验证码图⽚的像素进⾏识别,凹槽位置的RGB三个⾊素基本都是⼩于150,通过遍历x的轴,如果x轴从左到右边如果有连续x_max/8.6个像素中的RGB中的三个⾊素都是⼩于150,那个该x就是缺⼝的左边的距离,下⾯将详细讲解这个。
 三. 模拟拖动滑块
  模拟⼈的移动轨迹通过验证,⼀般是先加速后减速。
破解的重要点就是:识别滑动缺⼝的位置。
测试案例(凹槽像素x轴为80, y轴在45±15):
额外知识:全⿊的RGB为(0,0,0), 全⽩的RGB(255,255,255)
我们通过分析像素的R、G、B来得出规律,我们打印⼀下坐标轴y=50,x轴上个点像素的RGB:
x  y    像素R、G、B
自动点火器
72 50 (126, 126, 125)
73 50 (219, 219, 219)
73 50 (219, 219, 219)
77 50 (165, 166, 164)
81 50 (80, 80, 80)
82 50 (76, 76, 75)
83 50 (58, 58, 56)
84 50 (101, 102, 100)
扁头螺丝85 50 (124, 125, 122)
86 50 (118, 119, 116)
87 50 (105, 107, 103)
88 50 (96, 96, 94)
89 50 (82, 83, 81)
90 50 (77, 77, 77)
91 50 (77, 77, 77)
92 50 (83, 83, 83)
93 50 (104, 104, 104)
94 50 (135, 135, 135)
95 50 (128, 128, 128)
96 50 (85, 85, 85)
97 50 (84, 84, 84)
98 50 (139, 139, 138)
99 50 (139, 139, 137)
100 50 (139, 139, 139)
101 50 (123, 123, 123)
102 50 (83, 83, 83)
103 50 (91, 91, 91)
104 50 (141, 141, 141)
105 50 (140, 140, 140)
106 50 (135, 135, 135)
107 50 (98, 98, 98)
108 50 (73, 73, 73)
109 50 (119, 119, 119)
110 50 (140, 140, 140)
111 50 (127, 127, 127)
112 50 (85, 85, 85)
113 50 (88, 88, 88)
114 50 (137, 137, 137)
115 50 (135, 135, 135)
116 50 (133, 133, 133)
117 50 (132, 132, 132)
118 50 (129, 129, 129)
119 50 (123, 123, 123)
120 50 (87, 87, 87)
121 50 (57, 57, 57)
122 50 (145, 145, 145)
123 50 (234, 234, 234)
可以再尝试其他y轴的来进⾏分析,我们会发现,凹槽位置的像素点的R、G、B都是⼩于150,⽽且基本会连续40个x轴上的像素的R、G、B都是⼩于150,电脑屏幕⼤⼩不同,连续个数不同,基本都是连续image.size[0]/6.45个像素, 这样⼦我们就可以从这个思路写算法来出从凹槽的x坐标。
算法: 向右边连续有30到50个像素的R、G、B都是⼩于150,这就是我们所想要的数据,也就是凹槽缺⼝的左位置:
def get_gap(image):
"""
获取缺⼝偏移量
:param image: 带缺⼝图⽚
:
return:
"""
# left_list保存所有符合条件的x轴坐标
left_list =[]
# 我们需要获取的是凹槽的x轴坐标,就不需要遍历所有y轴,遍历⼏个等分点就⾏
for i in[10* i for i in range(1,int(image.size[1]/11)]:
# x轴从x为image.size[0]/5.16的像素点开始遍历,因为凹槽不会在x轴为50以内
for j in range(image.size[0]/5.16, image.size[0]-int(image.size[0]/8.6)):
if is_pixel_equal(image, j, i, left_list):
break
return left_list
def is_pixel_equal(image, x, y, left_list):
"""
判断两个像素是否相同
:param image: 图⽚
:param x: 位置x
:param y: 位置y
:return: 像素是否相同
"""
# 取两个图⽚的像素点
pixel1 = image.load()[x, y]
threshold =150
# count记录⼀次向右有多少个像素点R、G、B都是⼩于150的
count =0
# 如果该点的R、G、B都⼩于150,就开始向右遍历,记录向右有多少个像素点R、G、B都是⼩于150的
if pixel1[0]< threshold and pixel1[1]< threshold and pixel1[2]< threshold:
for i in range(x +1, image.size[0]):
piexl = image.load()[i, y]
if piexl[0]< threshold and piexl[1]< threshold and piexl[2]< threshold:
count +=1
else:
break
if int(image.size[0]/8.6)< count <int(image.size[0]/4.3):
left_list.append((x, count))
return True
else:
return False
if __name__ =='__main__':
# 这⾥的测试图⽚,需要读者⾃⾏更改
image = Image.open("captcha1.png")
image = vert("RGB")
left_list = get_gap(image)
print(left_list)
结果为:
[(80, 43), (76, 45), (80, 42), (80, 41)]
其中(x, z)中的x为凹槽左侧的位置,z是count,就是从该x点坐标起有多少连续像素点的R、G、B都是⼩于150的,因为我们遍历y轴,所有我们的得到⼏个值,其中,z值最接近40的,结果最符合。
我们可以⽤这个代码进⾏列表的排序,越接近40的越在前⾯:
left_list = sorted(left_list, key=lambd x: abs(x[1]-40))
结果变为:
[(80, 41), (80, 42), (80, 43), (76, 45)]
这⾥我们就去列表第⼀个元素中的x轴,这个x就是凹槽的左侧的x轴的下标,得到这个值,下⾯的内容就容易办了,我就直接上完整代码了喔,有什么不懂的可以留⾔给我
import time
from io import BytesIO
from selenium import webdriver
from selenium.webdriver import ActionChains
人造板热压机
自锁螺钉from selenium.webdrivermon.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from PIL import Image
EMAIL ='cqc@cuiqingcai'
PASSWORD ='123456'
BORDER_1 =7
BORDER_2 =12
class CrackGeetest(object):
def__init__(self):
self.url ='st/login'
self.browser = webdriver.Chrome()
self.browser.maximize_window()
self.wait = WebDriverWait(self.browser,5)
self.password = PASSWORD
self.success =False
<_num =2冰棍机
self.flesh_num =1
def__del__(self):
self.browser.close()
# 获取初始验证按钮
def get_geetest_button(self):
"""
获取初始验证按钮
:return:
"""
button = self.wait.until(EC.element_to_be_clickable((By.CLASS_NAME,'geetest_radar_tip')))
return button
# 获取截图中验证码的上下左右的位置
def get_position(self):
"""
获取验证码位置
:return: 验证码位置元组
"""
img = self.wait.until(EC.presence_of_element_located((By.CLASS_NAME,'geetest_canvas_img')))
time.sleep(0.5)
location = img.location
size = img.size
top, bottom, left, right = location['y'], location['y']+ size['height'], location['x'], location['x']+ size[
'width']
return top, bottom, left, right
# 获取⽹页截图
def get_screenshot(self):
"""
获取⽹页截图
:return: 截图对象
:return: 截图对象
"""
screenshot = _screenshot_as_png()
screenshot = Image.open(BytesIO(screenshot))
return screenshot
# 获取滑块对象
def get_slider(self):
"""
获取滑块
:return: 滑块对象
"""
try:
slider = self.wait.until(EC.element_to_be_clickable((By.CLASS_NAME,'geetest_slider_button'))) except Exception:
return
return slider
# 获取验证码图⽚
def get_geetest_image(self, name='captcha.png'):
"""
获取验证码图⽚
:return: 图⽚对象
"""
top, bottom, left, right = _position()
screenshot = _screenshot()
captcha = p((left, top, right, bottom))
captcha.save(name)
return captcha
# 打开页⾯,输⼊账号与密码
def open(self):
"""
打开⽹页输⼊⽤户名密码
:return: None
"""
(self.url)
time.sleep(0.5)
email = self.browser.find_elements_by_xpath("//i[@class='icon-email']/../../input")[0]
password = self.browser.find_element_by_xpath("//i[@class='icon-password']/../../input")
email.send_ail)
password.send_keys(self.password)
# 根据偏移量获取移动轨迹
@staticmethod
def get_track(distance):
"""
根据偏移量获取移动轨迹
:param distance: 偏移量
:return: 移动轨迹
"""
# 移动轨迹
track =[]
# 当前位移
current =0
# 减速阈值
mid = distance *4/5
# 计算间隔
t =0.2
# 初速度
v =0
while current < distance:
if current < mid:
# 加速度为正2
a =2
else:加油站三次油气回收

本文发布于:2024-09-22 09:54:11,感谢您对本站的认可!

本文链接:https://www.17tex.com/tex/2/260501.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:获取   位置   像素   验证码   遍历   像素点   坐标   结果
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议