V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
onsala
V2EX  ›  问与答

关于破解网易云音乐加密登录方式?

  •  
  •   onsala · 2017-02-21 12:19:34 +08:00 · 4490 次点击
    这是一个创建于 2592 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我使用的是邮箱登录的方式,登录的代码如下:

    import requests
    
    headers = {'Cookie': 'appver=1.5.0.75771;', `Referer': 'http://music.163.com/', 
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36'
    }
    
    session = requests.Session()
    
    
    def login(username, password):
        url = 'https://music.163.com/weapi/login/'
        text = {
            'username': username,
            'password': password,
            'rememberLogin': 'true'
        }
        data = encrypted_request(text)
        try:
            r = session.post(url, data=text, headers=headers)
            print r.text
        except requests.exceptions.RequestException as e:
            print e
    
    # 邮箱登录
    login('[email protected]', 'password')
    

    encrpyted_request部分的代码参考自https://github.com/darknessomi/musicbox/wiki/%E7%BD%91%E6%98%93%E4%BA%91%E9%9F%B3%E4%B9%90%E6%96%B0%E7%89%88WebAPI%E5%88%86%E6%9E%90%E3%80%82

    import hashlib
    import os
    import json
    import base64
    import binascii
    
    from Crypto.Cipher import AES
    
    modulus = ('00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7'
               'b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280'
               '104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932'
               '575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b'
               '3ece0462db0a22b8e7')
    nonce = '0CoJUm6Qyw8W8jud'
    pubKey = '010001'
    
    
    def encrypted_request(text):
        text = json.dumps(text)
        secKey = createSecretKey(16)
        encText = aesEncrypt(aesEncrypt(text, nonce), secKey)
        encSecKey = rsaEncrypt(secKey, pubKey, modulus)
        data = {'params': encText, 'encSecKey': encSecKey}
        return data
    
    
    def aesEncrypt(text, secKey):
        pad = 16 - len(text) % 16
        text = text + chr(pad) * pad
        encryptor = AES.new(secKey, 2, '0102030405060708')
        ciphertext = encryptor.encrypt(text)
        ciphertext = base64.b64encode(ciphertext).decode('utf-8')
        return ciphertext
    
    
    def rsaEncrypt(text, pubKey, modulus):
        text = text[::-1]
        rs = pow(int(binascii.hexlify(text), 16), int(pubKey, 16), int(modulus, 16))
        return format(rs, 'x').zfill(256)
    
    
    def createSecretKey(size):
        return binascii.hexlify(os.urandom(size))[:16]
    

    上面的代码可以直接运行,但是运行以后print r.text没有任何输出,而且也是闪退,估计没有登录成功,请问有登录成功的朋友能分享一下相关经验吗?

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1365 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 17:41 · PVG 01:41 · LAX 10:41 · JFK 13:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.