140 lines
6.0 KiB
Python
140 lines
6.0 KiB
Python
import os
|
|
"""Slack createnew workspace via patchright + free solver sidecar (:8877) recaptcha token injection."""
|
|
from patchright.sync_api import sync_playwright
|
|
import json, random, string, os, time, imaplib, email as emaillib, re, urllib.request
|
|
|
|
BASE = json.load(open(os.path.expanduser("~/Desktop/_SCRIPTS/gmail_pool.json")))
|
|
owner = BASE["email"]; app_pw = BASE["app_password"]
|
|
local = owner.split("@")[0]; dom = owner.split("@")[1]
|
|
alias = "vk" + "".join(random.choices(string.ascii_lowercase + string.digits, k=6))
|
|
EMAIL = f"{local}+{alias}@{dom}"
|
|
open("slack_email4.txt", "w").write(EMAIL)
|
|
print("EMAIL:", EMAIL)
|
|
|
|
SOLVER = "http://127.0.0.1:8877/solve"
|
|
URL = "https://slack.com/get-started#/createnew"
|
|
PDIR = os.environ.get("PROFILE_DIR", "browser_profile")
|
|
|
|
def solve_recaptcha(sitekey, page_url):
|
|
body = json.dumps({"type": "recaptcha", "version": "v2", "sitekey": sitekey, "url": page_url}).encode()
|
|
req = urllib.request.Request(SOLVER, data=body, headers={"Content-Type": "application/json"})
|
|
r = json.loads(urllib.request.urlopen(req, timeout=300).read())
|
|
return r
|
|
|
|
def inject_token(page, token):
|
|
page.evaluate("""(tok) => {
|
|
const el = document.getElementById('g-recaptcha-response');
|
|
if (el) { el.innerHTML = tok; el.value = tok; }
|
|
if (window.___grecaptcha_cfg) {
|
|
const clients = window.___grecaptcha_cfg.clients;
|
|
const walk = (o) => {
|
|
for (const k in o) {
|
|
const v = o[k];
|
|
if (v && typeof v === 'object') { walk(v); }
|
|
else if (typeof v === 'function' && k.toLowerCase().includes('callback')) { try { v(tok); } catch(e){} }
|
|
}
|
|
};
|
|
try { walk(clients); } catch(e){}
|
|
}
|
|
if (window.grecaptcha && window.grecaptcha.getResponse) {
|
|
window.grecaptcha.getResponse = () => tok;
|
|
}
|
|
}""", token)
|
|
|
|
def get_code(wait=120):
|
|
t0 = time.time()
|
|
while time.time() - t0 < wait:
|
|
try:
|
|
M = imaplib.IMAP4_SSL("imap.gmail.com", 993)
|
|
M.login(owner, app_pw); M.select("INBOX")
|
|
typ, data = M.search(None, f'(FROM "slack")')
|
|
for i in data[0].split()[-6:]:
|
|
typ, msgd = M.fetch(i, "(RFC822)")
|
|
msg = emaillib.message_from_bytes(msgd[0][1])
|
|
to = msg.get("To", "")
|
|
if alias not in to and EMAIL not in to: continue
|
|
body = ""
|
|
if msg.is_multipart():
|
|
for part in msg.walk():
|
|
if part.get_content_type() == "text/plain":
|
|
body += part.get_payload(decode=True).decode(errors="replace")
|
|
else:
|
|
body = msg.get_payload(decode=True).decode(errors="replace")
|
|
m = re.search(r"\b(\d{6})\b", body)
|
|
if m:
|
|
M.logout(); return m.group(1)
|
|
M.logout()
|
|
except Exception as e:
|
|
print("imap err", str(e)[:60])
|
|
time.sleep(6)
|
|
return None
|
|
|
|
with sync_playwright() as p:
|
|
ctx = p.chromium.launch_persistent_context(PDIR, headless=False, no_viewport=True, channel="chromium")
|
|
page = ctx.new_page()
|
|
page.goto(URL, timeout=90000)
|
|
page.wait_for_timeout(8000)
|
|
print("URL1:", page.url[:120])
|
|
|
|
inp = page.locator("input[type=email], input[name=email]").first
|
|
if not inp.is_visible(timeout=10000):
|
|
print("NO INPUT:", page.inner_text("body")[:250].replace("\n", " | "))
|
|
ctx.close(); raise SystemExit
|
|
inp.type(EMAIL, delay=50); page.wait_for_timeout(1200)
|
|
page.locator("button[type=submit]").first.click()
|
|
page.wait_for_timeout(10000)
|
|
print("URL2:", page.url[:140])
|
|
body2 = page.inner_text("body")[:400].replace("\n", " | ")
|
|
print("BODY2:", body2)
|
|
|
|
# find recaptcha sitekey on page
|
|
sitekey = page.evaluate("""() => {
|
|
const f = [...document.querySelectorAll('iframe')].map(i=>i.src).filter(s=>s.includes('recaptcha'));
|
|
const m = f.length ? f[0].match(/k=([A-Za-z0-9_\\-]+)/) : null;
|
|
return m ? m[1] : null;
|
|
}""")
|
|
print("SITEKEY:", sitekey)
|
|
|
|
if sitekey:
|
|
print("solving recaptcha via sidecar...")
|
|
res = solve_recaptcha(sitekey, page.url)
|
|
print("solver status:", res.get("status"), "| token len:", len(res.get("token") or ""))
|
|
tok = res.get("token")
|
|
if tok:
|
|
inject_token(page, tok)
|
|
# re-click submit
|
|
page.wait_for_timeout(2000)
|
|
try:
|
|
page.locator("button[type=submit]").first.click()
|
|
except Exception: pass
|
|
page.wait_for_timeout(12000)
|
|
print("URL3:", page.url[:140])
|
|
print("BODY3:", page.inner_text("body")[:400].replace("\n", " | "))
|
|
|
|
code = get_code(120)
|
|
print("CODE:", code)
|
|
if code:
|
|
cinp = page.locator("input[type=text]").first
|
|
if cinp.is_visible(timeout=8000):
|
|
cinp.type(code, delay=80); page.wait_for_timeout(1500)
|
|
page.locator("button[type=submit]").first.click()
|
|
page.wait_for_timeout(14000)
|
|
print("URL4:", page.url[:160])
|
|
print("BODY4:", page.inner_text("body")[:500].replace("\n", " | "))
|
|
# workspace naming step
|
|
for label, val in [("workspace", "ViktorTeam"), ("full name", "Viktor User"), ("name", "Viktor User")]:
|
|
try:
|
|
f = page.locator(f"input[placeholder*='{label}' i], input[name*='{label.split()[0]}' i]").first
|
|
if f.is_visible(timeout=2000): f.type(val, delay=40); page.wait_for_timeout(800)
|
|
except Exception: pass
|
|
try:
|
|
page.locator("button[type=submit]").first.click(); page.wait_for_timeout(10000)
|
|
except Exception: pass
|
|
print("URL5:", page.url[:160])
|
|
print("BODY5:", page.inner_text("body")[:500].replace("\n", " | "))
|
|
|
|
cookies = ctx.cookies()
|
|
json.dump({"email": EMAIL, "cookies": cookies, "url": page.url}, open("slack_ws_result.json", "w"))
|
|
page.screenshot(path="slack_ws.png")
|
|
ctx.close()
|