Python module with an attached reverse-engineering study of the X (former Twitter) x-client-transaction-id and x-xp-forwarded-for request headers.
This repository represents Episode 1 of a multi-part analysis of Twitter/X login-flow protections.
Be sure to follow me on Medium and Github in order to prevent loosing next episodes.
Next one is going to be about the first antibot challenge.
Be sure to check out LEARN.md in order to understand how this has been made as well as the full article on Medium
pip install twitter-generatorOr from source:
git clone https://github.com/aster-go/twitter-generator.git
cd twitter-generator
pip install -e .from twitter_generator import ClientTransactionGenerator
generator = ClientTransactionGenerator(
ondemand_file=ondemand_js_content, # Dynamic js file content
home_page=home_page_html # Loaded homepage content
)
transaction_id = generator.generate(
"GET", # Method you are going to use
"/api/1.1/statuses/user_timeline.json" # Route of the request
)
print(transaction_id)from twitter_generator import XPForwardedForGenerator
generator = XPForwardedForGenerator(
guest_id="v1%3A176824413470818950" # Your guest_id cookie
)
env = {
'userAgent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36',
'hasBeenActive': False,
'webdriver': False
}
token = generator.generate(env)
print(token)
# Or decrypting it via
generator.decode(
token,
generator._derive_key_from_guest_id(guest_id)
)class ClientTransactionGenerator:
def __init__(self, ondemand_file: str, home_page: str)
def generate(self, method: str, path: str) -> strclass XPForwardedForGenerator:
def __init__(self, guest_id: Optional[str] = None)
def generate(self, env: Dict) -> str
def decode(self, token: str, key: Optional[bytes] = None) -> Dict
def decode_with_key(self, token: str, key_hex: str) -> Dict
def decode_with_guest_id(self, token: str, guest_id: str) -> Dict
@staticmethod
def extract_guest_id_from_cookie(
cookie_string: str
) -> Optional[str]Be sure to check the
MIT License. See LICENSE for details.
