init
This commit is contained in:
+224
@@ -0,0 +1,224 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Bria AI autoreg (platform.bria.ai) -> api_token
|
||||
|
||||
Flow (verified 31.10.2026):
|
||||
1) Firebase signUp POST identitytoolkit.googleapis.com/v1/accounts:signUp?key=<FB_KEY>
|
||||
2) session login POST https://platform-api.bria.ai/session/login {idToken}
|
||||
-> cookie session_production (Domain=.bria.ai)
|
||||
3) create org POST https://platform-api.bria.ai/create_organization/
|
||||
{name, display_name, org_type:"personal"} -> uid
|
||||
4) create api key POST https://api.bria.ai/v2/organizations/api-keys/create
|
||||
headers: Cookie, Org-Id: <uid>, App-Name: platform
|
||||
{name, display_name, key_type:"production"} -> api_token (32 hex)
|
||||
|
||||
No email verification needed: token works immediately after signup.
|
||||
|
||||
Usage:
|
||||
python bria_farm.py --n 5 # 5 accounts
|
||||
python bria_farm.py --n 20 --workers 4 --proxy round
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
import secrets
|
||||
import string
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
|
||||
import requests
|
||||
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
BANK = os.path.join(HERE, "bank.jsonl")
|
||||
DONE = os.path.join(HERE, "done_emails.txt")
|
||||
FB_KEY_FILE = os.path.join(HERE, "fbkey.txt")
|
||||
|
||||
FB_KEY = open(FB_KEY_FILE).read().strip() if os.path.exists(FB_KEY_FILE) else ""
|
||||
FB_SIGNUP = "https://identitytoolkit.googleapis.com/v1/accounts:signUp?key="
|
||||
PLAT = "https://platform-api.bria.ai"
|
||||
API = "https://api.bria.ai/v2"
|
||||
ENGINE = "https://engine.prod.bria-api.com"
|
||||
|
||||
UA = ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
|
||||
"(KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36")
|
||||
|
||||
PROXIES = [p.strip() for p in os.environ.get("BRIA_PROXIES", "").split(",") if p.strip()]
|
||||
if os.environ.get("BRIA_DIRECT", "1") == "1":
|
||||
PROXIES.append(None) # direct last: Firebase IP quota burns fast without rotation
|
||||
|
||||
_lock = threading.Lock()
|
||||
|
||||
|
||||
def log(*a):
|
||||
with _lock:
|
||||
print(time.strftime("%H:%M:%S"), *a, flush=True)
|
||||
|
||||
|
||||
def rand_email():
|
||||
dom = random.choice(["t-online.de", "gmail.com", "web.de", "gmx.de", "mail.ru"])
|
||||
tag = "bria" + "".join(random.choices(string.ascii_lowercase + string.digits, k=12))
|
||||
return f"{tag}@{dom}"
|
||||
|
||||
|
||||
def rand_pw():
|
||||
return "".join(random.choices(string.ascii_letters + string.digits, k=10)) + "!A9"
|
||||
|
||||
|
||||
def px(proxy):
|
||||
if not proxy:
|
||||
return None
|
||||
return {"http": proxy, "https": proxy}
|
||||
|
||||
|
||||
class Account:
|
||||
def __init__(self, proxy=None):
|
||||
self.proxy = proxy
|
||||
self.s = requests.Session()
|
||||
self.s.headers.update({"User-Agent": UA, "App-Name": "platform",
|
||||
"Origin": "https://platform.bria.ai",
|
||||
"Referer": "https://platform.bria.ai/"})
|
||||
if proxy:
|
||||
self.s.proxies.update(px(proxy))
|
||||
self.email = None
|
||||
self.password = None
|
||||
self.id_token = None
|
||||
self.org_uid = None
|
||||
self.api_token = None
|
||||
|
||||
def signup(self):
|
||||
self.email = rand_email()
|
||||
self.password = rand_pw()
|
||||
r = self.s.post(FB_SIGNUP + FB_KEY, json={
|
||||
"email": self.email, "password": self.password, "returnSecureToken": True
|
||||
}, timeout=40)
|
||||
if r.status_code != 200:
|
||||
raise RuntimeError(f"fb_signup {r.status_code} {r.text[:160]}")
|
||||
self.id_token = r.json()["idToken"]
|
||||
|
||||
def drain_email_verify(self):
|
||||
"""Firebase verification mail is optional; ignore failures."""
|
||||
try:
|
||||
self.s.post("https://identitytoolkit.googleapis.com/v1/accounts:sendOobCode?key=" + FB_KEY,
|
||||
json={"requestType": "VERIFY_EMAIL", "idToken": self.id_token}, timeout=30)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def login(self):
|
||||
r = self.s.post(PLAT + "/session/login", json={"idToken": self.id_token}, timeout=40)
|
||||
if r.status_code != 200:
|
||||
raise RuntimeError(f"session_login {r.status_code} {r.text[:160]}")
|
||||
|
||||
def create_org(self):
|
||||
name = "ws" + secrets.token_hex(6)
|
||||
r = self.s.post(PLAT + "/create_organization/", json={
|
||||
"name": name, "display_name": "Bria Workspace", "org_type": "personal"
|
||||
}, timeout=45)
|
||||
if r.status_code != 200:
|
||||
raise RuntimeError(f"create_org {r.status_code} {r.text[:160]}")
|
||||
j = r.json()
|
||||
if not j.get("uid"):
|
||||
raise RuntimeError(f"create_org_nouid {j}")
|
||||
self.org_uid = j["uid"]
|
||||
|
||||
def create_key(self):
|
||||
r = self.s.post(API + "/organizations/api-keys/create",
|
||||
headers={"Org-Id": self.org_uid},
|
||||
json={"name": "default", "display_name": "Default",
|
||||
"key_type": "production"}, timeout=45)
|
||||
if r.status_code != 200:
|
||||
raise RuntimeError(f"create_key {r.status_code} {r.text[:160]}")
|
||||
self.api_token = r.json()["result"]["api_key"]["api_token"]
|
||||
|
||||
def verify_key(self, timeout=90):
|
||||
r = self.s.post(ENGINE + "/v2/image/generate/lite",
|
||||
headers={"api_token": self.api_token},
|
||||
json={"prompt": "a small red cube on white", "sync": True},
|
||||
timeout=timeout)
|
||||
ok = r.status_code == 200 and "image_url" in r.text
|
||||
return ok, r.status_code
|
||||
|
||||
def run(self):
|
||||
self.signup()
|
||||
self.login()
|
||||
self.create_org()
|
||||
self.create_key()
|
||||
return self.api_token
|
||||
|
||||
|
||||
def load_done():
|
||||
if not os.path.exists(DONE):
|
||||
return set()
|
||||
with open(DONE, encoding="utf-8") as f:
|
||||
return {l.strip() for l in f if l.strip()}
|
||||
|
||||
|
||||
def record(acc, status, note=""):
|
||||
row = {"email": acc.email, "password": acc.password, "api_token": acc.api_token,
|
||||
"org_uid": acc.org_uid, "status": status, "note": note,
|
||||
"proxy": acc.proxy or "direct", "ts": int(time.time())}
|
||||
with _lock:
|
||||
with open(BANK, "a", encoding="utf-8") as f:
|
||||
f.write(json.dumps(row, ensure_ascii=False) + "\n")
|
||||
with open(DONE, "a", encoding="utf-8") as f:
|
||||
f.write(acc.email + "\n")
|
||||
|
||||
|
||||
def worker(idx, mode):
|
||||
proxies_try = [None]
|
||||
if mode == "round":
|
||||
proxies_try = [PROXIES[idx % len(PROXIES)], None, None]
|
||||
elif mode == "direct":
|
||||
proxies_try = [None, None, None]
|
||||
elif mode.startswith("http"):
|
||||
proxies_try = [mode, None, None]
|
||||
|
||||
last = None
|
||||
for attempt, proxy in enumerate(proxies_try):
|
||||
acc = Account(proxy)
|
||||
try:
|
||||
acc.run()
|
||||
ok, code = acc.verify_key()
|
||||
record(acc, "ok" if ok else "key_nogen", f"gen={code}")
|
||||
log(f"[+] {acc.email} -> {acc.api_token} gen={code} try={attempt}")
|
||||
return True
|
||||
except Exception as e:
|
||||
last = e
|
||||
log(f"[-] {acc.email or '?'} try{attempt} fail: {str(e)[:110]}")
|
||||
time.sleep(2)
|
||||
if last is not None:
|
||||
acc2 = Account(None)
|
||||
acc2.email = getattr(locals().get('acc'), 'email', None) or rand_email()
|
||||
record(acc2, "fail", str(last)[:200])
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("--n", type=int, default=5)
|
||||
ap.add_argument("--workers", type=int, default=3)
|
||||
ap.add_argument("--proxy", default="round", help="round | direct | URL")
|
||||
args = ap.parse_args()
|
||||
|
||||
if not FB_KEY:
|
||||
print("no fbkey.txt", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
t0 = time.time()
|
||||
ok = 0
|
||||
with ThreadPoolExecutor(max_workers=args.workers) as ex:
|
||||
futs = [ex.submit(worker, i, args.proxy) for i in range(args.n)]
|
||||
for f in futs:
|
||||
try:
|
||||
ok += 1 if f.result() else 0
|
||||
except Exception:
|
||||
pass
|
||||
log(f"DONE ok={ok}/{args.n} in {int(time.time()-t0)}s bank={BANK}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user