Twitter / X Headers Generator
Python module with an attached reverse-engineering study of the X (former Twitter) x-client-transaction-id and x-xp-forwarded-for request headers.
Series Context
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.
Learning
Be sure to check out LEARN.md in order to understand how this has been made as well as the full article on Medium
Table of Contents
Installation
pip install twitter-generator
Or from source:
git clone https://github.com/GlizzyKingDreko/twitter-generator.git
cd twitter-generator
pip install -e .
Quick Start
X-Client-Transaction-Id
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)
X-XP-Forwarded-For
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)
)
API Reference
ClientTransactionGenerator
class ClientTransactionGenerator:
def __init__(self, ondemand_file: str, home_page: str)
def generate(self, method: str, path: str) -> str
XPForwardedForGenerator
class 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]
Implementations in Other Languages
Be sure to check the
License
MIT License. See LICENSE for details.
Author
If you found this project helpful or interesting, consider starring the repo and following me for more security research and tools, or buy me a coffee to keep me up.
Metadata
Release files for twitter-generator 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| twitter_generator-1.0.0.tar.gz | 25.9 kB | Without provenance | Details for twitter_generator-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| twitter_generator-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for twitter_generator-1.0.0-py3-none-any.whl |
Total release size: 39.0 kB
Release files / twitter_generator-1.0.0.tar.gz
| Download URL | twitter_generator-1.0.0.tar.gz |
|---|---|
| Size | 25.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a8a930a172377e1ad0af4df137517d9fe12db4c889cd49078685f223b9c44bae
|
|
BLAKE2b-256 checksum How to use checksums |
0df5fef71f8a436bbba55eb0cf9b1ea180f7a1d71969c8e976d37d75adae5e25
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Release files / twitter_generator-1.0.0-py3-none-any.whl
| Download URL | twitter_generator-1.0.0-py3-none-any.whl |
|---|---|
| Size | 13.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d39d87d752963d7becdf310598958b55c3c6ec37430182b03e3c54d6e5b5e029
|
|
BLAKE2b-256 checksum How to use checksums |
69cabf999c3c62a40574c803f0f9020768cbe160181b886376f8c12c9ff4555c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Security for twitter-generator 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.