python 爬虫 破解__jsluid_s 和 __jsl_clearance_s加密参数

该代码段展示了一个使用Python的requests库来获取并处理网页cookies的流程,特别是针对__jsluid_s和__jsl_clearance_s的加密参数。通过对不同hash算法(如sha256,sha1,md5)的检查,找到匹配的加密值,从而解密这些特定的cookies。
摘要由CSDN通过智能技术生成

破解__jsluid_s 和 __jsl_clearance_s加密参数

def get_cookies():
    headers = {
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
        'Upgrade-Insecure-Requests': '1',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.142 Safari/537.36',
    }
    url1 = 'https://zwgk.hefei.gov.cn/public/column/1741?type=4&action=list&nav=&sub=&catId=6712341'
    r1 = requests.get(url1, headers=headers, verify=False)
    js = r1.text
    js = js.replace('<script>document.cookie=', '').replace(';location.href=location.pathname+location.search</script>',
                                                            '')
    result = execjs.eval(js)
    __jsluid_h = r1.headers['Set-Cookie']
    __jsl_clearance = result
    cookies = {
        '__jsluid_s': __jsluid_h.replace('__jsluid_s=', ''),
        '__jsl_clearance_s': __jsl_clearance.replace('__jsl_clearance_s=', '')
    }
    url2 = 'https://zwgk.hefei.gov.cn/public/column/1741?type=4&action=list&nav=&sub=&catId=6712341'
    r2 = requests.get(url2, headers=headers, verify=False, cookies=cookies)
    data_org = re.findall(';go(.*)</script>', r2.text)[0]
    data = data_org.replace('(', '').replace(')', '')
    data = json.loads(data)
    bts = data['bts']
    chars = data['chars']
    ct = data['ct']
    ha = data['ha']
    # vt = data['vt']
    counti = 0
    countj = 0
    if ha == 'sha256':
        print('加密算法-' + ha)
        for i in range(len(bts[0])):
            for j in range(len(chars)):
                cookieTemp = bts[0] + chars[i] + chars[j] + bts[1]
                if get_hash256(cookieTemp) == ct:
                    counti = i
                    countj = j
                    break
    elif ha == 'sha1':
        print('加密算法-' + ha)
        for i in range(len(bts[0])):
            for j in range(len(chars)):
                cookieTemp = bts[0] + chars[i] + chars[j] + bts[1]
                if get_hashsha1(cookieTemp) == ct:
                    counti = i
                    countj = j
                    break
    elif ha == 'md5':
        print('加密算法-' + ha)
        for i in range(len(bts[0])):
            for j in range(len(chars)):
                cookieTemp = bts[0] + chars[i] + chars[j] + bts[1]
                if get_hashmd5(cookieTemp) == ct:
                    counti = i
                    countj = j
                    break
    __jsl_clearance = bts[0] + chars[counti] + chars[countj] + bts[1]
    new_cookies = {
        '__jsluid_s': __jsluid_h.replace('__jsluid_s=', '').replace(
            'max-age=31536000; path=/; HttpOnly; SameSite=None; secure', ''),
        '__jsl_clearance_s': __jsl_clearance,
    }
    result_cookies = '__jsluid_s={}; __jsl_clearance_s={}'.format(new_cookies['__jsluid_s'],
                                                                  new_cookies['__jsl_clearance_s'])
    return result_cookies
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值