25验证码无JS加密的滑块验证码

This commit is contained in:
luzhisheng 2023-05-30 01:45:45 +08:00
parent 009c0db85a
commit 267ab118ae
17 changed files with 85 additions and 81 deletions

View File

@ -0,0 +1,19 @@
# 知识点: 2张图片对比目标检测
## 解题思路一
比较两张图片是否相似,如果相似并返回缺口位置
![请求](./img/1.jpg)
对比
![请求](./img/2.png)
很容易就可以得到缺口坐标
## 解题思路二
目标检测yolov5框架
https://github.com/luzhisheng/js_reverse/tree/master/ayf_ocr/08%E6%95%B0%E6%8D%AE%E6%A0%87%E6%B3%A8-VOC%E6%95%B0%E6%8D%AE%E9%9B%86-%E7%9B%AE%E6%A0%87%E6%A3%80%E6%B5%8B%E6%A1%86%E6%9E%B6

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

@ -1,82 +1,82 @@
from 滑动验证码 import disparity
import requests
import base64
from PIL import Image
import os
import numpy as np
def challenge25_check_verify(distant):
url = "https://www.python-spider.com/api/challenge25CheckVerify"
payload = f"distant={distant}"
headers = {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
'cookie': 'sessionid=y3o4ap05sxbaa9oujc6yr63wsgydyd7x'
"accept": "application/json, text/javascript, */*; q=0.01",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)"
" Chrome/94.0.4606.71 Safari/537.36",
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"origin": "https://www.python-spider.com",
"referer": "https://www.python-spider.com/api/challenge25",
"x-requested-with": "XMLHttpRequest",
"cookie": "sessionid=dxebgqqn0x78r21nk6w19umv3je6pb0n;"
}
response = requests.request("POST", url, headers=headers, data=payload)
return response.json()
ses = requests.session()
def code_value():
url = "https://www.python-spider.com/api/challenge25verify"
payload = {}
headers = {
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,'
'*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
'cookie': 'sessionid=y3o4ap05sxbaa9oujc6yr63wsgydyd7x;',
'sec-ch-ua': '"Chromium";v="112", "Google Chrome";v="112", "Not:A-Brand";v="99"',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)'
' Chrome/112.0.0.0 Safari/537.36'
}
response = requests.request("GET", url, headers=headers, data=payload)
img1 = response.json().get('img1')
img2 = response.json().get('img2')
img1 = base64.urlsafe_b64decode(img1)
img2 = base64.urlsafe_b64decode(img2)
with open('img/background.png', 'wb') as f:
f.write(img1)
with open('img/target.png', 'wb') as f:
f.write(img2)
coordinate = disparity()
distant = coordinate.get('target')[0]
res = challenge25_check_verify(distant)
print(res)
rate = res.get('rate')
return rate
def get_slider_offset_method(ori_path, cut_pic_path):
"""比较两张图片是否相似,如果相似并返回缺口位置"""
pic_img = Image.open(ori_path)
cut_img = Image.open(cut_pic_path)
array1 = np.array(pic_img)
array2 = np.array(cut_img)
height, width, _ = array1.shape
threshold = 40
if np.sum(array1 == array2) > 80000: # 判断两张图片相似
for x in range(10, width - 10): # 从左往右
for y in range(5, height - 10): # 从上往下
pixel1 = pic_img.load()[x, y]
pixel2 = cut_img.load()[x, y]
if abs(pixel1[0] - pixel2[0]) < threshold and abs(pixel1[1] - pixel2[1]) < threshold and abs(
pixel1[2] - pixel2[2]) < threshold:
continue
else:
return x
def challenge25(page):
if page != 1:
rate = code_value()
if rate != '100.00%':
return False
def request_img():
url = f"https://www.python-spider.com/api/challenge25verify"
res = ses.get(url, headers=headers, timeout=10)
with open(r"./img1.jpg", "wb") as f:
f.write(base64.b64decode(res.json()["img1"]))
for item in os.listdir("./img_yuan"):
ori_path = os.path.join(os.path.abspath("./img_yuan"), item)
offset = get_slider_offset_method(ori_path, "./img1.jpg")
if offset:
form_data = {"distant": offset}
res = ses.post("https://www.python-spider.com/api/challenge25CheckVerify", data=form_data, headers=headers,
timeout=10)
print("滑块识别率:", offset, res.text)
if res.json()["success"]:
return True
url = "https://www.python-spider.com/api/challenge25"
payload = f"page={page}"
headers = {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
'cookie': 'sessionid=y3o4ap05sxbaa9oujc6yr63wsgydyd7x;'
}
response = requests.request("POST", url, headers=headers, data=payload)
return response.json()
def loop_page(page):
count = 0
if page > 1:
if not request_img():
return
form_data = {"page": str(page)}
res = ses.post("https://www.python-spider.com/api/challenge25", data=form_data, headers=headers, timeout=10)
print(res.status_code, res.text)
for row in res.json()['data']:
count += int(row['value'].strip())
return count
def run():
data_num = 0
page = 1
while True:
res_dict = challenge25(page)
if not res_dict:
print(f"验证码没有通过-{page}")
continue
else:
print(f"验证码通过{res_dict}-{page}")
data_list = res_dict.get('data')
for data in data_list:
data_num += int(data.get('value'))
print(data_num)
page += 1
if page == 101:
s = 0
for page in range(1, 101):
s_p = loop_page(page)
if not isinstance(s_p, int):
break
s += s_p
print(s)
if __name__ == '__main__':
run()

View File

@ -1,15 +0,0 @@
import ddddocr
def disparity():
slide = ddddocr.DdddOcr(det=False, ocr=False)
with open('./img/target.png', 'rb') as f:
target_bytes = f.read()
with open('./img/background.png', 'rb') as f:
background_bytes = f.read()
coordinate = slide.slide_match(target_bytes, background_bytes, simple_target=True)
return coordinate
if __name__ == '__main__':
print(disparity())