本文将介绍如何使用Ada语言结合Selenium和OpenCV库来实现对极验滑动验证码的自动破解。整个过程包括模拟点击、获取验证码图片、识别缺口位置、计算滑动轨迹以及模拟滑块拖动。
环境准备
首先需要安装Ada、Python、Selenium和OpenCV库:
bash
安装Ada
sudo apt-get install gnat
安装Python依赖
pip install selenium opencv-python
实现步骤
初始化
ada
with Ada.Text_IO; use Ada.Text_IO;
with GNAT.OS_Lib; use GNAT.OS_Lib;
procedure Geetest_Crack is
package Python is new Ada.Text_IO.C_Streams;
Python_Process : GNAT.OS_Lib.FD;
procedure Run_Python_Code is
use Python;
begin
Put_Line ("Initializing Python Script...");
Python_Process := Python.Start_Process ("python3", "");
if Python_Process = -1 then
Put_Line ("Error: Failed to start Python interpreter.");
return;
end if;
declare
-- Python code as a string
Python_Code : constant String :=
"from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
import cv2
import numpy as np
import time
class GeetestCrack:
def init(self):
self.url = 'https://www.geetest.com/type/'
self.browser = webdriver.Chrome()
self.wait = WebDriverWait(self.browser, 10)
def open(self):
self.browser.get(self.url)
def close(self):
self.browser.quit()
def change_to_slide(self):
huadong = self.wait.until(
lambda driver: driver.find_element(By.CSS_SELECTOR, '.products-content ul > li:nth-child(2)')
)
return huadong
def get_geetest_button(self):
button = self.wait.until(
lambda driver: driver.find_element(By.CSS_SELECTOR, '.geetest_radar_tip')
)
return button
def wait_pic(self):
self.wait.until(
lambda driver: driver.find_element(By.CSS_SELECTOR, '.geetest_popup_wrap')
)
def get_screenshot(self):
screenshot = self.browser.get_screenshot_as_png()
screenshot = np.frombuffer(screenshot, dtype=np.uint8)
screenshot = cv2.imdecode(screenshot, cv2.IMREAD_COLOR)
return screenshot
def get_position(self):
img = self.wait.until(
lambda driver: driver.find_element(By.CLASS_NAME, 'geetest_canvas_img')
)
time.sleep(2)
location = img.location
size = img.size
top, bottom = location['y'], location['y'] + size['height']
left, right = location['x'], location['x'] + size['width']
return top, bottom, left, right
def get_slider(self):
slider = self.wait.until(
lambda driver: driver.find_element(By.CLASS_NAME, 'geetest_slider_button')
)
return slider
def get_geetest_image(self, name='captcha.png'):
top, bottom, left, right = self.get_position()
screenshot = self.get_screenshot()
captcha = screenshot[top:bottom, left:right]
cv2.imwrite(name, captcha)
return captcha
def delete_style(self):
js = 'document.querySelectorAll(""canvas"")[2].style=""'
self.browser.execute_script(js)
def is_pixel_equal(self, img1, img2, x, y):
threshold = 60
pix1 = img1[y, x]
pix2 = img2[y, x]
if all(abs(pix1 - pix2) < threshold):
return True
else:
return False
def get_gap(self, img1, img2):
left = 60
for i in range(left, img1.shape[1]):
for j in range(img1.shape[0]):
if not self.is_pixel_equal(img1, img2, i, j):
return i
return left
def get_track(self, distance):
track = []
current = 0
mid = distance * 3 / 5
t = 0.2
v = 0
distance += 14
while current < distance:
if current < mid:
a = 2
else:
a = -1.5
v0 = v
v = v0 + a * t
move = v0 * t + 0.5 * a * t * t
current += move
track.append(round(move))
return track
def shake_mouse(self):
ActionChains(self.browser).move_by_offset(-3, 0).perform()
ActionChains(self.browser).move_by_offset(2, 0).perform()
def move_to_gap(self, slider, tracks):
back_tracks = [-1, -1, -2, -2, -3, -2, -2, -1, -1]
ActionChains(self.browser).click_and_hold(slider).perform()
for x in tracks:
ActionChains(self.browser).move_by_offset(x, 0).perform()
for x in back_tracks:
ActionChains(self.browser).move_by_offset(x, 0).perform()
self.shake_mouse()
time.sleep(0.5)
ActionChains(self.browser).release().perform()
def crack(self):
try:
self.open()
self.change_to_slide().click()
self.get_geetest_button().click()
self.wait_pic()
slider = self.get_slider()
image1 = self.get_geetest_image('captcha1.png')
self.delete_style()
image2 = self.get_geetest_image('captcha2.png')
gap = self.get_gap(image1, image2)
track = self.get_track(gap - 6)
self.move_to_gap(slider, track)
success = self.wait.until(
lambda driver: driver.find_element(By.CLASS_NAME, 'geetest_success_radar_tip_content').text == '验证成功'
)
print(success)
time.sleep(5)
self.close()
except:
print('Failed-Retry')
self.crack()
geetest = GeetestCrack()
geetest.crack()
";
begin
-- Write Python code to the Python interpreter
Python.Put (Python_Process, Python_Code);
Python.Flush (Python_Process);
end;
Put_Line ("Python script executed successfully.");更多内容联系1436423940
end Run_Python_Code;
begin
Run_Python_Code;
end Geetest_Crack;
运行代码更多内容访问ttocr.com或联系1436423940
在终端中运行以下命令来启动破解程序:
bash
gnatmake geetest_crack.adb -o geetest_crack
./geetest_crack