using this code i want you to tell me what the bda is and how they are gotten: import…
- User
using this code i want you to tell me what the bda is and how they are gotten:
import requests import random import time from urllib.parse import urlsplit from requests.packages.urllib3.exceptions import InsecureRequestWarning
For image manipulation
from PIL import Image from io import BytesIO
Modules for encryption and decryption
from Crypto.Cipher import AES import base64 import hashlib import json import string import re import execjs import secrets
Default params
DEFAULT_USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0"
Decides if images should be downloaded over the specified proxy or not
Turning this off improves speed
PROXY_IMAGE_DOWNLOADS = False
Load .js module for murmur3 related functions (used in BDA/fingerprint2 generation)
with open("fp.js") as f: mm3js = execjs.compile(f.read())
Create dict of fields from full token string
def parse_full_token(token): token = "token=" + token assoc = {}
for field in token.split("|"): s = field.partition("=") key, value = s[0], s[-1] assoc[key] = value return assocGet random float value
def get_float(): return random.uniform(0, 1)
Get random X,Y click coordinates for button
def get_xy(): start_pos = [117, 248] button_size = [90, 28] new_pos = [ start_pos[0] + random.randint(1, button_size[0]), start_pos[1] + random.randint(1, button_size[1])] return new_pos
CryptoJS AES Encryption
def cryptojs_encrypt(data, key): # Padding data = data + chr(16-len(data)%16)*(16-len(data)%16)
salt = b"".join(random.choice(string.ascii_lowercase).encode() for x in range(8)) salted, dx = b"", b"" while len(salted) < 48: dx = hashlib.md5(dx+key.encode()+salt).digest() salted += dx key = salted[:32] iv = salted[32:32+16] aes = AES.new(key, AES.MODE_CBC, iv) encrypted_data = {"ct": base64.b64encode(aes.encrypt(data.encode())).decode("utf-8"), "iv": iv.hex(), "s": salt.hex()} return json.dumps(encrypted_data, separators=(',', ':'))CryptoJS AES Decryption
def cryptojs_decrypt(data, key): data = json.loads(data) dk = key.encode()+bytes.fromhex(data["s"])
md5 = [hashlib.md5(dk).digest()] result = md5[0] for i in range(1, 3+1): md5.insert(i, hashlib.md5((md5[i-1]+dk)).digest()) result += md5[i] aes = AES.new(result[:32], AES.MODE_CBC, bytes.fromhex(data["iv"])) data = aes.decrypt(base64.b64decode(data["ct"])) return dataclass FunCaptchaChallenge(): images = None metadata = {}
## Set up challenge object def __init__(self, session, bda, full_token, session_token, region, lang, analytics_tier, download_images=True): self.session = session self.bda = bda self.full_token = full_token self.session_token = session_token self.region = region self.lang = lang self.analytics_tier = analytics_tier self.download_images = download_images self.send_analytics(render_type="canvas", sid=self.region, category="Site URL", analytics_tier=self.analytics_tier, session_token=self.session_token, action=self.session.page_url) self.reload(status="init") ## Reload the challenge def reload(self, status): r_resp = self.session.r.post( url=f"{self.session.service_url}/fc/gfct/", headers={ "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", "cache-control": "no-cache", "X-Requested-ID": self.get_request_id(), "Origin": self.session.service_url, "Referer": self.session.service_url + "/fc/gc"}, data={ "analytics_tier": self.analytics_tier, "render_type": "canvas", "lang": self.lang, "sid": self.region, "token": self.session_token, "data[status]": status}).json() self.metadata = {} self.token = r_resp["challengeID"] self.id = r_resp["challengeURL"] self.timeout = r_resp["sec"] self.angle = 51.4 self.encrypted_mode = bool(r_resp["game_data"]["customGUI"]["encrypted_mode"]) self.image_urls = r_resp["game_data"]["customGUI"]["_challenge_imgs"] if self.image_urls: ## Preload images if self.download_images: self.images = list(map(self.download_image, self.image_urls)) self.send_analytics(render_type="canvas", sid=self.region, category="loaded", game_token=self.token, analytics_tier=self.analytics_tier, game_type=1, session_token=self.session_token, action="game loaded") ## Get encryption key, if needed if self.encrypted_mode: self.key = self.get_encryption_key() self.send_analytics(render_type="canvas", sid=self.region, category="begin app", game_token=self.token, analytics_tier=self.analytics_tier, game_type=1, session_token=self.session_token, action="user clicked verify") ## This is some sort of weird metadata that's sent in ## the X-Requested-ID header def update_metadata(self, origin, value=None): if origin == "ekey" and not self.metadata.get("sc"): self.metadata["sc"] = get_xy() elif origin == "guess" and not self.metadata.get("dc"): self.metadata["dc"] = get_xy() elif origin == "lastguess" and value: self.metadata["ech"] = "{:.2f}".format(value) ## Send analytics logging request def send_analytics(self, **kwargs): an_resp = self.session.r.post( url=f"{self.session.service_url}/fc/a/", headers={ "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", "cache-control": "no-cache", "X-Requested-ID": self.get_request_id(), "Origin": self.session.service_url, "Referer": self.session.service_url + "/fc/gc"}, data={ **kwargs}).json() return an_resp.get("logged") ## Submit guesses def submit_guesses(self, guesses): data = ",".join(map(lambda x: "{:.2f}".format(x), guesses)) encrypted_data = cryptojs_encrypt(data, self.session_token) if len(guesses) == len(self.image_urls): self.update_metadata(origin="lastguess", value=guesses[-1]) else: self.update_metadata(origin="guess") sg_resp = self.session.r.post( url=f"{self.session.service_url}/fc/ca/", headers={ "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", "cache-control": "no-cache", "X-Requested-ID": self.get_request_id(), "Origin": self.session.service_url, "Referer": self.session.service_url + "/fc/gc"}, data={ "game_token": self.token, "session_token": self.session_token, "sid": self.region, "guess": encrypted_data, "analytics_tier": self.analytics_tier}).json() ## Update encryption key if response contains one if "decryption_key" in sg_resp: self.key = sg_resp["decryption_key"] ## Return status of challenge return sg_resp.get("solved") ## Download image data from url def download_image(self, image_url): i_resp = (self.session.r if PROXY_IMAGE_DOWNLOADS else requests).get( url=image_url, headers={ "Referer": f"{self.session.service_url}/fc/apps/canvas/{self.id}/?meta=6"}) return i_resp.content ## Get encryption key for the first image def get_encryption_key(self): self.update_metadata(origin="ekey") ek_resp = self.session.r.post( url=f"{self.session.service_url}/fc/ekey/", headers={ "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", "cache-control": "no-cache", "X-Requested-ID": self.get_request_id(), "Origin": self.session.service_url, "Referer": f"{self.session.service_url}/fc/gc"}, data={ "game_token": self.token, "sid": self.region, "session_token": self.session_token}).json() return ek_resp["decryption_key"] ## Generates value for X-Requested-ID header def get_request_id(self): key = "REQUESTED" + self.session_token + "ID" data = json.dumps(self.metadata, separators=(',', ':')) return cryptojs_encrypt(data, key) def get_iter(self): guesses = [] images_enabled = self.download_images for img_data in self.images or self.image_urls: img = None if images_enabled: img_data = cryptojs_decrypt(img_data, self.key) img = Image.open(BytesIO(img_data)) def submit(guess): guesses.append(guess) return self.submit_guesses(guesses) yield img, submit - Assistant
In this code, the "bda" is an encrypted string that represents browser data for identification. It is generated using the
get_browser_data()function from theFunCaptchaSessionclass. Thebdais obtained by calling theget_browser_data()function and passing it as a parameter when creating a new instance of theFunCaptchaChallengeclass.The
bdais used by the FunCaptcha service to identify and authenticate the browser that is solving the challenge. It contains various pieces of browser information such as user agent, screen resolution, language, plugin keys, etc. This helps the FunCaptcha service in verifying that the request is coming from a legitimate browser and not from a bot or automated script.The
get_browser_data()function calculates an encryption key using the user agent and current timestamp. It then generates a list of browser data and hashes it using the Murmur3 algorithm. The hashed data, along with other additional information, is then encrypted using AES and encoded in base64. The resulting string is thebda.Overall, the
bdaserves as a unique identifier for the browser and helps ensure the security and integrity of the FunCaptcha challenge process. - User
please rewrite the get browser data hashing using mmh3 python library
- Assistant
Certainly! The code can be rewritten to use the
mmh3library for hashing instead of theexecjsmodule.