请使用python进行编译失调,切勿用于非法用途!!
创建main.js脚本
代码如下
const {VM,VMScript} = require("vm2");
const fs = require("fs");
const {read} = require("./env/main");
const {readJsCode} = require("./JsCode/main");
const cheerio = require('cheerio');
const {getDocument} = require("./cheerio");
const {readHTMLCode} = require("./HTML/main");
const crypto = require("crypto");
const getRandomValues = require('get-random-values');
const{createCanvas} = require('canvas');
const Fingerprint = require("fingerprintjs");
let jsCode = "";
crypto.getRandomValues = getRandomValues;
jsCode += read();
jsCode += readJsCode();
const html = readHTMLCode();
$ = getDocument(html);
//console.log($);
_log = console.log
//debugger;
function sign(){
const vm = new VM({
sandbox:{
outside:{
$,
_log,
cheerio,
createCanvas,
}
}
});
const script = new VMScript(jsCode,{filename : "./debug.js"});
result = vm.run(script);
return vm.sandbox.outside.sign;
}
/*navigator = window.navigator;
screen = window.screen;
document = window.document;
HTMLCanvasElement = window.HTMLCanvasElement;
finJS = new Fingerprint({canvas:true}).get()*/
//console.log(window);
//console.log(sign())
然后创建ceshi.py文件
代码如下
import hashlib
import json
import re
import time
import ddddocr
import requests
import execjs
import base64
from io import BytesIO
from urllib.parse import urlencode
import os
from PIL import Image
def post_api(img):
with open(img, "rb") as f:
bin_contents = f.read()
heads={
"content-type":"image/png"
}
result = requests.post("http://111.224.107.217:710/ocr", data=bin_contents,headers=heads)
return result.text
def get_img(img1,img2):
new_image = Image.new('RGB', (672, 620), 'white')
new_image.paste(img1, (0, 0))
new_image.paste(img2, (200, 200))
slide = ddddocr.DdddOcr(det=False, ocr=False, show_ad=False)
yuming = "https://t.captcha.qq.com"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"
}
def get_slide_data(aid):
#url = "https://ssl.ptlogin2.qq.com/check?regmaster=&pt_tea=2&pt_vcode=1&uin=123456&appid=716027609&js_ver=23071715&js_type=1&login_sig=lbhSg7DKUcLjie3yZlSOblGe3WdqeOe9X4daUZecV-lhW7DCOcx6Y1wdPUmbnJ6F&u1=https%3A%2F%2Fgraph.qq.com%2Foauth2.0%2Flogin_jump&r=0.25903945246093674&pt_uistyle=40&daid=383&pt_3rd_aid=102013353&o1vId=b85257193f7035a52f6144d700801644&pt_js_version=v1.46.0"
#r = requests.get(url, headers=headers).text
#sid = re.findall(".*?'(.*?)'",r)
#print(sid[6])
url="https://t.captcha.qq.com/cap_union_prehandle?aid={}&protocol=https&accver=1&showtype=popup&ua=TW96aWxsYS81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzExNi4wLjAuMCBTYWZhcmkvNTM3LjM2&noheader=1&fb=1&aged=0&enableAged=0&enableDarkMode=0&grayscale=1&clientype=2&cap_cd=&uid=&lang=zh-cn&entry_url=https%3A%2F%2F007.qq.com%2Fonline.html&elder_captcha=0&js=%2Ftcaptcha-frame.7f61d9f7.js&login_appid=&wb=2&subsid=11&callback=_aq_426535&sess=".format(aid)
#url = "https://t.captcha.qq.com/cap_union_prehandle?aid=716027609&protocol=https&accver=1&showtype=embed&ua=TW96aWxsYS81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzExNi4wLjAuMCBTYWZhcmkvNTM3LjM2&noheader=1&fb=1&aged=0&enableAged=1&enableDarkMode=0&sid="+sid[6]+"&grayscale=1&clientype=2&cap_cd=&uid=&lang=zh-cn&entry_url=https%3A%2F%2Fgraph.qq.com%2Foauth2.0%2Flogin_jump&elder_captcha=0&js=%2Ftcaptcha-frame.7f61d9f7.js&login_appid=&wb=2&subsid=7&callback=_aq_380771&sess="
r = requests.get(url, headers=headers).text[11: -1]
data = json.loads(r)
#print(data)
_data ={}
_data["powCfg"]={}
_data["sid"] = data["sid"]
_data["sess"] = data["sess"]
_data["y"] = data["data"]['dyn_show_info']['fg_elem_list'][1]['init_pos'][1]
#print(_data["y"],"我是y坐标")
_data["powCfg"]["md5"] = data["data"]['comm_captcha_cfg']['pow_cfg']["md5"]
_data["powCfg"]["prefix"] = data["data"]['comm_captcha_cfg']['pow_cfg']["prefix"]
_data["dcFileName"] = data["data"]['comm_captcha_cfg']['tdc_path']
_data["cdnPic1"] = data["data"]['dyn_show_info']['bg_elem_cfg']['img_url']
_data["cdnPic2"] = data["data"]['dyn_show_info']['sprite_url']
print("_data->",_data)
#_data["sid"] = data["sid"]
return _data
def find_slide_notch(url):
css_dict = {
"background-image": url,
"background-position": "-70.8333px -247.917px",
"background-size": "345.06px 313.69px",
"width": "60.7143px",
"height": "60.7143px",
"left": "25.2976px",
"top": "123.958px",
"z-index": "1",
"cursor": "pointer",
"opacity": "1",
}
# 获取图片并加载为Pillow Image对象
response = requests.get(css_dict["background-image"])
img = Image.open(BytesIO(response.content))
# 解析CSS中的background-position和background-size属性
bg_position = [float(pos.strip("px")) for pos in css_dict["background-position"].split()]
bg_size = [float(size.strip("px")) for size in css_dict["background-size"].split()]
# 计算切割区域
x = -bg_position[0] * img.width / bg_size[0]
y = -bg_position[1] * img.height / bg_size[1]
w = float(css_dict["width"].strip("px")) * img.width / bg_size[0]
h = float(css_dict["height"].strip("px")) * img.height / bg_size[1]
# 切割图片
crop_img = img.crop((x, y, x + w, y + h))
# 可以将切割后的图片保存到本地
crop_img.save("crop_img.png")
with open("crop_img.png", "rb") as fp:
target_bytes = fp.read()
return target_bytes
def get_slide_distance(tar_img, back_img):
#图片处理 ddddorc处理,怎么处理啊,那种新版本的滑块,返回的阴影是整个
# target_bytes = requests.get(tar_img).content
target_bytes = find_slide_notch(tar_img)
background_bytes = requests.get(back_img).content
res = slide.slide_match(target_bytes, background_bytes, simple_target=True)
return res["target"][0]-2, res["target"][1]
def post_data(collect, eks, sess, notch_data, prefix, nonce, sid,ip):
url = "https://t.captcha.qq.com/cap_union_new_verify"
headers = {
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36",
}
ans = "{},{}".format(notch_data[0], notch_data[1])
data = {
"collect":collect,
"tlg":len(collect),
"eks":eks,
"sess":sess,
"pow_answer":prefix,
"pow_calc_time":28,
"ans":[{"elem_id":1,"type":"DynAnswerType_POS","data":ans}]
}
#print(data)
#print(ip)
try:
r = requests.post(url, headers=headers, data=urlencode(data), proxies=ip, timeout=(3))
print(r.text)
return json.loads(r.text)
except:
print("代理ip有问题")
return {}
def sign_md5(params):
"""
对拼接好的字符串进行md5签名
"""
hl = hashlib.md5()
hl.update(params.encode(encoding='utf-8'))
return hl.hexdigest()
def get_ans(prefix, md5_code):
u = 0
while sign_md5(str(prefix) + str(u)) != md5_code:
u += 1
return str(u)
def get_data():
with open("./main.js", "r", encoding="utf-8") as fp:
exec_js = execjs.compile(fp.read())
data = exec_js.call("sign")
return data
def check(ticket, randstr):
print(ticket,randstr)
url = "https://shminorshort.weixin.qq.com/security/secondauth?t=login_verify_entrances/w_tcaptcha_ret&wechat_real_lang=zh_CN&aid=2000000038&clientype=1&lang=2052&apptype=undefined&captype=7&disturblevel=1§icket=1_50849126415703827916983126930139&pass_ticket=09con7e6%2FLfNNyWYz%2BpNMApotpCkWv3dIq0rMg8J25g6D7c4Iy89Gl4nQFciZiFs8CQdBsOJ48Lmp51KaD4pRQ%3D%3D&ret=0&ticket={}&randstr={}&step=8".format(ticket,randstr)
headers = {
"accept": "application/json, text/plain, */*",
"accept-encoding": "gzip, deflate",
"accept-language": "zh-CN,zh;q=0.9",
"referer": url,
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36 NetType/WIFI MicroMessenger/7.0.20.1781(0x6700143B) WindowsWechat(0x6309071d) XWEB/8461 Flue"
}
jieguo = requests.get(url=url,headers=headers).text
print(jieguo,"----->我是提交结果")
def tx_start(aid, ip):
_t = time.time()
slide_data = get_slide_data(aid)
#tdc_js = "https://turing.captcha.qcloud.com/" + slide_data["dcFileName"]
slide_js = requests.get("https://t.captcha.qq.com" + slide_data["dcFileName"], headers=headers).text
img1 = "https://t.captcha.qq.com" + slide_data["cdnPic1"]
img2 = "https://t.captcha.qq.com" + slide_data["cdnPic2"]
print(img1,img2)
#find_slide_notch(img2)
#acc = get_slide_distance(img1,img2)
#print(acc[0],acc[1])
#notch_data = get_slide_distance(img2, img1)
background_bytes = requests.get(img1).content
res = slide.slide_match(background_bytes, find_slide_notch(img2), simple_target=True)
#res["target"][0] - 2, res["target"][1]
print(res)
#heads = {
# "content-type": "image/png"
#}
#result = requests.post("http://111.224.107.217:710/ocr", data=background_bytes, headers=heads).text
notch_data =[]
notch_data.append(res["target"][0] - 2)
notch_data.append(res["target"][1])
print("坐标->",notch_data)
md5_code = slide_data["powCfg"]["md5"]
prefix = slide_data["powCfg"]["prefix"]
ans = get_ans(prefix, md5_code)
with open("./JsCode/start.js", "w", encoding="utf-8") as fp:#我好像没这个东西
fp.write(slide_js)
fp.flush()
print("tx------->执行结果")
data = get_data()
collect = data
eks = re_x_url(slide_js, "='", "'")
result = post_data(collect, eks, slide_data["sess"], notch_data, prefix + ans, "", slide_data["sid"],ip)
#print("耗费时间:{}ms".format((time.time() - _t)* 1000))
#判断是否通过滑块
if result["errorCode"] == 0:
ticket = result["ticket"]
randstr = result["randstr"]
check(ticket,randstr)
return result
else:
ipurl = "";
ip = requests.get(ipurl, headers=headers).text;
proxies = {
"http": ip,
"https": ip
}
print(proxies)
# 重试多次退出 需要判断次数 自己补充,等等,ddddocr那个拼接,你复制给我一份
return tx_start(aid, proxies)
def re_x_url(url, start, end, is_raise=True):
id = re.findall(r"{}(.*?){}".format(start, end), url)
if id:
id = id[0]
if is_raise and not id:
print("正则处理数据为空!")
raise IndexError("正则处理数据为空!")
return id
if __name__ == '__main__':
for i in range(10):
ipurl = "";#这里传代理
ip = requests.get(ipurl,headers=headers).text;
proxies = {
"http": ip,
"https": ip
}
print(proxies)
tx_start("2000000038",proxies)
然后在py进行编译exe