douyin-abogus-reverse
Overview
Douyin Web side generally uses a feature calleda_bogussignature parameters. It is essentially a dynamically generated check value used to block requests that are not initiated by the browser. Simply put, the server will use a set of rules hidden in the security SDK to verify this value. If the verification fails, the request will be rejected.
This article will start from a complete reverse practice perspective, dismantle key steps such as environment simulation, anti-detection Hook, SDK loading, XHR simulation trigger encryption, etc., and finally provide a reusable Python + JavaScript solution, allowing you to generate legal code locallya_bogusparameter.
Web analysis
Before starting the reverse engineering, we first confirm from the browser sidea_bogusThe generation location and dependencies. Here is the Douyin personal homepage video list interface as an example:
-
Location encryption request Open Chrome Developer Tools and switch to
Networkpanel, filterXHR/FetchTypes of requests that can be easily found carrya_bogusParameter interface (such as/aweme/v1/web/aweme/post/)。 -
Find the encryption entrance This type of encryption is usually not placed in the business code, but is assembled by the security module before the request is initiated. Set XHR breakpoints directly on the request, or search globally
a_boguskeyword, you will find that the encryption entrance is located in a file calledbdms(ByteDance Security SDK) module. -
Analyze dependencies
bdmsIt is not a piece of code that can run independently. When it loads, it will detect a lot of browser environment, including:
- Whether the DOM API exists (e.g.
document.createElement) - Browser global object (
window、navigator、screenwait) - Whether various functions are native (via
Function.prototype.toStringjudge)
This shows that simply cutting outbdmsThe code cannot be run directly in the Node.js or Python environment - we must first build a realistic enough browser sandbox.
Core technical route
This reverse engineering adopts the idea of "Environment completion first + Dynamic agent to cover up":
-
Global environment simulation Complete
window、document、navigatorWait for the key properties and methods of the browser global object tobdmsIt will not report an error as soon as it is started. -
Function Native disguise
bdmswill passfn.toString()Check if a function is still[native code]state. we need to rewriteFunction.prototype.toString, and mark the fake function withnativemark. -
Dynamic Agent Monitoring use
ProxymonitorbdmsProperty access to environment objects. When you encounter uncompleted attributes, you can see the logs in the console and supplement them as needed to avoid writing in a large number of unused attributes at the beginning. -
SDK loading and calling Inject organized
bdmscode, call its initialization method, and then simulateXMLHttpRequestThe encryption process is triggered bywindow.a_bogusGet the generated parameters.
Core code implementation
The following is a complete browser environment simulation scriptenv.js, which combines environment completion, Native function camouflage, dynamic proxy and SDK initialization logic.
Note: You need to extract from Douyin page
bdmsThe core code is saved asbdms.jsand place it in the same directory,env.jswill pass in the endrequire('./bdms')Load it.
Python side call
aboveenv.jsRuns in Node.js environment and exposesget_abmethod. Python side can be usedPyExecJSto call it and construct the complete request.
Complete workflow
-
Extract bdms code In Chrome Developer Tools
SourcesSearch in panelbdms.init, copy the relevant code block and save it asbdms.js. Be careful not to omit any dependent modules (if the code is split into multiple files, they need to be merged in the same scope). -
Configure environment information Place the above
env.jsand in Python scriptwebid、sec_user_idand replace cookies with your own valid data. These can be copied directly from the Network panel after logging into Douyin in the browser. -
Run the build Make sure that the Node.js and Python environments are correct. Execute the Python script to output valid
a_bogusinterface response.
Technical difficulties and solutions
Notes
-
bdms version update Douyin will upgrade the security SDK from time to time. Once discovered
a_bogusThe signature is invalid and the latest one needs to be extracted from the page again.bdmscode and possibly adjust environment scripts. -
Cookie Validity Signing cookies that rely on login status (e.g.
s_v_web_id、ttwidwait). These cookies have a certain validity period and are associated with the server session, and need to be retrieved after expiration. -
WebID and User‑Agent consistency
webidIt is generated based on the browser fingerprint (including User-Agent, screen resolution, etc.). When replacing, make sureenv.jsInformation such as User‑Agent in thewebidThe current browser is completely consistent, otherwise the signature may fail to be verified. -
Request frequency control Even with the correct signature, too fast a request frequency may still trigger risk control. It is recommended to add random delays between requests and try to avoid using it in high-concurrency scenarios.

