网易云音乐缓存解密

本文原写于2020/10/06

在螺丝工作室的笔试中有一道题是⾳乐⽂件破解, 题目如下


本意是考察使用搜索引擎的能力, 百度一下加粗文字就能找到破解办法啦, 但我没注意到, 于是就自己分析了一遍网易云音乐的缓存
刚开始被题目误导, 在音乐解密网站尝试了多种格式但均以失败告终
MP3的魔数是 ID3, 因此文件开头的三个字节本应该是 ID3, 然后经一通分析发现是对每个字节都和 F6(11110110)做了异或, 再做一遍就解密了, 具体算法用 Python 实现, 代码如下:

with open("question_2.upw","rb") as file:
    with open("answer_2.upw","wb") as result:
        while True:
            abyte = file.read(1)
            if abyte == b"":
                break
            byte2 = int.from_bytes(abyte, byteorder='little')
            byte3 = byte2 ^ 246
            result.write(byte3.to_bytes(length=1, byteorder='little'))
            # b11110110=246

成功拿到音乐文件, 但是还有一个问题摆在我面前, 那就是这首歌我不认识= =
但是我还有大杀器Shazam, 用它听歌识曲得到最终答案


PS: 不懂就问, 异或能算加密嘛???


半年之后我又遇到了解密网易云音乐缓存的需求, 结果发现现在还是对每个字节和一个固定字节做异或, 只不过不是F6了, 因此果断改进一下脚本, 现在这个脚本能够检测当前目录下所有后缀名为.uc的文件, 并将其还原为mp3, 代码如下:

# coding=utf-8
import os
def unlock(input, output):
    while True:
        abyte = input.read(1)
        if abyte == b"":
            break
        byte2 = int.from_bytes(abyte, byteorder='little')
        byte3 = byte2 ^ 163 # 现在是A3(十进制163, 二进制10100011), 如果变了就改这里
        output.write(byte3.to_bytes(length=1, byteorder='little'))
    return
def main():
    print("Welcome to use CloudMusic cache unlocker. Made by wc")
    for root, dirs, files in os.walk('.'):
        for name in files:
            fullpath = os.path.join(root, name)
            if fullpath.endswith(".uc"):
                print("Found %s. Start to unlock." % fullpath)
                with open(fullpath, 'rb') as file:
                    fullpath2 = fullpath.replace(".uc", ".mp3")
                    with open(fullpath2, 'wb') as result:
                        unlock(file, result)
            else:
                print("Skip %s." % fullpath)
if __name__ == '__main__':
    main()

你也可以在GitHub上找到这个脚本, 我会优先更新GitHub而非博客
https://github.com/DawningW/Python-Tests/blob/master/cloudmusic_unlock.py

标题: 网易云音乐缓存解密
作者: QingChenW
链接: https://dawncraft.cc/2021/04/80/
本文遵循 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 许可
禁止商用, 非商业转载请注明作者及来源!
上一篇
下一篇
隐藏