fourmovie commited on
Commit
6e96b3b
·
1 Parent(s): 70067a8
Files changed (9) hide show
  1. Dockerfile +26 -0
  2. README.md +1 -3
  3. api_test.py +26 -0
  4. cache/cache.json +10 -0
  5. endpoints/antibot.js +193 -0
  6. endpoints/cloudflare.js +79 -0
  7. endpoints/turnstile.js +84 -0
  8. index.js +179 -0
  9. package.json +21 -0
Dockerfile ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM node:20-slim
2
+
3
+ RUN apt update && apt install -y \
4
+ wget gnupg ca-certificates xvfb \
5
+ fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 \
6
+ libatk1.0-0 libxss1 libnss3 libxcomposite1 libxdamage1 libxrandr2 libgbm1 \
7
+ && wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
8
+ && apt install -y ./google-chrome-stable_current_amd64.deb \
9
+ && rm google-chrome-stable_current_amd64.deb
10
+
11
+ WORKDIR /app
12
+
13
+ RUN mkdir -p /app/endpoints && \
14
+ mkdir -p /app/cache
15
+
16
+ COPY package*.json ./
17
+ RUN npm install
18
+
19
+ COPY . .
20
+
21
+ EXPOSE 7860
22
+
23
+ CMD rm -f /tmp/.X99-lock && \
24
+ Xvfb :99 -screen 0 1024x768x24 & \
25
+ export DISPLAY=:99 && \
26
+ npm start
README.md CHANGED
@@ -3,10 +3,8 @@ title: Antibot2
3
  emoji: 📚
4
  colorFrom: gray
5
  colorTo: indigo
6
- sdk: gradio
7
  sdk_version: 5.49.1
8
- app_file: app.py
9
- pinned: false
10
  license: apache-2.0
11
  short_description: antibot
12
  ---
 
3
  emoji: 📚
4
  colorFrom: gray
5
  colorTo: indigo
6
+ sdk: docker
7
  sdk_version: 5.49.1
 
 
8
  license: apache-2.0
9
  short_description: antibot
10
  ---
api_test.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import asyncio
2
+ import httpx
3
+
4
+ async def main():
5
+ async with httpx.AsyncClient(timeout=30.0) as client:
6
+ resp1 = await client.post(
7
+ "http://localhost:8080/cloudflare",
8
+ json={
9
+ "domain": "https://olamovies.watch/generate",
10
+ "mode": "iuam",
11
+ },
12
+ )
13
+ print(resp1.json())
14
+
15
+ resp2 = await client.post(
16
+ "http://localhost:8080/cloudflare",
17
+ json={
18
+ "domain": "https://lksfy.com/",
19
+ "siteKey": "0x4AAAAAAA49NnPZwQijgRoi",
20
+ "mode": "turnstile",
21
+ },
22
+ )
23
+ print(resp2.json())
24
+
25
+ if __name__ == "__main__":
26
+ asyncio.run(main())
cache/cache.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "{\"domain\":\"https://v2links.org\",\"mode\":\"iuam\"}": {
3
+ "timestamp": 1758616160392,
4
+ "value": {
5
+ "cf_clearance": "qqs5f4MpFMgA0v78Qmh_HYDWoKhbwqlQ57bTW5KeIr8-1758616161-1.2.1.1-D5PdpmheHl.26ssIRKQBsXzPtPPkSXntEZ_H9FUJVt7MMTS_BEE8iH.E48MDzKtFBLwZqRYxE_1GLo1gj3ChXrwatOGEJcmGRUwavy2qvGgUPizn7qufd.sW0ULfhaRO7Gz_H_eO1TU3iEqCzltEUDNk0SviKRFkF8ozbvJ91MW_qmO.qrjQorbu_jxcgJv5BHs6rTNOitWtVDAmYMDukASq0viHXIUAIvTM.LIfQ88",
6
+ "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36",
7
+ "elapsed_time": 5.028
8
+ }
9
+ }
10
+ }
endpoints/antibot.js ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const Tesseract = require("tesseract.js");
2
+ const fs = require("fs");
3
+ const path = require("path");
4
+ const sharp = require("sharp");
5
+
6
+ const WORD_TO_NUM = {
7
+ zero:"0",oh:"0",one:"1",won:"1",two:"2",to:"2",too:"2",three:"3",tree:"3",
8
+ four:"4",for:"4",five:"5",six:"6",seven:"7",eight:"8",ate:"8",nine:"9",ten:"10"
9
+ };
10
+
11
+ const LEET_REPLACE = {
12
+ "4":"a","3":"e","1":"i","0":"o","5":"s","7":"t","@":"a","$":"s","|":"l"
13
+ };
14
+
15
+ const buf = b => Buffer.from(b.replace(/^data:image\/\w+;base64,/,""),"base64");
16
+
17
+ function fixLeetToText(s){
18
+ return s.toLowerCase().split("").map(c=>LEET_REPLACE[c]??c).join("");
19
+ }
20
+
21
+ function wordToDigit(t){
22
+ if(!t)return"";
23
+ t=t.toLowerCase().trim();
24
+ if(/^\d+$/.test(t))return t;
25
+ const c=t.replace(/[^a-z0-9]/gi,"");
26
+ const f=fixLeetToText(c);
27
+ if(WORD_TO_NUM[f]!==undefined)return WORD_TO_NUM[f];
28
+ const d=t.match(/\d+/);
29
+ if(d)return d[0];
30
+ return"";
31
+ }
32
+
33
+ function normalizeExpression(raw){
34
+ if(!raw)return"";
35
+ let s=raw.toLowerCase().replace(/\s+/g,"");
36
+ s=s.replace(/[×xX·•]/g,"*");
37
+ const parts=s.split(/([+\-*/()])/).filter(p=>p!=="");
38
+ return parts.map(p=>{
39
+ if(/^[+\-*/()]+$/.test(p))return p;
40
+ let num=wordToDigit(p);
41
+ if(num)return num;
42
+ const tf=fixLeetToText(p).replace(/[^a-z0-9]/g,"");
43
+ num=WORD_TO_NUM[tf]??"";
44
+ if(num)return num;
45
+ const dig=p.match(/\d+/);
46
+ if(dig)return dig[0];
47
+ return p;
48
+ }).join("");
49
+ }
50
+
51
+ function safeEvalExpression(expr){
52
+ if(!expr)return null;
53
+ const n=normalizeExpression(expr);
54
+ if(!/^[0-9+\-*/().]+$/.test(n))return null;
55
+ try{
56
+ const v=Function(`"use strict";return(${n});`)();
57
+ if(typeof v==="number"&&isFinite(v)){
58
+ if(Math.abs(v-Math.round(v))<1e-9)return String(Math.round(v));
59
+ return String(v);
60
+ }
61
+ return null;
62
+ }catch(e){return null;}
63
+ }
64
+
65
+ async function writeTempAndRecognize(b,opt={}){
66
+ const tmp=path.join(__dirname,"tmp_"+Date.now()+"_"+Math.random()+".png");
67
+ fs.writeFileSync(tmp,b);
68
+ try{
69
+ const r=await Tesseract.recognize(tmp,"eng",opt);
70
+ fs.unlinkSync(tmp);
71
+ return r.data.text||"";
72
+ }catch(e){
73
+ if(fs.existsSync(tmp))fs.unlinkSync(tmp);
74
+ return"";
75
+ }
76
+ }
77
+
78
+ async function ocrDigit(b){
79
+ const t=await writeTempAndRecognize(b,{
80
+ tessedit_char_whitelist:"0123456789Il!|OoZSTBGg",
81
+ tessedit_pageseg_mode:"7",
82
+ tessedit_ocr_engine_mode:"1"
83
+ });
84
+ const m={"I":"1","l":"1","|":"1","!":"1","O":"0","o":"0","Q":"0","Z":"2","z":"2",
85
+ "S":"5","s":"5","T":"7","t":"7","B":"8","b":"8","G":"6","g":"9"};
86
+ return t.split("").map(c=>m[c]??c).join("").replace(/[^0-9]/g,"");
87
+ }
88
+
89
+ async function ocrGeneric(b){
90
+ const t=await writeTempAndRecognize(b,{
91
+ tessedit_char_whitelist:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-*/()., ",
92
+ tessedit_pageseg_mode:"7",
93
+ tessedit_ocr_engine_mode:"1"
94
+ });
95
+ return t.trim();
96
+ }
97
+
98
+ async function preprocessForSoal(b){
99
+ return sharp(b).resize({width:1000}).grayscale().normalize().sharpen({sigma:1.2}).median(1).toBuffer();
100
+ }
101
+
102
+ async function preprocessForBot(b){
103
+ return sharp(b).resize({width:700}).grayscale().normalize().sharpen({sigma:1}).median(1).toBuffer();
104
+ }
105
+
106
+ module.exports = async function solveAntiBot(data){
107
+ try{
108
+ const soalBuf=buf(data.main);
109
+ const soalPrep=await preprocessForSoal(soalBuf);
110
+ const soalRawText=await ocrGeneric(soalPrep);
111
+
112
+ const tok=soalRawText.split(/[,;]+|\s+/).filter(Boolean);
113
+ const soalNumbers=tok.slice(0,10).map(t=>{
114
+ const e=safeEvalExpression(t);
115
+ if(e!==null&&e!=="")return e;
116
+ const w=wordToDigit(t);
117
+ if(w)return w;
118
+ const fx=fixLeetToText(t.replace(/[^a-z0-9+\-*/().]/gi,""));
119
+ if(WORD_TO_NUM[fx]!==undefined)return WORD_TO_NUM[fx];
120
+ const d=t.match(/\d+/);
121
+ if(d)return d[0];
122
+ return"";
123
+ }).filter(Boolean);
124
+
125
+ const botResults=[];
126
+ for(const b of data.bots){
127
+ const bbuf=buf(b.img);
128
+ const prep=await preprocessForBot(bbuf);
129
+ let v=await ocrDigit(prep);
130
+ if(!v){
131
+ const g=await ocrGeneric(prep);
132
+ if(g){
133
+ const ev=safeEvalExpression(g);
134
+ if(ev!==null)v=ev;
135
+ else v=wordToDigit(g)||fixLeetToText(g).replace(/[^0-9]/g,"");
136
+ }
137
+ }
138
+ botResults.push({id:b.id,raw:v||""});
139
+ }
140
+
141
+ botResults.forEach(br=>{
142
+ if(!br.raw)return;
143
+ if(!/^\d+$/.test(br.raw)){
144
+ br.raw=wordToDigit(br.raw)||safeEvalExpression(br.raw)||br.raw.match(/\d+/)?.[0]||"";
145
+ }
146
+ });
147
+
148
+ const result=[];
149
+ const used=new Set();
150
+ for(const need of soalNumbers){
151
+ let f=null;
152
+ for(const b of botResults){
153
+ if(!used.has(b.id)&&b.raw&&String(b.raw)===String(need)){
154
+ f=b.id;break;
155
+ }
156
+ }
157
+ if(!f){
158
+ for(const b of botResults){
159
+ if(!used.has(b.id)&&b.raw&&Number(b.raw)==Number(need)){
160
+ f=b.id;break;
161
+ }
162
+ }
163
+ }
164
+ if(!f){
165
+ for(const b of botResults){
166
+ if(!used.has(b.id)&&b.raw){
167
+ const bw=fixLeetToText(String(b.raw));
168
+ if(WORD_TO_NUM[bw]===String(need)){f=b.id;break;}
169
+ }
170
+ }
171
+ }
172
+ if(f){result.push(f);used.add(f);}
173
+ else result.push(null);
174
+ }
175
+
176
+ for(let i=0;i<result.length;i++){
177
+ if(result[i]===null){
178
+ for(const b of botResults){
179
+ if(!used.has(b.id)){
180
+ result[i]=b.id;
181
+ used.add(b.id);
182
+ break;
183
+ }
184
+ }
185
+ }
186
+ }
187
+
188
+ return {rawSoalText:soalRawText,soalNumbers,botResults,result};
189
+
190
+ }catch(e){
191
+ return {rawSoalText:"",soalNumbers:[],botResults:[],result:[]};
192
+ }
193
+ };
endpoints/cloudflare.js ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ async function cloudflare(data, page) {
2
+ return new Promise(async (resolve, reject) => {
3
+ if (!data.domain) return reject(new Error("Missing domain parameter"))
4
+
5
+ const startTime = Date.now()
6
+ let isResolved = false
7
+ let userAgent = null
8
+
9
+ const cl = setTimeout(() => {
10
+ if (!isResolved) {
11
+ isResolved = true
12
+ const elapsedTime = (Date.now() - startTime) / 1000
13
+ resolve({
14
+ cf_clearance: null,
15
+ user_agent: userAgent,
16
+ elapsed_time: elapsedTime,
17
+ })
18
+ }
19
+ }, 20000)
20
+
21
+ try {
22
+ if (data.proxy?.username && data.proxy?.password) {
23
+ await page.authenticate({
24
+ username: data.proxy.username,
25
+ password: data.proxy.password,
26
+ })
27
+ }
28
+
29
+ page.removeAllListeners("request")
30
+ page.removeAllListeners("response")
31
+ await page.setRequestInterception(true)
32
+
33
+ page.on("request", async (req) => {
34
+ try {
35
+ await req.continue()
36
+ } catch (_) {}
37
+ })
38
+
39
+ page.on("response", async (res) => {
40
+ try {
41
+ const url = res.url()
42
+ if (url.includes("/cdn-cgi/challenge-platform/")) {
43
+ const headers = res.headers()
44
+ if (headers["set-cookie"]) {
45
+ const match = headers["set-cookie"].match(/cf_clearance=([^;]+)/)
46
+ if (match) {
47
+ const cf_clearance = match[1]
48
+ const userAgent = (await res.request().headers())["user-agent"]
49
+ const elapsedTime = (Date.now() - startTime) / 1000
50
+
51
+ if (!isResolved) {
52
+ isResolved = true
53
+ clearTimeout(cl)
54
+
55
+ resolve({
56
+ cf_clearance,
57
+ user_agent: userAgent,
58
+ elapsed_time: elapsedTime,
59
+ })
60
+ }
61
+ }
62
+ }
63
+ }
64
+ } catch (_) {}
65
+ })
66
+
67
+ await page.goto(data.domain, { waitUntil: "domcontentloaded" })
68
+ userAgent = await page.evaluate(() => navigator.userAgent)
69
+ } catch (err) {
70
+ if (!isResolved) {
71
+ isResolved = true
72
+ clearTimeout(cl)
73
+ reject(err)
74
+ }
75
+ }
76
+ })
77
+ }
78
+
79
+ module.exports = cloudflare
endpoints/turnstile.js ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ async function turnstile({ domain, proxy, siteKey }, page) {
2
+ if (!domain) throw new Error("Missing domain parameter");
3
+ if (!siteKey) throw new Error("Missing siteKey parameter");
4
+
5
+ const timeout = global.timeOut || 60000;
6
+ let isResolved = false;
7
+
8
+ const cl = setTimeout(async () => {
9
+ if (!isResolved) {
10
+ throw new Error("Timeout Error");
11
+ }
12
+ }, timeout);
13
+
14
+ try {
15
+ if (proxy?.username && proxy?.password) {
16
+ await page.authenticate({
17
+ username: proxy.username,
18
+ password: proxy.password,
19
+ });
20
+ }
21
+
22
+ const htmlContent = `
23
+ <!DOCTYPE html>
24
+ <html lang="en">
25
+ <body>
26
+ <div class="turnstile"></div>
27
+ <script src="https://challenges.cloudflare.com/turnstile/v0/api.js?onload=onloadTurnstileCallback" defer></script>
28
+ <script>
29
+ window.onloadTurnstileCallback = function () {
30
+ turnstile.render('.turnstile', {
31
+ sitekey: '${siteKey}',
32
+ callback: function (token) {
33
+ var c = document.createElement('input');
34
+ c.type = 'hidden';
35
+ c.name = 'cf-response';
36
+ c.value = token;
37
+ document.body.appendChild(c);
38
+ },
39
+ });
40
+ };
41
+ </script>
42
+ </body>
43
+ </html>
44
+ `;
45
+
46
+ await page.setRequestInterception(true);
47
+ page.removeAllListeners("request");
48
+ page.on("request", async (request) => {
49
+ if ([domain, domain + "/"].includes(request.url()) && request.resourceType() === "document") {
50
+ await request.respond({
51
+ status: 200,
52
+ contentType: "text/html",
53
+ body: htmlContent,
54
+ });
55
+ } else {
56
+ await request.continue();
57
+ }
58
+ });
59
+
60
+ await page.goto(domain, { waitUntil: "domcontentloaded" });
61
+
62
+ await page.waitForSelector('[name="cf-response"]', { timeout });
63
+
64
+ const token = await page.evaluate(() => {
65
+ try {
66
+ return document.querySelector('[name="cf-response"]').value;
67
+ } catch {
68
+ return null;
69
+ }
70
+ });
71
+
72
+ isResolved = true;
73
+ clearTimeout(cl);
74
+
75
+ if (!token || token.length < 10) throw new Error("Failed to get token");
76
+ return token;
77
+
78
+ } catch (e) {
79
+ clearTimeout(cl);
80
+ throw e;
81
+ }
82
+ }
83
+
84
+ module.exports = turnstile;
index.js ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const express = require('express');
2
+ const { connect } = require("puppeteer-real-browser");
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+
6
+ const app = express();
7
+ const port = process.env.PORT || 7860;
8
+ const authToken = process.env.authToken || null;
9
+ const domain = process.env.DOMAIN || `https://fourstore-antibot2.hf.space`;
10
+
11
+ global.browserLimit = Number(process.env.browserLimit) || 20;
12
+ global.timeOut = Number(process.env.timeOut) || 60000;
13
+
14
+ const CACHE_DIR = path.join(__dirname, "cache");
15
+ const CACHE_FILE = path.join(CACHE_DIR, "cache.json");
16
+ const CACHE_TTL = 5 * 60 * 1000;
17
+
18
+ function loadCache() {
19
+ if (!fs.existsSync(CACHE_FILE)) return {};
20
+ try {
21
+ return JSON.parse(fs.readFileSync(CACHE_FILE, 'utf-8'));
22
+ } catch {
23
+ return {};
24
+ }
25
+ }
26
+
27
+ function saveCache(cache) {
28
+ if (!fs.existsSync(CACHE_DIR)) {
29
+ fs.mkdirSync(CACHE_DIR, { recursive: true });
30
+ }
31
+ fs.writeFileSync(CACHE_FILE, JSON.stringify(cache, null, 2), 'utf-8');
32
+ }
33
+
34
+ function readCache(key) {
35
+ const cache = loadCache();
36
+ const entry = cache[key];
37
+ if (entry && Date.now() - entry.timestamp < CACHE_TTL) {
38
+ return entry.value;
39
+ }
40
+ return null;
41
+ }
42
+
43
+ function writeCache(key, value) {
44
+ const cache = loadCache();
45
+ cache[key] = { timestamp: Date.now(), value };
46
+ saveCache(cache);
47
+ }
48
+
49
+ app.use(express.json({ limit: "50mb" }));
50
+ app.use(express.urlencoded({ extended: true, limit: "50mb" }));
51
+
52
+ app.get("/", (req, res) => {
53
+ res.json({
54
+ message: "Server is running!",
55
+ domain: domain,
56
+ endpoints: {
57
+ cloudflare: `${domain}/cloudflare`,
58
+ antibot: `${domain}/antibot`
59
+ },
60
+ status: {
61
+ browserLimit: global.browserLimit,
62
+ timeOut: global.timeOut,
63
+ authRequired: authToken !== null
64
+ }
65
+ });
66
+ });
67
+
68
+ if (process.env.NODE_ENV !== 'development') {
69
+ let server = app.listen(port, () => {
70
+ console.log(`Server running on port ${port}`);
71
+ console.log(`Domain: ${domain}`);
72
+ console.log(`Auth required: ${authToken !== null}`);
73
+ });
74
+ try {
75
+ server.timeout = global.timeOut;
76
+ } catch {}
77
+ }
78
+
79
+ async function createBrowser(proxyServer = null) {
80
+ const connectOptions = {
81
+ headless: false,
82
+ turnstile: true,
83
+ connectOption: { defaultViewport: null },
84
+ disableXvfb: false,
85
+ };
86
+ if (proxyServer) connectOptions.args = [`--proxy-server=${proxyServer}`];
87
+
88
+ const { browser } = await connect(connectOptions);
89
+ const [page] = await browser.pages();
90
+
91
+ await page.goto('about:blank');
92
+ await page.setRequestInterception(true);
93
+ page.on('request', (req) => {
94
+ const type = req.resourceType();
95
+ if (["image", "stylesheet", "font", "media"].includes(type)) req.abort();
96
+ else req.continue();
97
+ });
98
+
99
+ return { browser, page };
100
+ }
101
+
102
+ const turnstile = require('./endpoints/turnstile');
103
+ const cloudflare = require('./endpoints/cloudflare');
104
+ const antibot = require('./endpoints/antibot');
105
+
106
+ app.post('/cloudflare', async (req, res) => {
107
+ const data = req.body;
108
+ if (!data || typeof data.mode !== 'string')
109
+ return res.status(400).json({ message: 'Bad Request: missing or invalid mode' });
110
+
111
+ if (global.browserLimit <= 0)
112
+ return res.status(429).json({ message: 'Too Many Requests' });
113
+
114
+ let cacheKey, cached;
115
+ if (data.mode === "iuam") {
116
+ cacheKey = JSON.stringify(data);
117
+ cached = readCache(cacheKey);
118
+ if (cached) return res.status(200).json({ ...cached, cached: true });
119
+ }
120
+
121
+ global.browserLimit--;
122
+ let result, browser;
123
+
124
+ try {
125
+ const proxyServer = data.proxy ? `${data.proxy.hostname}:${data.proxy.port}` : null;
126
+ const ctx = await createBrowser(proxyServer);
127
+ browser = ctx.browser;
128
+ const page = ctx.page;
129
+
130
+ await page.goto('about:blank');
131
+
132
+ switch (data.mode) {
133
+ case "turnstile":
134
+ result = await turnstile(data, page).then(t => ({ token: t }));
135
+ break;
136
+
137
+ case "iuam":
138
+ result = await cloudflare(data, page).then(r => ({ ...r }));
139
+ writeCache(cacheKey, result);
140
+ break;
141
+
142
+ case "antibot":
143
+ result = await antibot(data);
144
+ break;
145
+
146
+ default:
147
+ result = { code: 400, message: 'Invalid mode' };
148
+ }
149
+ } catch (err) {
150
+ result = { code: 500, message: err.message };
151
+ } finally {
152
+ if (browser) try { await browser.close(); } catch {}
153
+ global.browserLimit++;
154
+ }
155
+
156
+ res.status(result.code ?? 200).json(result);
157
+ });
158
+
159
+ app.post("/antibot", async (req, res) => {
160
+ const data = req.body;
161
+
162
+ if (!data || !data.main || !Array.isArray(data.bots))
163
+ return res.status(400).json({ message: "Invalid body" });
164
+
165
+ try {
166
+ const result = await antibot(data);
167
+ res.json(result);
168
+ } catch (err) {
169
+ res.status(500).json({ message: err.message });
170
+ }
171
+ });
172
+
173
+ app.use((req, res) => {
174
+ res.status(404).json({ message: 'Not Found' });
175
+ });
176
+
177
+ if (process.env.NODE_ENV === 'development') {
178
+ module.exports = app;
179
+ }
package.json ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "cf-bypass",
3
+ "version": "1.0",
4
+ "description": "get the cf_clearance cookie from any website",
5
+ "scripts": {
6
+ "start": "node index.js",
7
+ "dev": "nodemon index.js"
8
+ },
9
+ "dependencies": {
10
+ "express": "^5.1.0",
11
+ "canvas": "^2.11.2",
12
+ "sharp": "^0.32.0",
13
+ "puppeteer-real-browser": "^1.4.0",
14
+ "axios": "^1.9.0",
15
+ "tesseract.js": "^5.0.3",
16
+ "jimp": "^0.22.10"
17
+ },
18
+ "devDependencies": {
19
+ "nodemon": "^3.1.10"
20
+ }
21
+ }