File size: 3,406 Bytes
6403d77
787e9f9
 
6403d77
 
787e9f9
 
 
6403d77
787e9f9
 
6403d77
787e9f9
 
 
 
 
6403d77
787e9f9
6403d77
787e9f9
 
 
 
 
 
 
 
 
 
6403d77
787e9f9
 
 
 
 
 
 
 
 
 
 
 
6403d77
787e9f9
 
 
6403d77
787e9f9
 
 
6403d77
787e9f9
 
 
 
 
 
641ae43
787e9f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6403d77
 
787e9f9
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
 * /Api/interstitial.js
 * Geus disinkronkeun jeung Api.js (puppeteer-real-browser)
 */

async function interstitial({ domain, proxy }, page) {
    return new Promise(async (resolve, reject) => {
        if (!domain) return reject(new Error("Missing domain parameter"));

        let isResolved = false;
        let cf_clearance = null;

        // Timeout 60 detik sangkan teu ngagantung
        const timeout = setTimeout(() => {
            if (!isResolved) {
                isResolved = true;
                resolve({ success: false, error: "Timeout nungguan Cloudflare" });
            }
        }, 60000);

        try {
            // 1. Ngintip sési clearance tina response jaringan
            page.on('response', async (response) => {
                try {
                    const cookies = await page.cookies();
                    const found = cookies.find(c => c.name === 'cf_clearance');
                    if (found && !isResolved) {
                        cf_clearance = found.value;
                        const userAgent = await page.evaluate(() => navigator.userAgent);
                        const cookieString = cookies.map(c => `${c.name}=${c.value}`).join('; ');

                        isResolved = true;
                        clearTimeout(timeout);
                        
                        resolve({
                            success: true,
                            cf_clearance: cf_clearance,
                            user_agent: userAgent,
                            full_cookies: cookieString
                        });
                    }
                } catch (_) {}
            });

            // 2. Buka domain target
            // Paké networkidle2 sangkan mastikeun script Cloudflare geus jalan
            await page.goto(domain, { waitUntil: 'networkidle2', timeout: 60000 });

            // 3. Akalan: Simulasi gerakan mouse saeutik sangkan dianggap manusa
            await page.mouse.move(100, 100);
            await page.mouse.move(200, 300, { steps: 5 });

            // 4. Tungguan sakedap bisi aya Turnstile iframe
            const turnstileIframe = await page.$('iframe[src*="challenges"]');
            if (turnstileIframe) {
                console.log("[*] Turnstile detected, waiting 10s...");
                await new Promise(r => setTimeout(r, 10000));
            }

            // 5. Mun geus nunggu tapi can meunang cookie, coba cek sakali deui méméh kaluar
            if (!isResolved) {
                const cookies = await page.cookies();
                const found = cookies.find(c => c.name === 'cf_clearance');
                if (found) {
                    const userAgent = await page.evaluate(() => navigator.userAgent);
                    isResolved = true;
                    clearTimeout(timeout);
                    resolve({
                        success: true,
                        cf_clearance: found.value,
                        user_agent: userAgent,
                        full_cookies: cookies.map(c => `${c.name}=${c.value}`).join('; ')
                    });
                }
            }

        } catch (err) {
            if (!isResolved) {
                isResolved = true;
                clearTimeout(timeout);
                reject(err);
            }
        }
    });
}

// IEU WAJIB AYA SANGKAN BISA DIPANGGIL DI API.JS
module.exports = interstitial;