#!/usr/bin/env python3 # chat.co autoreg: email -> Turnstile -> OTP -> verify -> bot -> api keys import json, os, re, sys, time, imaplib, email, random, threading import requests API = os.environ.get('CHATCO_API', 'https://fwb567mce3.us-east-1.awsapprunner.com') CLIENT = 'https://api.chat.co' SITE = '0x4AAAAAAChjbcr8LGkrIuGG' CAP = os.environ.get('CHATCO_CAP') or open(os.environ.get('CHATCO_CAP_FILE', 'cap.txt'), encoding='utf-8').read().strip() HERE = os.path.dirname(os.path.abspath(__file__)) UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0 Safari/537.36' H = {'Content-Type': 'application/json', 'Origin': 'https://chat.co', 'Referer': 'https://chat.co/auth/login', 'User-Agent': UA} SCOPES = ['chat:read', 'chat:write', 'bot:read', 'bot:write', 'analytics:read', 'content:read', 'content:write', 'crawl:read', 'crawl:write'] IMAP = { 'rambler.ru': ('imap.rambler.ru', 993), 'gazeta.pl': ('imap.gazeta.pl', 993), 'lenta.ru': ('imap.lenta.ru', 993), 'ro.ru': ('imap.ro.ru', 993), 'i.ua': ('imap.i.ua', 993), 'topnet.tn': ('imap.topnet.tn', 993), 'singnet.com.sg': ('imap.singnet.com.sg', 993), 'rediffmail.com': ('imap.rediffmail.com', 993), 'mail.tmwlsw.com': ('imap.mail.tmwlsw.com', 993), 'tvnetwork.hu': ('imap.tvnetwork.hu', 993), 'aliyun.com': ('imap.aliyun.com', 993), } def log(*a): print(time.strftime('%H:%M:%S'), *a, flush=True) def ts_token(page='https://chat.co/auth/login', tries=2): for _ in range(tries): r = requests.post('https://api.2captcha.com/createTask', json={'clientKey': CAP, 'task': {'type': 'TurnstileTaskProxyless', 'websiteURL': page, 'websiteKey': SITE}}, timeout=40).json() if 'taskId' not in r: log('createTask err', str(r)[:120]); continue tid = r['taskId']; t0 = time.time() while time.time() - t0 < 200: time.sleep(4) g = requests.post('https://api.2captcha.com/getTaskResult', json={'clientKey': CAP, 'taskId': tid}, timeout=40).json() if g.get('status') == 'ready': return g['solution']['token'] raise RuntimeError('no turnstile token') def wait_otp(mail, pw, t0, timeout=300): dom = mail.split('@')[1].lower() host, port = IMAP.get(dom, ('imap.' + dom, 993)) deadline = time.time() + timeout while time.time() < deadline: try: M = imaplib.IMAP4_SSL(host, port, timeout=25) M.login(mail, pw); M.select('INBOX', readonly=True) typ, d = M.search(None, 'ALL'); ids = d[0].split() if d and d[0] else [] for i in reversed(ids[-12:]): t, dd = M.fetch(i, '(RFC822)'); m = email.message_from_bytes(dd[0][1]) if 'chat.co' not in (m['From'] or '').lower(): continue body = '' for p in m.walk(): if p.get_content_type() == 'text/html': body = p.get_payload(decode=True).decode('utf-8', 'ignore'); break if not body: for p in m.walk(): if p.get_content_type() == 'text/plain': body = p.get_payload(decode=True).decode('utf-8', 'ignore'); break txt = re.sub(r'', ' ', body) txt = re.sub(r'<[^>]+>', ' ', txt); txt = re.sub(r'\s+', ' ', txt) mm = re.search(r'verification code\s*(\d{6})', txt, re.I) or re.search(r'\b(\d{6})\b', txt) if mm: M.logout(); return mm.group(1) M.logout() except Exception as e: log('imap', dom, type(e).__name__, str(e)[:60]) time.sleep(10) return None def reg_one(mail, pw): t0 = time.time() tok = ts_token() s = requests.Session() r = s.post(API + '/auth/login', json={'email': mail, 'turnstileToken': tok}, headers=H, timeout=60) if r.status_code not in (200, 201): return {'email': mail, 'ok': False, 'stage': 'login', 'code': r.status_code, 'body': r.text[:160]} otp = wait_otp(mail, pw, t0) if not otp: return {'email': mail, 'ok': False, 'stage': 'otp'} r = s.post(API + '/auth/verify/email', json={'email': mail, 'otp': otp}, headers=H, timeout=60) if r.status_code not in (200, 201): return {'email': mail, 'ok': False, 'stage': 'verify', 'code': r.status_code, 'body': r.text[:160]} tokens = r.json()['data']['tokens'] AH = {'Authorization': 'Bearer ' + tokens['accessToken'], 'Content-Type': 'application/json', 'Origin': 'https://chat.co', 'User-Agent': UA} # бот rr = s.post(API + '/chatbot', json={'name': 'node', 'chatLimit': 2000}, headers=AH, timeout=60) if rr.status_code not in (200, 201): return {'email': mail, 'ok': False, 'stage': 'bot', 'code': rr.status_code, 'body': rr.text[:160]} bot = rr.json()['data']['chatbot']['id'] rr = s.post(API + '/api-keys', json={'name': 'full', 'chatbotId': bot, 'scopes': SCOPES}, headers=AH, timeout=60) key = rr.json()['data']['key'] rr = s.post(API + '/api-keys', json={'name': 'acct', 'scopes': SCOPES}, headers=AH, timeout=60) akey = rr.json()['data']['key'] return {'email': mail, 'ok': True, 'bot': bot, 'key': key, 'acct_key': akey, 'at': tokens['accessToken'], 'rt': tokens['refreshToken'], 'ts': int(time.time())} def mails(n, seen): out = [] for line in open(os.environ.get('CHATCO_SOIL','soil.txt'), encoding='utf-8', errors='ignore'): line = line.strip() if not line or ':' not in line: continue m, p = line.rsplit(':', 1) dom = m.split('@')[-1].lower() if dom not in IMAP or m in seen: continue if dom == 'rediffmail.com': # POP3-only, IMAP отбивает continue out.append((m, p)); seen.add(m) if len(out) >= n: break return out if __name__ == '__main__': n = int(sys.argv[1]) if len(sys.argv) > 1 else 3 pool = os.environ.get('CHATCO_POOL', os.path.join(HERE, 'pool.jsonl')) seen = set() if os.path.exists(pool): for line in open(pool, encoding='utf-8'): try: seen.add(json.loads(line)['email']) except Exception: pass todo = mails(n * 3, seen) ok = 0 for m, p in todo: if ok >= n: break try: res = reg_one(m, p); res['pw'] = p except Exception as e: res = {'email': m, 'ok': False, 'stage': 'exc', 'body': str(e)[:160]} with open(pool, 'a', encoding='utf-8') as f: f.write(json.dumps(res, ensure_ascii=False) + '\n') log(('OK ' if res.get('ok') else 'FAIL ') + m, res.get('stage', ''), res.get('code', '')) if res.get('ok'): ok += 1 time.sleep(3) log('done ok=%d' % ok)