首页 > 其他分享 >使用Lua语言破解滑块验证码的完整流程解析

使用Lua语言破解滑块验证码的完整流程解析

时间:2024-10-12 16:03:07浏览次数:1  
标签:distance bg end 滑块 track image 验证码 Lua local

本文将使用 Lua 语言来破解滑块验证码,带领大家一步步实现验证码破解,包括获取图片、计算滑块移动距离、生成滑动轨迹等。

  1. 下载验证码图片
    首先,我们要获取滑块的前景图片和背景图片。使用 Lua 中的 socket.http 来进行 HTTP 请求并下载图片。

lua

local http = require("socket.http")
local ltn12 = require("ltn12")

function download_image(url, file)
local response_body = {}
local res, code = http.request{
url = url,
sink = ltn12.sink.table(response_body)
}

if code == 200 then
    local file_handler = io.open(file, "wb")
    file_handler:write(table.concat(response_body))
    file_handler:close()
    print("Downloaded: " .. file)
else
    print("Failed to download image. Status code: " .. code)
end

end

download_image("https://captcha.com/bg.png", "background.png")
download_image("https://captcha.com/fg.png", "foreground.png")
2. 计算滑块移动距离
接下来,我们需要对比前景图和背景图来确定滑块的移动距离。Lua 的 image 库可以帮助我们加载图片并进行对比。

lua

local image = require("image")

function calculate_distance(bg_path, fg_path)
local bg_img = image.load(bg_path)
local fg_img = image.load(fg_path)

for x = 1, bg_img.width do
    for y = 1, bg_img.height do
        local bg_pixel = bg_img:get_pixel(x, y)
        local fg_pixel = fg_img:get_pixel(x, y)
        if bg_pixel ~= fg_pixel then
            print("Slide distance: " .. x)
            return x
        end
    end
end

print("No difference found between images.")

end

local distance = calculate_distance("background.png", "foreground.png")
3. 生成滑动轨迹
生成滑动轨迹是破解滑块验证码的关键步骤之一,目的是让服务器相信我们模拟了人类的行为。轨迹将包含滑动的每一帧的坐标和时间间隔。

lua

function generate_track(distance)
local track = {}
local current_position = 0
local random_delay = function() return math.random(10, 30) end

while current_position < distance do
    local move_step = math.random(1, 3)
    current_position = current_position + move_step
    if current_position > distance then
        current_position = distance
    end
    table.insert(track, {current_position, 0, random_delay()})
end

return track

end

local track = generate_track(distance)
4. 发送验证请求
在最后一步,我们将生成的滑动轨迹发送到服务器,进行验证。在 Lua 中,我们可以继续使用 socket.http 来发送 HTTP 请求。

lua

function send_verification(distance, track)
local track_data = "["
for i, step in ipairs(track) do
track_data = track_data .. string.format("[%d, %d, %d]", step[1], step[2], step[3])
if i < #track then
track_data = track_data .. ","
end
end
track_data = track_data .. "]"

local body = string.format("distance=%d&track=%s", distance, track_data)

local response_body = {}
local res, code = http.request{
    url = "https://captcha.com/verify",
    method = "POST",
    headers = {
        ["Content-Type"] = "application/x-www-form-urlencoded",
        ["Content-Length"] = tostring(#body)
    },
    source = ltn12.source.string(body),
    sink = ltn12.sink.table(response_body)
}

print("Verification response: " .. code)

end

send_verification(distance, track)
5. 整合所有步骤
最后,我们将所有的步骤组合在一起,形成一个完整的滑块验证码破解程序。

lua

local http = require("socket.http")
local ltn12 = require("ltn12")
local image = require("image")

-- 下载图片
function download_image(url, file)
local response_body = {}
local res, code = http.request{
url = url,
sink = ltn12.sink.table(response_body)
}

if code == 200 then
    local file_handler = io.open(file, "wb")
    file_handler:write(table.concat(response_body))
    file_handler:close()
    print("Downloaded: " .. file)
else
    print("Failed to download image. Status code: " .. code)
end

end

-- 计算滑动距离
function calculate_distance(bg_path, fg_path)
local bg_img = image.load(bg_path)
local fg_img = image.load(fg_path)

for x = 1, bg_img.width do
    for y = 1, bg_img.height do
        local bg_pixel = bg_img:get_pixel(x, y)
        local fg_pixel = fg_img:get_pixel(x, y)
        if bg_pixel ~= fg_pixel then
            return x
        end
    end
end

print("No difference found between images.")

end

-- 生成滑动轨迹
function generate_track(distance)
local track = {}
local current_position = 0
local random_delay = function() return math.random(10, 30) end

while current_position < distance do
    local move_step = math.random(1, 3)
    current_position = current_position + move_step
    if current_position > distance then
        current_position = distance
    end
    table.insert(track, {current_position, 0, random_delay()})
end

return track

end

-- 发送验证请求
function send_verification(distance, track)
local track_data = "["
for i, step in ipairs(track) do
track_data = track_data .. string.format("[%d, %d, %d]", step[1], step[2], step[3])
if i < #track then
track_data = track_data .. ","
end
end
track_data = track_data .. "]"

local body = string.format("distance=%d&track=%s", distance, track_data)

local response_body = {}
local res, code = http.request{
    url = "https://captcha.com/verify",
    method = "POST",
    headers = {
        ["Content-Type"] = "application/x-www-form-urlencoded",
        ["Content-Length"] = tostring(#body)
    },
    source = ltn12.source.string(body),
    sink = ltn12.sink.table(response_body)
}更多内容联系1436423940

print("Verification response: " .. code)

end

-- 主函数
function main()
-- 1. 下载验证码图片
download_image("https://captcha.com/bg.png", "background.png")
download_image("https://captcha.com/fg.png", "foreground.png")

-- 2. 计算滑动距离
local distance = calculate_distance("background.png", "foreground.png")

-- 3. 生成滑动轨迹
local track = generate_track(distance)

-- 4. 发送验证请求
send_verification(distance, track)

end

main()

标签:distance,bg,end,滑块,track,image,验证码,Lua,local
From: https://www.cnblogs.com/ocr1/p/18460699

相关文章

  • 使用Go语言破解滑块验证码的完整流程
    在本文中,我们将通过Go语言破解滑块验证码,逐步讲解如何计算滑块移动距离、生成轨迹并提交验证请求。下载验证码图片使用Go的net/http库来获取验证码图片,并保存到本地。packagemainimport("fmt""io/ioutil""net/http""os")funcdownloadImage(urlstring,fileP......
  • <免费开题>登录网站验证码的生成与识别系统(django)|全套源码+文章lw+毕业设计+课程设计
    <免费开题>登录网站验证码的生成与识别系统(django)|全套源码+文章lw+毕业设计+课程设计+数据库+ppt摘要近年来随着互联网应用技术的飞速发展,为了确保网站系统平台的安全性,各类网站相继推出了验证码应用技术,通过验证码的应用来帮助缓解暴力破解账户密码、垃圾邮件攻击以及在......
  • lightdb pllua存储过程实测
    根据对pl/lua的相关介绍和一些说明如http://www.pgsql.tech/project_305_10000096,其性能相比plpgsql和plsql快不少,那实际到底如何呢?下面拿demo和一些实际的来对比下。1、lua安装。从https://www.lua.org/download.html下载最新版。因为pllua需要依赖lua.so动态库,所以不......
  • 验证码绕过爆破
    验证码绕过爆破图片验证码绕过方法一、插件xiapao下载地址:https://github.com/smxiazi/NEW_xp_CAPTCHA/releases/tag/4.2需要python3.6的环境来启动sercer.py服务,下载python3.6安装包,选择路径进行安装(不需要配置环境变量),然后再pycharm中打开文件,配置虚拟环境,虚拟环境......
  • 为什么帝国cms验证码一直均显示为“ecms”
    在帝国CMS中,验证码显示为“ecms”的主要原因是因为服务器空间不支持GD库(GraphicsDrawingLibrary)。GD库是PHP的一个扩展库,用于生成图像,如验证码图片。当服务器不支持GD库时,验证码生成功能会受到影响,导致默认显示为“ecms”。解决方案升级服务器环境:确保服务器支持GD库。使用......
  • PbootCms后台登陆不显示验证码
    当使用PbootCMS后台登录时,如果验证码图片不显示,这通常是由于阿里云虚拟主机的配置问题导致的。以下是一些具体的解决步骤:解决方案检查PHP配置修改 php.ini 文件操作步骤1.登录阿里云控制台登录阿里云控制台登录阿里云官网,进入控制台。选择“虚拟主机”。进......
  • 织梦CMS后台登录验证码如何取消?
    如果你想取消织梦CMS后台登录时的验证码,可以通过以下步骤进行操作:1.下载并编辑 inc_safe_config.php 文件下载文件:使用FTP客户端连接到服务器。导航到网站根目录下的 DATA 文件夹。找到 safe/inc_safe_config.php 文件并下载到本地。编辑文件:使用文本编辑......
  • 基于JAVA绘制验证码
    目录概要整体架构流程代码解释Java绘图注意事项:Swing演示效果概要        Java绘图通常指的是在Java应用程序中创建和显示图形、图像和其他视觉元素。        Swing是Java的一个图形用户界面工具包,它提供了一套丰富的组件来构建桌面应用程序,包括......
  • Web入门 ——生成验证码
    <!DOCTYPEhtml><htmllang="zh-CN"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><title>验证码</title>......
  • Spring boot中使用实现Redis Lua计数器
    Springboot中使用实现RedisLua计数器在SpringBoot中使用RedisLua脚本实现计数器,可以通过以下步骤来完成。这个示例将展示如何使用Lua脚本在Redis中安全地增加计数器的值。步骤1:添加依赖首先,确保你的pom.xml文件中包含了SpringDataRedis和Lettuce的依赖:<dependency>......