【Python】爬取m3u8视频,有AES-128加密和IV偏移,自己研究三天三夜,来论坛求助大...
本帖最后由 大兵马元帅 于 2023-11-18 13:58 编辑先试下载001.ts,下载后一直是无法打开,求助各位大佬
谢谢私信
链接请先base64解密:aHR0cHM6Ly93d3cuOTJneXcuY29t
{:1_919:}from Cryptodome.Cipher import AES
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
import requests
key_url = "https://www.*****.com/video/d7d2d2590b54a7c57cd62eecaa919498c14f156683503e8b682791f139995d20.key"
key_response = requests.get(key_url)
key_bytes = key_response.content
print(key_bytes)
# IV = '0xAC516370842EFE6802965DCE1C918CC6'(开发者工具获取到IV值)
# //取前16位
iv_bytes = b"AC516370842EFE68"
print(iv_bytes)
video_url_1 = "https://f.*****.com/video/00/00/0b/9c/001.ts"
video_response_1 = requests.get(video_url_1)
video_data_1 = video_response_1.content
# 创建 Cipher 对象时包括 IV
ci = AES.new(key_bytes, AES.MODE_CBC, iv_bytes)
decrypted_data_1 = ci.decrypt(video_data_1)
# 保存解密后的视频数据到本地文件
with open("output_001.mp4", "wb") as file_1:
file_1.write(decrypted_data_1)
key在本地经过二次处理
from Cryptodome.Cipher import AES
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
import requests
import struct
def decrypt_key(response_data, revise_value, little_endian=False):
new_data = b''
for i in range(4):
fmt = '<I' if little_endian else '>I'
data = struct.unpack(fmt, response_data) ^ revise_value
new_data += struct.pack(fmt, data)
return new_data
# revise从course/getLessonVideo中获取
revise = [
3854078970,
2917115795,
3887476043,
3350876132
]
key_url = "https://www.*****.com/video/d7d2d2590b54a7c57cd62eecaa919498c14f156683503e8b682791f139995d20.key"
key_response = requests.get(key_url)
key_bytes = key_response.content
key_bytes = decrypt_key(key_bytes, revise)
print(key_bytes)
# IV = '0xAC516370842EFE6802965DCE1C918CC6'(开发者工具获取到IV值)
# //取前16位
iv_bytes = b"AC516370842EFE68"
print(iv_bytes)
video_url_1 = "https://f.*****.com/video/00/00/0b/9c/001.ts"
video_response_1 = requests.get(video_url_1)
video_data_1 = video_response_1.content
# 创建 Cipher 对象时包括 IV
ci = AES.new(key_bytes, AES.MODE_CBC, iv_bytes)
decrypted_data_1 = ci.decrypt(video_data_1)
# 保存解密后的视频数据到本地文件
with open("output_001.mp4", "wb") as file_1:
file_1.write(decrypted_data_1) 得合并碎片啊, sai609 发表于 2023-11-18 11:54
得合并碎片啊,
按道理来说,不合并也可以打开一小段,现在是一小段都不打开,应该是还没有解密成功{:1_937:} 既然求助就拿出诚意来,网址别打码呀 直接用逍遥大仙的下载器试一下如果失败,说明你的key是错的,二次加密了 蹲一个后续,这个怎么使用呢 有道 理,有道理 pwp 发表于 2023-11-18 12:17
既然求助就拿出诚意来,网址别打码呀
https://www.92gyw.com,我担心论坛不让发链接,所以开始没敢放{:1_937:} 平淡最真 发表于 2023-11-18 12:27
直接用逍遥大仙的下载器试一下如果失败,说明你的key是错的,二次加密了
提示:m3u8文件无效