This repository documents the reverse engineering of the Trip.com Phantom-Token generation logic. By analyzing the underlying Stack-Based Virtual Machine (JSVMP), I managed to reconstruct the cryptographic and fingerprinting logic to run natively, avoiding the need of using a browser.
- Localizing the Token Generation: Using the browser's DevTools, the phantom-token
generation was traced to a single call:
var C = window.signature(o.data);, whereo.datais the request payload. Notably, an empty payload is also accepted and will return a valid token. - VM Sandboxing: Isolated the JSVMP environment and provided mocked browser globals
(
window,document,location,navigatorandscreen) on-demand via a Proxy that intercepts property accesses returningundefinedas they are requested by the VM (see thewatchmethod in./js/vm_logged.js), until the full token generation flow completed successfully. - High-Level Hooking: Logged inputs and outputs of critical handlers, the closest to the JavaScript runtime:
func_call&new(Object instantiation and API calls)- Bitwise & Arithmetic operations
- String manipulation logic
- Trace Export: Generated a comprehensive execution trace in
.txtformat vianode ./js/vm_logged.js > out.txt. - Pattern Recognition: Analyzed the trace from top to bottom (from line 0 to the end) to identify the underlying algorithms and reconstruct the js logic.
node ./js/vm_logged.js > out.txtuv venv venv
source venv/bin/activate
uv pip install -r requirements.txt
python main.pyDisclaimer: This project is for educational and research purposes only. Use of this tool must comply with the target website's Terms of Service and applicable data privacy laws.