bspline interpolated recaptcha evasion with selenium
This commit is contained in:
parent
4ba097060a
commit
4cb94cdd81
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
__pycache__
|
||||
mysql
|
||||
|
|
17
docker-compose.yml
Normal file
17
docker-compose.yml
Normal file
|
@ -0,0 +1,17 @@
|
|||
version: '3.1'
|
||||
|
||||
services:
|
||||
|
||||
test_db:
|
||||
image: mariadb
|
||||
restart: always
|
||||
container_name: testing_db
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: insecure
|
||||
MYSQL_USER: insecure
|
||||
MYSQL_PASSWORD: insecure
|
||||
MYSQL_DATABASE: insecure
|
||||
ports:
|
||||
- 127.0.0.1:3306:3306
|
||||
volumes:
|
||||
- ./mysql:/var/lib/mysql
|
70
main.py
70
main.py
|
@ -8,19 +8,21 @@ import time
|
|||
from threading import Timer, Lock
|
||||
|
||||
import selenium
|
||||
from selenium import webdriver
|
||||
import lxml.etree as etree
|
||||
from cssselect import HTMLTranslator, SelectorError
|
||||
import requests as req
|
||||
from io import StringIO
|
||||
|
||||
import math
|
||||
#import web
|
||||
|
||||
DB_HOST = "127.0.0.1"
|
||||
DB_USER = "dbuser"
|
||||
DB_PASSWD = "dbpasswd"
|
||||
DB_DATABASE = "base"
|
||||
ACCOUNT_USERNAME = "foo"
|
||||
ACCOUNT_PASSWORD = "foo"
|
||||
DB_USER = "insecure"
|
||||
DB_PASSWD = "insecure"
|
||||
DB_DATABASE = "insecure"
|
||||
ACCOUNT_USERNAME = "foooo@google.com"
|
||||
ACCOUNT_PASSWORD = "foorg53"
|
||||
|
||||
|
||||
def getDb():
|
||||
|
@ -49,7 +51,7 @@ def createTable(db, name):
|
|||
(id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
title VARCHAR(255),
|
||||
author VARCHAR(255),
|
||||
content VARCHAR(65535))
|
||||
content TEXT(65535))
|
||||
""".format(name))
|
||||
cursor.close()
|
||||
|
||||
|
@ -61,13 +63,13 @@ def createTableMa(db, name):
|
|||
name VARCHAR(255),
|
||||
url VARCHAR(255),
|
||||
pass VARCHAR(255),
|
||||
user VARCHAR(255)),
|
||||
user VARCHAR(255),
|
||||
selector VARCHAR(255),
|
||||
selector_login_user VARCHAR(255),
|
||||
selector_login_pass VARCHAR(255),
|
||||
selector_login_verify VARCHAR(255),
|
||||
selector_login_url VARCHAR(255),
|
||||
selector_login_verify_url VARCHAR(255)
|
||||
selector_login_verify_url VARCHAR(255))
|
||||
""".format(name))
|
||||
cursor.close()
|
||||
|
||||
|
@ -115,20 +117,58 @@ def getContent(entryUrl, session_cookies, selector):
|
|||
|
||||
return a.tostring()
|
||||
|
||||
#url: https://accounts.ft.com/login
|
||||
#p1 = (23.,23.)
|
||||
def move_mouse(p1, p2, driver, time=1000, n=400, click=False):
|
||||
|
||||
action = ActionChains(driver);
|
||||
points = bspline(gcv(p1,p2,5), degree=3, n=n)
|
||||
for point in points:
|
||||
action.move_to_element(point[0],point[1]);
|
||||
action.perform();
|
||||
sleep(time/(1000*n))
|
||||
if click:
|
||||
action.click()
|
||||
|
||||
def get_loc(e):
|
||||
return (e.location['x']+(e.size['width']/3),e.location['y']+(e.size['height']/3))
|
||||
|
||||
def getSession(user, password, url="https://accounts.ft.com/login"):
|
||||
#selenium
|
||||
driver = selenium.webdriver.Chrome()
|
||||
driver.get(url)
|
||||
driver.find_element_by_id("enter-email").send_keys(user)
|
||||
#sleep
|
||||
driver.find_element_by_id("enter-email-next").submit()
|
||||
#sleep
|
||||
driver.find_element_by_id("enter-password").send_keys(password)
|
||||
driver.find_element_by_id("enter-password").submit()
|
||||
|
||||
email = driver.find_element_by_id("enter-email")
|
||||
pos1 = get_loc(email)
|
||||
move_mouse((128.3, 345.2),pos1,driver, n=200)
|
||||
email.send_keys(user)
|
||||
|
||||
time.sleep(2)
|
||||
|
||||
email_submit = driver.find_element_by_id("enter-email-next")
|
||||
pos2 = get_loc(email,submit)
|
||||
move_mouse(pos1,pos2,driver, n=50)
|
||||
email_submit.submit()
|
||||
|
||||
time.sleep(3)
|
||||
|
||||
password_el = driver.find_element_by_id("enter-password").send_keys(password)
|
||||
pos3 = get_loc(password_el)
|
||||
move_mouse(pos2,pos3,driver, n=50)
|
||||
password_el.send_keys(password)
|
||||
|
||||
time.sleep(5)
|
||||
|
||||
button = driver.find_element_by_css_selector(".o-buttons--primary.o-buttons--big.main-button")
|
||||
pos4 = get_loc(button)
|
||||
move_mouse(pos3,pos4,driver, n=50, click=True)
|
||||
time.sleep(20)
|
||||
|
||||
cookies = driver.get_cookies()
|
||||
cookies_dict = {}
|
||||
for cookie in cookies:
|
||||
cookies_dict[cookie['name']] = cookie['value']
|
||||
print(cookies_dict)
|
||||
die()
|
||||
return cookies
|
||||
|
||||
#url: https://www.ft.com/myaccount
|
||||
|
|
57
math.py
Normal file
57
math.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
import numpy as np
|
||||
import scipy.interpolate as si
|
||||
|
||||
from scipy.spatial import distance
|
||||
|
||||
def bspline(cv, n=100, degree=3, periodic=False):
|
||||
""" Calculate n samples on a bspline
|
||||
|
||||
cv : Array ov control vertices
|
||||
n : Number of samples to return
|
||||
degree: Curve degree
|
||||
periodic: True - Curve is closed
|
||||
False - Curve is open
|
||||
"""
|
||||
|
||||
# If periodic, extend the point array by count+degree+1
|
||||
cv = np.asarray(cv)
|
||||
count = len(cv)
|
||||
|
||||
if periodic:
|
||||
factor, fraction = divmod(count+degree+1, count)
|
||||
cv = np.concatenate((cv,) * factor + (cv[:fraction],))
|
||||
count = len(cv)
|
||||
degree = np.clip(degree,1,degree)
|
||||
|
||||
# If opened, prevent degree from exceeding count-1
|
||||
else:
|
||||
degree = np.clip(degree,1,count-1)
|
||||
|
||||
|
||||
# Calculate knot vector
|
||||
kv = None
|
||||
if periodic:
|
||||
kv = np.arange(0-degree,count+degree+degree-1,dtype='int')
|
||||
else:
|
||||
kv = np.concatenate(([0]*degree, np.arange(count-degree+1), [count-degree]*degree))
|
||||
|
||||
|
||||
# Calculate query range
|
||||
u = np.linspace(periodic,(count-degree),n)
|
||||
|
||||
|
||||
# Calculate result
|
||||
return np.array(si.splev(u, (kv,cv.T,degree))).T
|
||||
|
||||
|
||||
def gcv(p1,p2, n):
|
||||
d = distance.euclidean(p1,p2)
|
||||
x_lst = np.linspace(p1[0],p2[0],n-2)
|
||||
y_lst = np.linspace(p1[1],p2[1],n-2)
|
||||
|
||||
r = np.random.random_sample((n-2,))
|
||||
r_ = np.random.random_sample((n-2,))
|
||||
s = np.array(list(zip(x_lst + d *(r_-0.5),y_lst + d *(r-0.5))))
|
||||
b = np.concatenate((np.array([[p1[0],p1[1]]]),np.concatenate((s,np.array([[p2[0],p2[1]]])))))
|
||||
return s
|
||||
|
Loading…
Reference in a new issue