Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { createRequire } from "node:module";
- import { randomUUID, randomBytes } from "node:crypto";
- try {
- const perf = require("node:perf_hooks") as Record<string, unknown>;
- const stub = () => ({
- count: 0, min: 0, max: 0, mean: 0, stddev: 0, exceeds: 0,
- percentiles: new Map<number, number>(),
- record() {}, recordDelta() {}, reset() {}, percentile() { return 0; },
- });
- let broken = false;
- try { (perf.createHistogram as () => unknown)?.(); } catch { broken = true; }
- if (typeof perf.createHistogram !== "function" || broken) {
- perf.createHistogram = () => stub();
- }
- } catch {}
- try {
- const req = createRequire(import.meta.url);
- const mod = req("piscina") as any;
- const Piscina: any = mod.Piscina ?? mod.default ?? mod;
- const proto = Piscina?.prototype;
- if (proto?.run && !proto.__certCompressionPatched) {
- const orig = proto.run;
- proto.run = function (task: unknown, opts?: { name?: string }) {
- if (opts?.name === "request" && typeof task === "string" && task.includes('"certCompressionAlgo":')) {
- task = task.replace(/"certCompressionAlgo":"(\w+)"/, '"certCompressionAlgos":["$1"]');
- }
- return orig.call(this, task, opts);
- };
- proto.__certCompressionPatched = true;
- }
- } catch {}
- import { Session, initTLS, type SessionOptions } from "node-tls-client";
- import { NoneCap } from "nonecap";
- const NONECAP_API_KEY = process.env.NONECAP_API_KEY ?? "YOUR_NONECAP_API_KEY";
- const PROXY_URL =
- process.env.PROXY_URL ?? "http://user:[email protected]:12321";
- const COUNT = Math.max(1, Number(process.env.COUNT ?? 1));
- const CONCURRENCY = Math.max(1, Number(process.env.CONCURRENCY ?? COUNT));
- const NONECAP_MAX_CONCURRENCY = Math.max(1, Number(process.env.NONECAP_MAX_CONCURRENCY ?? 5));
- const API = "https://discord.com/api/v9";
- const USER_AGENT =
- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36";
- const CLIENT_LAUNCH_ID = randomUUID();
- const LAUNCH_SIGNATURE = randomUUID();
- const SUPER_PROPERTIES = Buffer.from(JSON.stringify({
- os: "Mac OS X",
- browser: "Chrome",
- device: "",
- system_locale: "en-US",
- has_client_mods: false,
- browser_user_agent: USER_AGENT,
- browser_version: "149.0.0.0",
- os_version: "10.15.7",
- referrer: "",
- referring_domain: "",
- referrer_current: "",
- referring_domain_current: "",
- release_channel: "stable",
- client_build_number: 573410,
- client_event_source: null,
- client_launch_id: CLIENT_LAUNCH_ID,
- launch_signature: LAUNCH_SIGNATURE,
- client_app_state: "focused",
- }), "utf8").toString("base64");
- const CHROME_149_TLS: SessionOptions = {
- ja3string:
- "771,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,35-11-13-16-65281-10-45-18-5-17613-27-23-0-65037-51-43,4588-29-23-24,0",
- h2Settings: {
- HEADER_TABLE_SIZE: 65536,
- ENABLE_PUSH: 0 as unknown as boolean,
- INITIAL_WINDOW_SIZE: 6291456,
- MAX_HEADER_LIST_SIZE: 262144,
- },
- h2SettingsOrder: ["HEADER_TABLE_SIZE", "ENABLE_PUSH", "INITIAL_WINDOW_SIZE", "MAX_HEADER_LIST_SIZE"],
- supportedSignatureAlgorithms: [
- "ECDSAWithP256AndSHA256", "PSSWithSHA256", "PKCS1WithSHA256",
- "ECDSAWithP384AndSHA384", "PSSWithSHA384", "PSSWithSHA512", "PKCS1WithSHA512",
- ],
- supportedVersions: ["GREASE", "1.3", "1.2"],
- keyShareCurves: ["GREASE", "X25519MLKEM768" as unknown as "X25519", "X25519"],
- certCompressionAlgo: "brotli",
- pseudoHeaderOrder: [":method", ":authority", ":scheme", ":path"],
- alpnProtocols: ["h2", "http/1.1"],
- alpsProtocols: ["h2"],
- connectionFlow: 15663105,
- randomTlsExtensionOrder: false,
- };
- let tlsInit: Promise<void> | undefined;
- const ensureTls = () => (tlsInit ??= initTLS());
- function generateProxySessionId(): string {
- return randomBytes(4).toString("hex");
- }
- function stickyProxy(baseUrl: string): string {
- try {
- const parsed = new URL(baseUrl);
- const password = parsed.password ? decodeURIComponent(parsed.password) : "";
- if (!password.includes("_session-")) {
- parsed.password = encodeURIComponent(
- `${password}_session-${generateProxySessionId()}_lifetime-30m`,
- );
- }
- return parsed.toString();
- } catch {
- return baseUrl;
- }
- }
- class Agent {
- private readonly session: Session;
- private readonly defaults: Record<string, string>;
- constructor(proxyUrl: string) {
- this.session = new Session({ ...CHROME_149_TLS, timeout: 60_000, proxy: proxyUrl });
- this.defaults = {
- "User-Agent": USER_AGENT,
- Accept: "*/*",
- "Accept-Language": "en-US",
- "Accept-Encoding": "gzip, deflate, br, zstd",
- Origin: "https://discord.com",
- Referer: "https://discord.com/register",
- "X-Discord-Locale": "en-US",
- "X-Discord-Timezone": "Europe/Stockholm",
- "X-Debug-Options": "bugReporterEnabled",
- "X-Super-Properties": SUPER_PROPERTIES,
- "sec-ch-ua": '"Not)A;Brand";v="24", "Chromium";v="149", "Google Chrome";v="149"',
- "sec-ch-ua-mobile": "?0",
- "sec-ch-ua-platform": '"macOS"',
- "Sec-Fetch-Dest": "empty",
- "Sec-Fetch-Mode": "cors",
- "Sec-Fetch-Site": "same-origin",
- };
- }
- set(key: string, value: string): void {
- this.defaults[key] = value;
- }
- private async request(
- method: "GET" | "POST",
- url: string,
- body?: unknown,
- headers?: Record<string, string>,
- ): Promise<{ status: number; body: any }> {
- await ensureTls();
- const merged = { ...this.defaults, ...headers };
- const opts: Record<string, unknown> = { headers: merged, followRedirects: false };
- if (method === "POST") {
- merged["Content-Type"] = "application/json";
- opts.body = JSON.stringify(body ?? {});
- }
- const r = method === "GET"
- ? await this.session.get(url, opts)
- : await this.session.post(url, opts);
- let parsed: any = r.body;
- if (typeof r.body === "string" && (r.body[0] === "{" || r.body[0] === "[")) {
- try { parsed = JSON.parse(r.body); } catch {}
- }
- return { status: r.status, body: parsed };
- }
- get(url: string, headers?: Record<string, string>) {
- return this.request("GET", url, undefined, headers);
- }
- post(url: string, body: unknown, headers?: Record<string, string>) {
- return this.request("POST", url, body, headers);
- }
- close(): Promise<void> {
- return this.session.close().catch(() => {});
- }
- }
- class Semaphore {
- private active = 0;
- private readonly waiters: Array<() => void> = [];
- constructor(private readonly max: number) {}
- async run<T>(fn: () => Promise<T>): Promise<T> {
- if (this.active >= this.max) {
- await new Promise<void>((resolve) => this.waiters.push(resolve));
- } else {
- this.active++;
- }
- try {
- return await fn();
- } finally {
- const next = this.waiters.shift();
- if (next) next();
- else this.active--;
- }
- }
- }
- const solveLimiter = new Semaphore(NONECAP_MAX_CONCURRENCY);
- interface Challenge {
- sitekey: string;
- sessionId: string;
- rqdata: string;
- rqtoken: string;
- }
- function challengeFrom(status: number, body: any): Challenge | null {
- if (status !== 400 || !body || typeof body !== "object") return null;
- const keys = Array.isArray(body.captcha_key) ? body.captcha_key : [];
- if (!keys.includes("captcha-required") && !keys.includes("invalid-response")) return null;
- if (!body.captcha_sitekey || !body.captcha_session_id || !body.captcha_rqtoken) return null;
- return {
- sitekey: body.captcha_sitekey,
- sessionId: body.captcha_session_id,
- rqdata: body.captcha_rqdata,
- rqtoken: body.captcha_rqtoken,
- };
- }
- async function solveCaptcha(client: NoneCap, proxyUrl: string, chal: Challenge): Promise<string> {
- return solveLimiter.run(async () => {
- const solve = await client.solve(
- {
- type: "hcaptcha_enterprise",
- sitekey: chal.sitekey,
- url: "https://discord.com/verify",
- rqdata: chal.rqdata,
- user_agent: USER_AGENT,
- proxy: proxyUrl,
- },
- { timeout: 120_000 },
- );
- if (!solve.token) throw new Error(`nonecap solve ${solve.status}: no token`);
- return solve.token;
- });
- }
- async function register(
- agent: Agent,
- client: NoneCap,
- proxyUrl: string,
- input: { username: string; password: string; email: string; dateOfBirth: string },
- ): Promise<string> {
- const exp = await agent.get(`${API}/experiments`);
- const fingerprint = exp.body?.fingerprint as string | undefined;
- if (!fingerprint) throw new Error(`no fingerprint (status ${exp.status})`);
- agent.set("X-Fingerprint", fingerprint);
- const avail = await agent.post(`${API}/unique-username/username-attempt-unauthed`, {
- username: input.username,
- });
- if (avail.body?.taken !== false) throw new Error(`username "${input.username}" is taken`);
- const body = {
- fingerprint,
- email: input.email,
- username: input.username,
- global_name: input.username,
- password: input.password,
- invite: null,
- consent: true,
- date_of_birth: input.dateOfBirth,
- gift_code_sku_id: null,
- promotional_email_opt_in: false,
- };
- let res = await agent.post(`${API}/auth/register`, body);
- for (let attempt = 0; attempt < 2; attempt++) {
- const chal = challengeFrom(res.status, res.body);
- if (!chal) break;
- const token = await solveCaptcha(client, proxyUrl, chal);
- res = await agent.post(`${API}/auth/register`, body, {
- "X-Captcha-Key": token,
- "X-Captcha-Rqtoken": chal.rqtoken,
- "X-Captcha-Session-Id": chal.sessionId,
- });
- }
- if (res.status === 201 && typeof res.body?.token === "string") return res.body.token;
- throw new Error(`register failed (status ${res.status}): ${JSON.stringify(res.body)}`);
- }
- async function oneAttempt(index: number): Promise<string | null> {
- const tag = `#${index + 1}`;
- const proxyUrl = stickyProxy(PROXY_URL);
- const agent = new Agent(proxyUrl);
- const client = new NoneCap({ apiKey: NONECAP_API_KEY });
- const rand = Math.random().toString(36).slice(2, 9) + Date.now().toString(36).slice(-4);
- const t0 = Date.now();
- try {
- const token = await register(agent, client, proxyUrl, {
- username: `lum${rand}`,
- password: `Lun!um_${rand}_xZ`,
- email: `james.miller.${rand}@your-catchall-domain.com`,
- dateOfBirth: "1998-01-12",
- });
- console.log(`${tag} created in ${((Date.now() - t0) / 1000).toFixed(1)}s — ${token.slice(0, 24)}…`);
- return token;
- } catch (e) {
- console.log(`${tag} failed after ${((Date.now() - t0) / 1000).toFixed(1)}s — ${(e as Error).message}`);
- return null;
- } finally {
- await agent.close();
- }
- }
- function fail(message: string): never {
- console.error(`preflight failed — ${message}`);
- process.exit(1);
- }
- async function preflight(): Promise<void> {
- console.log("running preflight checks…");
- if (!NONECAP_API_KEY || NONECAP_API_KEY === "YOUR_NONECAP_API_KEY") {
- fail("NONECAP_API_KEY is not set (edit the file or pass NONECAP_API_KEY=…). Get a key at nonecap.com.");
- }
- if (!PROXY_URL || PROXY_URL.includes("user:pass")) {
- fail("PROXY_URL is not set (edit the file or pass PROXY_URL=…). Use a sticky residential proxy.");
- }
- let proxy: URL;
- try {
- proxy = new URL(PROXY_URL);
- } catch {
- fail(`PROXY_URL is not a valid URL: ${PROXY_URL}`);
- }
- if (!/^https?:$|^socks[45]?:$/.test(proxy.protocol)) {
- fail(`unsupported proxy scheme "${proxy.protocol.replace(/:$/, "")}" (use http, https, socks4 or socks5)`);
- }
- if (!proxy.hostname || !proxy.port) fail("PROXY_URL must include an explicit host and port");
- if (!proxy.username || !proxy.password) fail("PROXY_URL must include credentials (user:pass@host:port)");
- const client = new NoneCap({ apiKey: NONECAP_API_KEY });
- try {
- const account = await client.me();
- if (account.credits_balance <= 0) {
- fail(`NoneCap account has no credits (balance ${account.credits_balance}). Top up at nonecap.com.`);
- }
- console.log(` nonecap ok — ${account.credits_balance} credits`);
- } catch (e) {
- fail(`could not reach NoneCap / invalid API key: ${(e as Error).message}`);
- }
- const agent = new Agent(stickyProxy(PROXY_URL));
- try {
- const res = await agent.get(`${API}/experiments`);
- if (res.status === 0) {
- fail("proxy could not reach discord.com (connection failed) — check the proxy host/port/credentials");
- }
- if (!res.body?.fingerprint) {
- fail(`discord /experiments returned status ${res.status} without a fingerprint — proxy IP may be blocked`);
- }
- console.log(` proxy + discord ok — exit reachable, fingerprint issued`);
- } catch (e) {
- fail(`proxy connectivity test threw: ${(e as Error).message}`);
- } finally {
- await agent.close();
- }
- console.log("preflight passed\n");
- }
- const results = new Array<string | null>(COUNT);
- let nextIndex = 0;
- async function worker(): Promise<void> {
- while (true) {
- const i = nextIndex++;
- if (i >= COUNT) break;
- results[i] = await oneAttempt(i);
- }
- }
- await preflight();
- console.log(`creating ${COUNT} account(s), ${Math.min(CONCURRENCY, COUNT)} at a time\n`);
- await Promise.all(Array.from({ length: Math.min(CONCURRENCY, COUNT) }, () => worker()));
- const tokens = results.filter((t): t is string => t !== null);
- console.log(`\ndone · ${tokens.length}/${COUNT} created`);
- process.exit(tokens.length > 0 ? 0 : 1);
Add Comment
Please, Sign In to add comment