我对网站开发的反思,wordpress相册点击弹出框,做网站基本,wordpress文章更新插件过某开源滑动验证码
今天早上我有一点空闲时间#xff0c;想着回顾一下前几天在某查询网站遇到的滑动验证码#xff0c;以免时间久了忘记了。那个网站可能使用的是较早版本的开源滑块验证码系统tianai-captcha#xff0c;但我不确定是否正确。
整体思路#xff1a;
获取…过某开源滑动验证码
今天早上我有一点空闲时间想着回顾一下前几天在某查询网站遇到的滑动验证码以免时间久了忘记了。那个网站可能使用的是较早版本的开源滑块验证码系统tianai-captcha但我不确定是否正确。
整体思路
获取背景大图和模板小图用ddddocr识别缺口位置模拟人滑动从通过了验证的载荷来看主要是模拟形成这个trackList。 基本步骤
1、获取背景图与模板小图这个容易试着滑动一下从图中接口可以得到backgroundImage和templateImage。 将获取的图片base64解码保存到本地,保存图片时要注意“固定尺寸”与“渲染大小”之间的关系。
# 将base64编码的图转换为图片def decode_base64_to_image(base64_string, output_filename, target_sizeNone):# 分割base64字符串去掉前缀如果有的话base64_data base64_string.split(,)[1] if , in base64_string else base64_string# 解码base64字符串image_data base64.b64decode(base64_data)# 使用BytesIO将字节数据转为图像image Image.open(BytesIO(image_data))# 如果指定了尺寸调整图像大小if target_size:image image.resize(target_size, Image.LANCZOS)# 保存图像到本地文件image.save(output_filename)def get_image_id():url http://xxx.xxx.xxx/x_xxxx/genparams {type: SLIDER}data ^^{^}^.encode(unicode_escape)response session.post(url, headersheaders, cookiescookies, paramsparams, datadata, verifyFalse)json_data json.loads(response.text)backgroundImage json_data[captcha][backgroundImage].split(,)[1]templateImage json_data[captcha][templateImage].split(,)[1]# # 保存图片到本地文件decode_base64_to_image(backgroundImage, backgroundImage.jpg, (300, 180)) #注意这里的尺寸是原图的 1/2decode_base64_to_image(templateImage, templateImage.png, (55, 180))return json_data[id]2、用ddddocr识别缺口位置
# 识别偏移量
def get_slider_offset_ddddocr(target, background):det ddddocr.DdddOcr(detFalse, ocrFalse, show_adFalse)with open(target, rb) as f:target_bytes f.read()with open(background, rb) as f:background_bytes f.read()res det.slide_match(target_bytes, background_bytes)return res3、得到缺口位置后模拟滑动(此乃核心部分),程序中随机数区间可以自行调整以便获得更高的通过率。
def generate_trajectory(x):trajectory []current_x 0current_y 0current_time random.randint(824, 3065)# start with down eventtrajectory.append({x: current_x, y: current_y, type: down, t: current_time})# add move eventswhile current_x x:current_time random.randint(10, 30)move_x random.randint(1, int(max(1, (x - current_x) / 20))) # adjust move speed based on distance leftmove_y random.randint(-2, 2) # random minor variance in ycurrent_x move_xcurrent_y move_y# ensure current_x does not exceed target xif current_x x:current_x xtrajectory.append({x: current_x, y: current_y, type: move, t: current_time})# end with up eventcurrent_time random.randint(100, 1000) # randomly determine time taken to lift fingertrajectory.append({x: current_x, y: current_y, type: up, t: current_time})return trajectory4、组装数据提交我就按照载荷数据的形式组装的没有去校验各个参数能否更简单。 def generate_data(trajectory, id):import datetime# 当前时间为滑动开始时间start_time datetime.datetime.now()# 将轨迹时间转换为合适的时间戳并取毫秒部分updated_trajectory []for event in trajectory:# 计算事件时间event_time start_time datetime.timedelta(millisecondsevent[t])# 获取毫秒部分的最后三位数字转为三位字符串milli_str (000 str(event_time.microsecond // 1000))[-3:]updated_event {x: event[x],y: event[y],type: event[type],t: milli_str # 只保留时间的最后三位}updated_trajectory.append(updated_event)# 设置滑动结束时间end_time start_time datetime.timedelta(millisecondstrajectory[-1][t])# 将时间格式化start_sliding_time start_time.isoformat() Zend_sliding_time end_time.isoformat() Z# 提交的数据对象from datetime import datetimedata {id: id,data: {bgImageWidth: 300,bgImageHeight: 180,startSlidingTime: datetime.fromisoformat(start_sliding_time.replace(Z, 00:00)).strftime(%Y-%m-%dT%H:%M:%S.%f)[:-3] Z,endSlidingTime: datetime.fromisoformat(end_sliding_time.replace(Z, 00:00)).strftime(%Y-%m-%dT%H:%M:%S.%f)[:-3] Z,trackList: updated_trajectory}}return json.dumps(data, separators(,, :))5、如果通过校验返回如下状态可以检测中的某一个Key,如果没有通过重新获取。
{code:200,data:{id:get_image_id函数所获取的id},msg:OK,success:true}整个程序通过率90%吧。在生成轨迹时当时我滑动了大约近二十组数据将它提供给gpt-4o,让它进行了分析。 以下轨迹分析的程序你可以根据它分析的结果来确定generate_trajectory中随机数。以下是分析程序。 File : 轨迹
Author : Bobo
Blog : https://blog.csdn.net/chinagaobo
Note : This code is for learning and communication purposes onlyimport jsonguiji1 [] #校验通过后的轨迹列表
guiji2 []
guiji3 []
guiji4 []
...def analyze_trajectories(trajectories):for i, trajectory in enumerate(trajectories):print(fAnalysis of track {i 1}:)for j in range(1, len(trajectory)):dx trajectory[j][x] - trajectory[j - 1][x]dy trajectory[j][y] - trajectory[j - 1][y]dt trajectory[j][t] - trajectory[j - 1][t]print(fStep {j} - dx: {dx}, dy: {dy}, dt: {dt})print()# 将四组轨迹放入列表
trajectories [guiji1, guiji2, guiji3, guiji4]# 分析轨迹
analyze_trajectories(trajectories)整篇文章给出了解决此种滑动验证的思路及代码如果您有好的思路还请不吝赐教。