生成X-Bogus的js代码,通过python调用生成

简介: 该文本是一个关于如何解析和执行JavaScript代码的步骤说明。主要内容包括:1. 找到JavaScript文件的位置。2. 下载代码并进行格式化。3. 运行代码时会出现缺少变量错误,需要添加模拟环境的代码。4. 指出主要的入口函数是`_0x5a8f25`,将其赋值给`window`。5. 提供了整个JavaScript代码的长串内容。6. 提供了一个Python脚本,用于调用这个JavaScript函数并处理返回的数据。总结:这段文本描述了如何处理和运行一个JavaScript文件,以及使用Python来与这个脚本交互的示例。

1、找到js所在位置,一般这样来找的:
image.png

2、下载下来代码,格式化一下;

3、直接运行代码会报错,提示缺少变量;
添加以下代码(补环境)

window = global
Request = function(){
   
   }
Headers = function(){
   
   }
document = {
   
   }
document.addEventListener =function (){
   
   }

4、 主要入口函数是:_0x5a8f25; 赋值给window

  function _0x5a8f25(_0x48914f, _0xa771aa) {
        return ('undefined' == typeof window ? global : window)['_$webrt_1668687510']('484e4f4a403f52430017211b45bdadd5a9f8450800000000000007fa1b0002012f1d00921b000b191b000b02402217000a1c1b000b1926402217000c1c1b000b190200004017002646000306000e271f001b000200021d00920500121b001b000b031b000b19041d0092071b000b0401220117000b1c1b000b051e01301700131b00201d00741b000b06260a0000101c1b000b07260a0000101c1b001b000b081e01311d00931b001b000b091e00091d00941b0048021d00951b001b000b1d1d009d1b0048401d009e1b001b000b031b000b18041d00d51b001b000b0a221e0132241b000b031b000b0a221e0132241b000b200a000110040a0001101d00d71b001b000b0a221e0132241b000b031b000b0a221e0132241b000b1a0a000110040a0001101d00d91b000b0b1e00161e01330117002d1b000b0b1e001602000025001d11221e006e24131e00530201340200701a020200000a000210001d01331b001b000b0c1e00101d00da1b000b232217000e1c211b000b23430201353e1700151b001b000b23221e0133240a0000101d00da1b001b000b0d261b000b1c1b000b1b0a0002101d00db1b001b000b0e261b000b241b000b230a0002101d00dd1b001b000b0f261b000b250200200a0002101d00e11b001b000b0a221e0132241b000b031b000b26040a0001101d00e21b001b000b101a00221e00dc240a0000104903e82b1d00e31b001b000b11260a0000101d00e41b001b000b1f1d00e71b001b000b1c4901002b1d00e81b001b000b1c4901002c1d00ea1b001b000b1b1d00ee1b001b000b21480e191d00f31b001b000b21480f191d00f91b001b000b22480e191d00fa1b001b000b22480f191d00fc1b001b000b27480e191d00ff1b001b000b27480f191d01011b001b000b284818344900ff2f1d01021b001b000b284810344900ff2f1d01041b001b000b284808344900ff2f1d01361b001b000b284800344900ff2f1d01371b001b000b294818344900ff2f1d01381b001b000b294810344900ff2f1d01391b001b000b294808344900ff2f1d013a1b001b000b294800344900ff2f1d013b1b001b000b2a1b000b2b311b000b2c311b000b2d311b000b2e311b000b2f311b000b30311b000b31311b000b32311b000b33311b000b34311b000b35311b000b36311b000b37311b000b38311b000b39311b000b3a311b000b3b311d013c1b004900ff1d013d1b001b000b12261b000b2a1b000b2c1b000b2e1b000b301b000b321b000b341b000b361b000b381b000b3a1b000b3c1b000b2b1b000b2d1b000b2f1b000b311b000b331b000b351b000b371b000b391b000b3b0a0013101d013e1b001b000b0e261b000b131b000b3d041b000b3e0a0002101d013f1b001b000b14261b000b1e1b000b3d1b000b3f0a0003101d01401b001b000b15261b000b400200240a0002101d01411b000b4100000142000160203333333333333333333333333333333333333333333333333333333333333333016d0e3130333c3b3005273a253027212c023c31061a373f3036210332302108313037203232302707303b23363a313007363a3b263a393007333c27303720320a3a20213027023c31213d0a3c3b3b3027023c31213d0b3a202130271d303c323d210b3c3b3b30271d303c323d2109202630271432303b210b213a193a223027163426300163073c3b31302d1a33083039303621273a3b09203b3130333c3b30310925273a213a212c253008213a0621273c3b3204363439390725273a36302626100e3a373f3036217525273a3630262608063a373f30362105213c213930043b3a31300168016202266541141716111013121d1c1f1e19181b1a05040706010003020d0c0f343736313033323d3c3f3e39383b3a25242726212023222d2c2f65646766616063626d6c7e7a6802266441113e3125323d610f1e2604176d657a1833232266630d1c640767607e02001439103c621b19373a240c011a05202f38133f1f3b272c2d6c1d03123634062116306802266741113e3125323d610f1e2604176d657a1833232266630d1c640767607802001439103c621b19373a240c011a05202f38133f1f3b272c2d6c1d031236340621163068016c0264640639303b32213d0a363d3427163a3130142102646506363d342714210f0e3a373f30362175023c3b313a220808113a362038303b21120e3a373f303621751b34233c3234213a2708053f26313a38100e3a373f303621751d3c26213a272c0807253920323c3b26080a253d343b213a380b36343939053d343b213a380b0a0a3b3c323d2138342730051420313c3a1816343b23342607303b3130273c3b32163a3b21302d2167110922303731273c233027133230211a223b05273a253027212c1b343830260939343b32203432302606363d273a38300727203b213c383007363a3b3b303621140a0a22303731273c2330270a3023343920342130130a0a263039303b3c20380a30233439203421301b0a0a22303731273c2330270a2636273c25210a33203b36213c3a3b170a0a22303731273c2330270a2636273c25210a33203b36150a0a22303731273c2330270a2636273c25210a333b130a0a332d31273c2330270a3023343920342130120a0a31273c2330270a203b22273425253031150a0a22303731273c2330270a203b22273425253031110a0a31273c2330270a3023343920342130140a0a263039303b3c20380a203b22273425253031140a0a332d31273c2330270a203b22273425253031090a263039303b3c20380c36343939063039303b3c2038160a063039303b3c20380a1c11100a0730363a2731302702646708313a362038303b21043e302c2602646602646102646002646305383421363d06073032102d250a09710e34782f0831360a063634363d300a04263a383008363033063d34272508163033063d34272505303a34253c16303a02303717273a22263027113c26253421363d30270f373c3b311a373f30362114262c3b360e3c26101a02303717273a222630270166043a25303b0421302621093c3b363a323b3c213a073a3b3027273a2704363a31301204001a01140a100d1610101110110a1007070e263026263c3a3b06213a27343230072630211c21303810263a38301e302c1d302730172c2130310a2730383a23301c213038093c3b31302d303111170c053a3c3b2130271023303b210e1806053a3c3b2130271023303b210d36273034213010393038303b210636343b23342609213a1134213400071907273025393436300309267f01320a3b34213c2330363a3130140e3a373f30362175053920323c3b142727342c084a0b3d212125266a6f097a097a7d0e65786c082e647966287d097b0e65786c082e647966287c2e6628290e34783365786c082e647961287d6f0e34783365786c082e647961287c2e62287c016108393a3634213c3a3b043d27303304333c3930103d2121256f7a7a393a3634393d3a26210825393421333a273807223c3b313a222603223c3b07343b31273a3c3105393c3b202d026462063c253d3a3b3002646d043c25343102646c043c253a3102676503383436026764093834363c3b213a263d0c3834360a253a22302725367c0436273a26032d64640536273c3a2605332d3c3a2604253c3e3002676702676602676102676002676302676202676d02676c08333c2730333a2d7a063a253027347a05753a25277a05753a25217a07363d273a38307a0821273c31303b217a0438263c300266650266640623303b313a2706123a3a3239300e0a253427343806223c21363d1a3b0a313c27303621063c323b0a363a3b263c2621303b210626223c21363d03313a3807253d343b213a38043d3a3a3e40141716111013121d1c1f1e19181b1a05040706010003020d0c0f343736313033323d3c3f3e39383b3a25242726212023222d2c2f65646766616063626d6c787b03343c31013b01330127092621342721013c383001210934373c393c213c30260a213c3830262134382564133d34273122342730163a3b36202727303b362c0c3130233c36301830383a272c0839343b32203432300a2730263a3920213c3a3b0f3423343c390730263a3920213c3a3b0926362730303b013a250a26362730303b19303321103130233c3630053c2d30390734213c3a0a25273a31203621062037073734212130272c012509213a20363d1c3b333a08213c38302f3a3b300a213c3830262134382567073225201c3b333a0b3f26133a3b2126193c26210b253920323c3b26193c26210a213c38302621343825660a30233027163a3a3e3c300721210a26363c3101380b262c3b21342d1027273a270c3b34213c233019303b32213d052721361c05093325033027263c3a3b0b0a0a233027263c3a3b0a0a0836393c303b211c310a213c38302621343825610b302d21303b31133c303931042520263d0334393904213d303b093734263063610a363d0c33273a38163d3427163a3130063763610a6665083734263063610a65026667083734263063610a64026666083734263063610a6702666102666002666307323021013c38300266620b313a381b3a210334393c31092620372621273c3b320825273a213a363a3902666d02666c02616502616401650e646565656565656564646565656502616702616607333a272730343902616104373a312c092621273c3b323c332c022e280261600b373a312c033439672621270a373a312c0a3d34263d6801730320273902616305242030272c0a34263a39310a263c323b092534213d3b343830680921210a2230373c3168067320203c316802616202616d0e0a372c2130310a2630360a313c3102616c0a61676c616c6362676c63093330033027263c3a3b0260650e0a656717610f63223a65656565640260640260670526393c3630026066070610161c1b131a033b3a2209213c383026213438250533393a3a270627343b313a380f3230210101023037163a3a3e3c3026052121223c310821210a2230373c310721210230371c310b21210a2230373c310a23670921210230373c3103670727203b3b3c3b3205333920263d08383a2330193c2621062625393c3630063730183a23300936393c363e193c262107373016393c363e0c3e302c373a342731193c26210a37301e302c373a3427310b3436213c233006213421300b223c3b313a2206213421300326013805212734363e08203b3c21013c3830033436360a203b3c2114383a203b210837303d34233c3a2707382632012c253003221c1107343c31193c26210b25273c2334362c183a313006362026213a38063426263c323b0f0210170a1110031c16100a1c1b131a043f263a3b0a2730323c3a3b163a3b33092730253a272100273904302d3c21090d78180678060100170c0d7818067805140c191a141120656565656565656565656565656565656565656565656565656565656565656520316164316d36316c6d33656537676561306c6d65656c6c6d3036336d616762300123062037363a3130063130363a31300421273c38210b0e0926092013101313092d1465087e290e0926092013101313092d1465087e71062621273c3b3202606102606002606302606202606d02606c026365026364026367026366026361026360', [, , void (-0x1afd + 0x22 * 0x25 + 0x1613), void (-0x1 * 0x71e + 0x726 + -0x2 * 0x4) !== _0x38ba41 ? _0x38ba41 : void (0x1 * 0x247f + -0x584 * -0x1 + -0x2a03), void (0x216d + -0x1 * -0x5ba + -0x303 * 0xd) !== _0x3dbe20 ? _0x3dbe20 : void (-0x325 * -0x2 + 0xb1b + -0x49 * 0x3d), void (-0x27 * 0xe9 + -0x19e2 + 0x3d61) !== _0xeb6638 ? _0xeb6638 : void (-0x211a + -0x3d * -0x88 + 0xb2 * 0x1), void (-0x1 * 0x61f + -0x65 * 0x1f + 0x125a) !== _0x2bd2cf ? _0x2bd2cf : void (-0x71e * -0x5 + 0x42b + 0x1 * -0x27c1), void (-0x7 * -0x481 + 0xc49 + -0x2bd0) !== _0x45636f ? _0x45636f : void (-0x1 * 0x1072 + -0x9e4 + 0x1a56 * 0x1), void (0x569 + 0x20ae + 0x571 * -0x7) !== _0x2cee6c ? _0x2cee6c : void (0x6 * 0x10f + -0xac * -0x3a + -0x2d52 * 0x1), void (0x58 * 0x26 + -0x17f6 * 0x1 + -0xa * -0x117) !== _0x402a35 ? _0x402a35 : void (-0x13d4 + 0x1dbd + 0x9e9 * -0x1), void (0x10fb + 0x2332 + -0x342d) !== _0x5cf87b ? _0x5cf87b : void (-0xa * 0x1ed + 0x1713 + 0x3d1 * -0x1), 'undefined' != typeof String ? String : void (-0x1131 + -0x24e8 + 0x1 * 0x3619), 'undefined' != typeof navigator ? navigator : void (0x1 * 0xbdf + -0x173e + 0xb5f), void (-0x3 * 0x166 + -0x584 + 0x9b6) !== _0x5caed2 ? _0x5caed2 : void (-0x10e * -0xf + 0x12b6 + -0x2288), void (0x272 * -0x6 + -0xcf * -0x2f + -0x21 * 0xb5) !== _0x25788b ? _0x25788b : void (-0x9 * -0x37b + -0x1 * 0x143b + -0xb18), void (0x1a77 + -0x53 * -0x16 + -0x2199) !== _0x2642b3 ? _0x2642b3 : void (0x264d + -0x11 * 0x1a + 0x2493 * -0x1), 'undefined' != typeof Date ? Date : void (0x14f * 0x3 + -0x2ff * 0xd + -0x1183 * -0x2), void (-0x1 * 0xb81 + 0x1c8c + -0x110b) !== _0x17dd8c ? _0x17dd8c : void (-0x1 * 0xf01 + -0x466 * -0x5 + 0x6fd * -0x1), void (-0x1 * -0x141b + -0x1 * -0x15ee + -0x2a09) !== _0x398111 ? _0x398111 : void (-0x16bd + 0x1690 + 0x2d), void (0x706 * 0x1 + -0x116 * 0x13 + 0x86 * 0x1a) !== _0x86cb82 ? _0x86cb82 : void (-0x121 + 0x22 * -0xa3 + 0x1 * 0x16c7), void (-0x1 * 0x599 + -0x98a + 0xf23) !== _0x94582 ? _0x94582 : void (-0xa0d + -0x1253 + 0x1c60), void (-0x348 + 0x959 * -0x2 + -0x1d * -0xc2) !== _0x38c772 ? _0x38c772 : void (0x8 * -0x4a2 + -0x6 * 0x340 + -0x10 * -0x389), , _0x5a8f25, _0x48914f, _0xa771aa]);
    }

    //
   window.dyjs = _0x5a8f25;
    //

5、全部代码在这里下载

6、测试代码:

# _*_ coding:utf-8 _*_

import json
import requests
import time
import random
import execjs

headers = """Accept: application/json, text/plain, */*
Accept-Language: zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;
Sec-Ch-Ua: "Not/A)Brand";v="99", "Microsoft Edge";v="115", "Chromium";v="115"
Sec-Ch-Ua-Mobile: ?0
Sec-Ch-Ua-Platform: "Windows"
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.188"""
# 将请求头字符串转化为字典
headers = dict([line.split(": ",1) for line in headers.split("\n")])
#print(headers)

def genXbogus(params):

    with open("webmssdk.js") as f:
        js_data = f.read()

    js_compile =execjs.compile(js_data)
    xb_data =js_compile.call("window.dyjs",params)
    print(xb_data)
    return xb_data

def downloadFile(path,url):
    rc = requests.get(url,headers=headers, stream=True)
    with open(path,'wb') as f:
        for r in rc:
            f.write(r)


def delAwemeList(aweme_list):
    with open('luyou.txt',mode='a',encoding='utf-8') as fileLy:
        for aweme in aweme_list:
            try:
                urls = aweme['video']['play_addr']['url_list']
                desc = aweme['desc'].replace(" ","").replace("#","")
                urls.insert(0,desc)
                if len(desc) > 50:
                    desc = desc[0:50]
                path = f'{desc}.mp4'
                print(desc, urls[1])
                downloadFile(path,urls[1])
                #for url in urls:
                #    fileLy.writelines(url+'\n')
                fileLy.write(desc + '下载成功\n')
            except Exception as e:
                print(e.args)
                print('----')


dy_url = 'https://www.***.com/aweme/v1/web/aweme/post/?'
user_id =''

def getDyUrl(max_cursor):
        XbogusParams = '&X-Bogus={0}'
        url_query = '你懂得'
        url_query = url_query.format(max_cursor,user_id)
        xbogus = genXbogus(url_query)
        XbogusParams = XbogusParams.format(xbogus)
        url = dy_url + url_query + XbogusParams;
        print(url)
        ret = requests.get(url,headers=headers).json()
        #ret.encoding = 'utf-8'
        #print(ret.apparent_encoding) #返回的编码
        #ret = ret.text
        #print('===',ret)
        #ret = json.loads(ret)
        print('===',ret)
        max_cursor = ret['max_cursor']
        has_more = ret['has_more']
        print('max_cursor:',max_cursor)
        print('has_more:',has_more)
        #delAwemeList(ret['aweme_list'])
        #print('urls:',ret['aweme_list'][0]['video']['play_addr']['url_list'][0])
        return (max_cursor,has_more)

def start():
    max_cursor, has_more = getDyUrl(0)
    while has_more:
        time.sleep(random.randint(1,3))
        max_cursor, has_more = getDyUrl(max_cursor)

start()
相关文章
|
3天前
|
存储 缓存 算法
Python性能优化:让你的代码更快更流畅
本文介绍了优化 Python 代码性能的十二个技巧,包括使用内置数据类型和函数、避免不必要的循环和递归、使用局部变量、利用生成器节省内存、选择合适的数据结构、并行和并发处理、使用第三方库、缓存减少重复计算、代码剖析和性能分析、优化算法和数据结构以及减少 I/O 操作。通过这些方法,开发者可以编写出运行更快、效率更高的 Python 程序。
|
4天前
|
算法 程序员 开发工具
GitHub上新!14个Python项目详细教程(附完整代码)
Python作为程序员的宠儿,越来越得到人们的关注,使用Python进行应用程序开发的也越来越多。 今天给小伙伴们分享的这份项目教程完整代码已上传至GitHub,你可以选择跟着这份教程一段一段的手敲出来这几个项目,也可以直接从GitHub上copy下来。
|
6天前
|
开发工具 Python
【分享Python代码】图片转化为素描画
【分享Python代码】图片转化为素描画
22 2
|
6天前
|
数据库连接 Python
如何提高python程序代码的健壮性
在编程的时候,我们难免会遇到一些不可靠的情况,比如网络请求失败,数据库连接超时等等。这些不确定性会让我们的程序容易出现各种错误和异常。那么如何来增加程序的容错性和健壮性呢? 可能大多数人会想到使用try except来进行异常捕捉进行失败重试(Retry)。虽然try-escept一个非常常见和有效的方式来增强程序稳定性,但是可能一不小心就会造成栈溢出。 所以接下来我就来介绍一个另外的一个专门用于失败重试的库:retrying。
|
7天前
|
机器学习/深度学习 缓存 人工智能
令你膛目结舌的代码技巧 —— Python编程代码技巧
令你膛目结舌的代码技巧 —— Python编程代码技巧
21 2
|
7天前
|
存储 Python
10个小技巧,让你的 Python 代码更加优雅~
10个小技巧,让你的 Python 代码更加优雅~
10个小技巧,让你的 Python 代码更加优雅~
|
7天前
|
数据采集 XML 程序员
最新用Python做垃圾分类_python垃圾分类代码用key和format,5年经验Python程序员面试27天
最新用Python做垃圾分类_python垃圾分类代码用key和format,5年经验Python程序员面试27天
最新用Python做垃圾分类_python垃圾分类代码用key和format,5年经验Python程序员面试27天
|
7天前
|
数据采集 机器学习/深度学习 人工智能
最新用python代码画爱心,来自程序猿的浪漫~_python画爱心代码(1),2024年最新面试简历模板免费
最新用python代码画爱心,来自程序猿的浪漫~_python画爱心代码(1),2024年最新面试简历模板免费
最新用python代码画爱心,来自程序猿的浪漫~_python画爱心代码(1),2024年最新面试简历模板免费
|
7天前
|
测试技术 开发工具 iOS开发
Python如何快速定位最慢的代码?_pycharm找到执行时间长的代码(2)
Python如何快速定位最慢的代码?_pycharm找到执行时间长的代码(2)
Python如何快速定位最慢的代码?_pycharm找到执行时间长的代码(2)
|
7天前
|
数据采集 数据挖掘 测试技术
Python如何快速定位最慢的代码?_pycharm找到执行时间长的代码(1)
Python如何快速定位最慢的代码?_pycharm找到执行时间长的代码(1)
Python如何快速定位最慢的代码?_pycharm找到执行时间长的代码(1)