目录
视频MP4格式解密
/        

视频MP4格式解密

思路来自 52大神:https://www.52pojie.cn/forum.php?mod=viewthread&tid=1475926&page=4#pid39275617

加密后的视频:https://www.aliyundrive.com/s/cYTryqmPkGK

解密后的视频:https://www.aliyundrive.com/s/xetYHxJXoB5

加密视频的16进制文件头

第一行有16个字节,其中每个字节占8位,比如十六进制64 即 0x64 转换成二进制位 为 0110 0100 = 十进制100

image.png

正常MP4视频的文件头

image.png

一个数字a 异或 数字b, 得到数字c,我们可以数字c和数字b进行按位异或,能得到数字a;

a 和 c 异或 能得到 b

image.png

所以我们要测试 加密视频头第一行 和 正常视频的 第一行进行异或,如果没发现规律,继续第二行进行异或

image.png

image.png

在进行第二行的异或的时候,就会发现规律

最终得到的key为:100\106\107\56\38\36\100\102 - 96\50\50\51\106\115\106\104

python 代码实现

"""
  当前目录下的1.mp4文件是无法正常播放的,需要对其进行解密
  采用异或的方式;key 为
  100\106\107\56\38\36\100\102 - 96\50\50\51\106\115\106\104 这里是十进制的
  16个字节一组
"""
key = [100, 106, 107, 56, 38, 36, 100, 102,
       96, 50, 50, 51, 106, 115, 106, 104]
# key = [hex(x).encode() for x in key]


def to_hex(binary):
    l = []
    temp = []
    count = 0
    for byte in binary:
        h = int(byte)
        temp.append(h)
        count += 1
        if count == 16:
            l.append(temp)
            temp = []
            count = 0
    return l


def decode(content):
    decode_list = []
    for byte in content:
        t = []
        for x, y in zip(byte, key):
            h = hex(x ^ y)
            if len(h) < 4:
                h = h[:2] + '0' + h[2:]
            t.append(h)
        decode_list.append(t)
    return decode_list


if __name__ == '__main__':
    print(key)
    with open('./1.mp4', 'rb') as f:
        content = f.read()
    # print(content)
    l = to_hex(content)

    # print(l)
    decode_list = decode(l)
    result_content = []
    for decode in decode_list:
        result_content.append(''.join(decode))
    result_content = ''.join(result_content).replace('0x', '')
    print(result_content)
    # print(decode_list)
    with open('./1_decode.mp4', 'wb') as f:
        str = bytes.fromhex(result_content)
        f.write(str)

同理加密也是如此。


标题:视频MP4格式解密
作者:gitsilence
地址:https://blog.lacknb.cn/articles/2021/07/15/1626364407456.html