262 lines
9.9 KiB
Python
262 lines
9.9 KiB
Python
"""Composio farm wave: signup (or login) -> OTP -> passkey skip -> ck_ key -> bank.
|
|
|
|
Usage: python wave.py --pool pool.txt --start 7 --count 5 [--bank bank/accounts.jsonl]
|
|
Each line of pool: email:imap_password
|
|
"""
|
|
import argparse
|
|
import imaplib
|
|
import json
|
|
import os
|
|
import random
|
|
import re
|
|
import string
|
|
import sys
|
|
import time
|
|
from email.utils import parsedate_to_datetime
|
|
|
|
import email as emod
|
|
from playwright.sync_api import sync_playwright
|
|
|
|
CHROME = "C:/Program Files/Google/Chrome/Application/chrome.exe"
|
|
if not os.path.exists(CHROME):
|
|
CHROME = os.path.expandvars(r"%LOCALAPPDATA%\Google\Chrome\Application\chrome.exe")
|
|
DASH = "https://dashboard.composio.dev"
|
|
ENTRY = DASH + "/f/~/connect/clients"
|
|
OUT = "C:/Users/User/tmp/composio"
|
|
IMAP_HOST = "secureimap.t-online.de"
|
|
|
|
|
|
def log(*a):
|
|
print(*a, flush=True)
|
|
|
|
|
|
def gen_password():
|
|
sym = "@#$%*!?"
|
|
body = "".join(random.choice(string.ascii_letters + string.digits) for _ in range(8))
|
|
return body[:3] + random.choice(sym) + body[3:] + random.choice(sym) + str(random.randint(10, 99))
|
|
|
|
|
|
def imap_code(mail, pw, since_ts, tries=20, delay=9):
|
|
for _ in range(tries):
|
|
M = None
|
|
try:
|
|
M = imaplib.IMAP4_SSL(IMAP_HOST)
|
|
M.login(mail, pw)
|
|
M.select("INBOX")
|
|
typ, data = M.search(None, '(FROM "login.composio.dev")')
|
|
for i in reversed(data[0].split()[-5:]):
|
|
typ, msgd = M.fetch(i, "(RFC822)")
|
|
item = msgd[0]
|
|
raw = item[1] if isinstance(item, tuple) else None
|
|
if not raw:
|
|
continue
|
|
m = emod.message_from_bytes(raw)
|
|
try:
|
|
ts = parsedate_to_datetime(m["Date"]).timestamp()
|
|
except Exception:
|
|
ts = 0
|
|
if ts < since_ts - 180:
|
|
continue
|
|
body = b""
|
|
if m.is_multipart():
|
|
for part in m.walk():
|
|
if part.get_content_type() == "text/plain":
|
|
body = part.get_payload(decode=True) or b""
|
|
break
|
|
else:
|
|
body = m.get_payload(decode=True) or b""
|
|
codes = re.findall(r"\b(\d{6})\b", (body or b"").decode("utf-8", "ignore"))
|
|
if codes:
|
|
M.logout()
|
|
return codes[-1]
|
|
except Exception as e:
|
|
log(" imap:", str(e)[:70])
|
|
finally:
|
|
try:
|
|
if M:
|
|
M.logout()
|
|
except Exception:
|
|
pass
|
|
time.sleep(delay)
|
|
return None
|
|
|
|
|
|
def first_name_from(mail):
|
|
base = mail.split("@")[0]
|
|
return base[:12] or "User"
|
|
|
|
|
|
def run_one(br, mail, imap_pass, bank_path):
|
|
t0 = time.time()
|
|
password = gen_password()
|
|
try:
|
|
for line in open(bank_path, encoding="utf-8"):
|
|
rec = json.loads(line)
|
|
if rec.get("email", "").lower() == mail.lower() and rec.get("password"):
|
|
password = rec["password"]
|
|
break
|
|
except Exception:
|
|
pass
|
|
ctx = br.new_context(viewport={"width": 1280, "height": 900}, locale="de-DE")
|
|
pg = ctx.new_page()
|
|
pg.set_default_timeout(25000)
|
|
res = {"email": mail, "imap_pass": imap_pass, "password": password, "ok": False, "stage": "start"}
|
|
try:
|
|
pg.goto(ENTRY, wait_until="domcontentloaded")
|
|
pg.wait_for_timeout(3500)
|
|
# switch to signup route when login form shown
|
|
if pg.locator('input[name="first_name"]').count() == 0 and pg.locator('a[href*="/sign-up"]').count() > 0:
|
|
log(" [0] opening /sign-up")
|
|
try:
|
|
pg.locator('a[href*="/sign-up"]').first.click()
|
|
pg.wait_for_timeout(4000)
|
|
except Exception as e:
|
|
log(" signup link err:", str(e)[:60])
|
|
log(" ->", pg.url[:90])
|
|
# signup form?
|
|
if pg.locator('input[name="first_name"]').count() > 0:
|
|
log(" [1] signup form")
|
|
pg.fill('input[name="first_name"]', first_name_from(mail))
|
|
if pg.locator('input[name="last_name"]').count():
|
|
pg.fill('input[name="last_name"]', "Schulz")
|
|
pg.fill('input[name="email"]', mail)
|
|
if pg.locator('input[name="password"]').count():
|
|
pg.fill('input[name="password"]', password)
|
|
pg.wait_for_timeout(300)
|
|
try:
|
|
pg.locator('button[type="submit"]').first.click()
|
|
except Exception:
|
|
pg.keyboard.press("Enter")
|
|
pg.wait_for_timeout(5000)
|
|
log(" ->", pg.url[:90])
|
|
# email step (skip when already on password step)
|
|
if (pg.locator('input[name="email"]').count() > 0 and "otp" not in pg.url
|
|
and "password" not in pg.url):
|
|
log(" [2] email step")
|
|
pg.fill('input[name="email"]', mail)
|
|
pg.wait_for_timeout(300)
|
|
try:
|
|
pg.locator('button[type="submit"]').first.click()
|
|
except Exception:
|
|
pg.keyboard.press("Enter")
|
|
pg.wait_for_timeout(4500)
|
|
log(" ->", pg.url[:90])
|
|
# password step
|
|
if pg.locator('input[name="password"]').count() > 0:
|
|
log(" [3] password step")
|
|
pg.fill('input[name="password"]', password)
|
|
pg.wait_for_timeout(300)
|
|
try:
|
|
pg.locator('button[type="submit"]').first.click()
|
|
except Exception:
|
|
pg.keyboard.press("Enter")
|
|
pg.wait_for_timeout(5500)
|
|
log(" ->", pg.url[:90])
|
|
# otp / verify
|
|
if pg.locator('[data-test="otp-input"]').count() > 0 or "radar-challenge" in pg.url or "verify" in pg.url:
|
|
log(" [4] otp step")
|
|
code = imap_code(mail, imap_pass, t0)
|
|
if not code:
|
|
res.update(stage="imap", err="no code")
|
|
log(" FAIL no code")
|
|
return res
|
|
box = pg.locator('[data-test="otp-input"]').first
|
|
box.click(force=True)
|
|
pg.keyboard.type(code, delay=140)
|
|
pg.wait_for_timeout(6500)
|
|
log(" ->", pg.url[:90], "code:", code)
|
|
# passkey skip
|
|
if "passkey" in pg.url or pg.locator('button[name="intent"][value="skip"]').count() > 0:
|
|
log(" [5] passkey skip")
|
|
try:
|
|
pg.locator('button[name="intent"][value="skip"]').first.click(timeout=8000)
|
|
except Exception:
|
|
try:
|
|
pg.get_by_text("Vorerst überspringen").click(timeout=5000)
|
|
except Exception:
|
|
pg.get_by_text("Skip").first.click(timeout=5000)
|
|
pg.wait_for_timeout(6500)
|
|
log(" ->", pg.url[:90])
|
|
for _ in range(14):
|
|
if "dashboard.composio.dev" in pg.url and "login." not in pg.url and "passkey" not in pg.url:
|
|
break
|
|
pg.wait_for_timeout(1500)
|
|
if "dashboard.composio.dev" not in pg.url:
|
|
res.update(stage="login", err=pg.url[:120])
|
|
log(" FAIL not in dashboard:", pg.url[:90])
|
|
return res
|
|
# key
|
|
ws = re.match(r"https://dashboard\.composio\.dev/([^/]+)/", pg.url + "/")
|
|
ws_name = ws.group(1) if ws else ""
|
|
tok = {"v": None}
|
|
|
|
def on_resp(r):
|
|
if "consumer.getToken" in r.url:
|
|
try:
|
|
b = r.text()
|
|
m = re.findall(r"ck_[A-Za-z0-9_\-]{16,}", b)
|
|
if m:
|
|
tok["v"] = m[0]
|
|
except Exception:
|
|
pass
|
|
|
|
pg.on("response", on_resp)
|
|
pg.goto(f"{DASH}/{ws_name}/~/connect/settings/sessions", wait_until="domcontentloaded")
|
|
pg.wait_for_timeout(6000)
|
|
if not tok["v"]:
|
|
try:
|
|
pg.locator('button:has-text("Copy")').first.click(timeout=6000)
|
|
pg.wait_for_timeout(900)
|
|
clip = pg.evaluate("() => navigator.clipboard.readText()")
|
|
if clip and clip.strip().startswith("ck_"):
|
|
tok["v"] = clip.strip()
|
|
except Exception:
|
|
pass
|
|
if not tok["v"]:
|
|
res.update(stage="key", err="no ck_ token")
|
|
log(" FAIL no key")
|
|
return res
|
|
res.update(ok=True, stage="done", api_key=tok["v"], workspace=ws_name,
|
|
elapsed=round(time.time() - t0, 1), ts=int(time.time()))
|
|
log(" OK key:", tok["v"][:10] + "..." + tok["v"][-4:], "ws:", ws_name)
|
|
except Exception as e:
|
|
res.update(stage="exc", err=str(e)[:160])
|
|
log(" EXC:", str(e)[:120])
|
|
finally:
|
|
try:
|
|
ctx.close()
|
|
except Exception:
|
|
pass
|
|
with open(bank_path, "a", encoding="utf-8") as f:
|
|
f.write(json.dumps(res, ensure_ascii=False) + "\n")
|
|
return res
|
|
|
|
|
|
def main():
|
|
ap = argparse.ArgumentParser()
|
|
ap.add_argument("--pool", default=OUT + "/pool_tonline.txt")
|
|
ap.add_argument("--start", type=int, default=0)
|
|
ap.add_argument("--count", type=int, default=3)
|
|
ap.add_argument("--bank", default=OUT + "/bank/accounts.jsonl")
|
|
ap.add_argument("--pause", type=int, default=20)
|
|
a = ap.parse_args()
|
|
lines = [l.strip() for l in open(a.pool, encoding="utf-8", errors="ignore") if ":" in l]
|
|
todo = lines[a.start:a.start + a.count]
|
|
log("wave:", len(todo), "accounts from idx", a.start)
|
|
ok = 0
|
|
with sync_playwright() as p:
|
|
br = p.chromium.launch(executable_path=CHROME, headless=False,
|
|
args=["--disable-blink-features=AutomationControlled", "--no-first-run"])
|
|
for n, line in enumerate(todo):
|
|
mail, imap_pass = line.split(":", 1)
|
|
log(f"--- [{a.start + n}] {mail}")
|
|
r = run_one(br, mail, imap_pass, a.bank)
|
|
if r.get("ok"):
|
|
ok += 1
|
|
time.sleep(a.pause)
|
|
br.close()
|
|
log("WAVE DONE ok=%d/%d" % (ok, len(todo)))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |