Overview
bet365 actively rotates their obfuscated JavaScript code, presenting a unique challenge for reverse engineering efforts. The obfuscation patterns, variable names, and even control flow change periodically, requiring systematic tracking and adaptive deobfuscation strategies.What is Code Rotation?
Code rotation refers to bet365’s practice of periodically changing their obfuscated JavaScript while maintaining the same underlying functionality. This creates multiple “versions” of the same code, each with different obfuscation patterns.Code rotation is a defensive measure against reverse engineering. By frequently changing the obfuscation, bet365 makes it harder to maintain working deobfuscation tools.
Rotation Factors
bet365’s obfuscated code appears to rotate based on several factors:Geographic Location (IP Address)
Different geographic regions may receive different versions of the obfuscated code:- Users from different countries report seeing different variable names
- Same request from different IPs yields different obfuscated code
Time-based Rotation
The code appears to rotate over time, possibly on a schedule:- New versions appear every few days to weeks
- Not strictly scheduled - appears somewhat random
- Major updates seem to correlate with bet365 deployments
User Agent / Browser Version
Different browsers or browser versions might receive different code:- Desktop vs Mobile
- Chrome vs Firefox vs Safari
- Different browser versions
Session-based Variation
Some rotation may be session-specific or user-specific:- A/B testing different obfuscation strategies
- Gradual rollout of new obfuscation versions
Tracking Rotation Strategy
The project implements a systematic approach to tracking code rotation:Timestamped Archive
All intercepted obfuscated code is saved with Unix timestamps:readme.md documents the purpose:
Automatic Saving
Thesave_obfuscated_code.py script automatically archives new obfuscated code:
- Intercept new obfuscated code in
output/directory - Copy to timestamped archive in
obfuscated/directory - Create symlink
obfuscated-new-raw.jspointing to latest version - Allows quick access to latest version while preserving history
Impact on Deobfuscation
Variable Name Changes
The most common rotation involves changing obfuscated variable names:_0x588211 → _0xa83f42) but the functionality remains the same.
Deobfuscation Challenge:
The variable mapping in Stage 2 needs constant updates:
Pattern Changes
Sometimes the obfuscation patterns themselves change:- Pattern A
- Pattern B
- Pattern C
CI/CD for Rotation Detection
The README outlines a plan for automated rotation detection:We understand that bet365 frequently updates their obfuscated code. To address this, we will:
- Establish a CI/CD pipeline to identify precisely when changes are made.
- Maintain a functional backup script to ensure the deobfuscation process continues to work, even when bet365 updates their code.
Proposed CI/CD Pipeline
Handling Rotation: Best Practices
1. Maintain a Version Database
Keep structured metadata about each version:2. Automated Mapping Discovery
Develop heuristics to automatically discover variable mappings:3. Differential Analysis
Compare new versions against known versions to identify changes:4. Fallback Strategies
Implement graceful degradation when encountering unknown versions:Strategy 1: Use Last Known Good Configuration
Strategy 1: Use Last Known Good Configuration
If deobfuscation fails with new code, serve the last successfully deobfuscated version:
Strategy 2: Partial Deobfuscation
Strategy 2: Partial Deobfuscation
Apply only the transformation stages that succeed:
Strategy 3: Pattern Matching
Strategy 3: Pattern Matching
Use pattern matching to identify semantic equivalents across versions:
Development Workflow for Rotation
When a new rotation is detected:Update Variable Mappings
Modify
refactor-obfuscated-code-jscodeshift-2.js with new mappings based on semantic analysis.Update Pattern Matchers
If new obfuscation patterns are found, create new transformer stages or update existing ones.
Monitoring Rotation Frequency
Track rotation patterns over time:Future Improvements
Planned enhancements to handle rotation more effectively:
- Machine learning to predict variable mappings
- Semantic analysis to identify functionally equivalent code patterns
- Automated variable mapping generation from execution traces
- Multi-version deobfuscation support (handle multiple versions simultaneously)
- Real-time A/B testing detection
Challenges
Variable Explosion
With over 200 variable mappings needed and frequent rotation, maintenance becomes challenging:Breaking Changes
Occasionally, bet365 makes structural changes that break the entire deobfuscation pipeline:- New control flow obfuscation
- Different function wrapping
- Changed module system
- Additional encoding layers
Geographic Testing
Testing from multiple geographic locations requires:- VPN/proxy infrastructure
- Coordinated testing
- Version correlation across locations
Resources
Rotation Archive
All historical versions in
mitmproxy/src/javascript/obfuscated/Save Script
save_obfuscated_code.py for archiving new versionsVariable Mappings
refactor-obfuscated-code-jscodeshift-2.js contains all mappingsCI/CD Plan
See README.md for planned automation
Next Steps
- Learn about the Deobfuscation Process that needs updating for rotations
- Understand AST Manipulation to create new transformers
- Explore mitmproxy Integration for capturing new versions
