目标:mmz多页下载
方法:加一个for循环实现多页的下载
问题:浏览器传输服务器时对页码参数做了加密处理
解决方法:
1、判断加密算法模式(mmz是AES-CBC算法)
2、找到加密的key和iv
代码:
import json
import timeimport requests
import base64
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad,unpadfor page in range(2, 10):# ==============================================第一部分(模仿浏览器对页码加密传输服务器)=================================# 获取到mmz网站加密的明文数据data = {"Type": 0, "page": page, "expire": 1710571993849}# dic转化为json字符串进行处理data = json.dumps(data)# print(type(data))fill_btext = pad(data.encode(), 16)# print(fill_btext)# 解析mmz网站js拿到kv,浏览器向服务器传送加密的kvkey = '55b3b62613aef1a0'.encode()vi = keyencry = AES.new(key, AES.MODE_CBC, vi)# AES加密encry_data = encry.encrypt(fill_btext)# 加密 b64b64encode_data = base64.b64encode(encry_data)# print(b64encode.decode())# ============================================第二部分(拿到加密的参数获取服务器返回的数据并解密)=================================# 解密服务器返回的数据cookies = {'PHPSESSID': '48nu182kdlsmgfo2g7hl6eufsa','Hm_lvt_6cd598ca665714ffcd8aca3aafc5e0dc': '1710568549','SECKEY_ABVK': 'FUnr+pnCS/p1Ou/WiS6a82jLBmKcwlQfvALD/bEpSYS0EV42eXkFNYpCmcekNiiKvyrlcEHfDw6QLw7GSqcv/w%3D%3D','Hm_lpvt_6cd598ca665714ffcd8aca3aafc5e0dc': '1710568575','BMAP_SECKEY': 'FUnr-pnCS_p1Ou_WiS6a82jLBmKcwlQfvALD_bEpSYRjgInAaoK-vELl57QFAxX-y1kv64ZfrWIegR6xAqZk5YPrHMNgpor4__VOFQ2YBt9ZLJyD0Ru3kQ8TLNDX9tgT2rE6la_DNO7NooPoKY8lg-7nkrw7RqULcxikq6qpjt72ToZ7LhtjeWs5kU5TcRy2ruVzAKFKBpjmyUlPmKeBwJM_HQkgSUF_-wJjonbLE8U',}headers = {'Accept': '*/*','Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6','Connection': 'keep-alive','Content-Type': 'application/json; charset=UTF-8',# 'Cookie': 'PHPSESSID=48nu182kdlsmgfo2g7hl6eufsa; Hm_lvt_6cd598ca665714ffcd8aca3aafc5e0dc=1710568549; SECKEY_ABVK=FUnr+pnCS/p1Ou/WiS6a82jLBmKcwlQfvALD/bEpSYS0EV42eXkFNYpCmcekNiiKvyrlcEHfDw6QLw7GSqcv/w%3D%3D; Hm_lpvt_6cd598ca665714ffcd8aca3aafc5e0dc=1710568575; BMAP_SECKEY=FUnr-pnCS_p1Ou_WiS6a82jLBmKcwlQfvALD_bEpSYRjgInAaoK-vELl57QFAxX-y1kv64ZfrWIegR6xAqZk5YPrHMNgpor4__VOFQ2YBt9ZLJyD0Ru3kQ8TLNDX9tgT2rE6la_DNO7NooPoKY8lg-7nkrw7RqULcxikq6qpjt72ToZ7LhtjeWs5kU5TcRy2ruVzAKFKBpjmyUlPmKeBwJM_HQkgSUF_-wJjonbLE8U','Origin': 'https://www.maomaozu.com','Referer': 'https://www.maomaozu.com/','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/122.0.0.0 Safari/537.36 Edg/122.0.0.0','sec-ch-ua': '"Chromium";v="122", "Not(A:Brand";v="24", "Microsoft Edge";v="122"','sec-ch-ua-mobile': '?0','sec-ch-ua-platform': '"Windows"',}response = requests.post('https://www.maomaozu.com/index/build.json', cookies=cookies, headers=headers,data=b64encode_data)res = response.text# 解密 b64b64decode = base64.b64decode(res)# 解析mmz网站js拿到kv,服务器向浏览器传送数据的解密kvkey = '0a1fea31626b3b55'.encode()vi = keycry = AES.new(key, AES.MODE_CBC, vi)# print(cry.decrypt(b64decode).decode())# unpad去除填充mmz_text = unpad(cry.decrypt(b64decode),16).decode()print(mmz_text)time.sleep(1)
浏览器和服务器之间关系示意图:
浏览器到服务器加密、服务器到浏览器加密,不一定一样
代码流程:
1、使用方法搜索到加密位置,并断点分析
2、拿到传输的明文数据和key、iv
3、模仿浏览器生成加密数据
4、将加密的数据写入“第二部分代码”的加密参数(data)中