Advertisement
FlyFar

Bypass netflix.com Enterprise Recaptcha V3 at sign-in page

Feb 24th, 2024
1,565
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 4.69 KB | Cybersecurity | 0 0
  1. //npm install puppeteer fs @antiadmin/anticaptchaofficial
  2. // update your login credentials
  3. // run with command: "node netflix.js"
  4.  
  5. //IMPORTANT:
  6. //1. Netflix utilizes Enterprise Recaptcha V3
  7. //2. We use their obfuscated script located at https://codex.nflxext.com/*** CDN.
  8. //   We modify it a little to add a function "getMyToken" at the place where they use token from Google.
  9. //   In case of script modifcations, you may add this function yourself.
  10. //   This function simply returns V3 Enterprise token which we substitute after solving it in Anti Captcha.
  11. //3. Netflix login and password are required to test this script.
  12. //4. Several attempts (about 10 times) should be made to sign in successfully.
  13.  
  14. const anticaptcha = require("@antiadmin/anticaptchaofficial");
  15. const pup = require("puppeteer");
  16. const fs = require('fs');
  17.  
  18.  
  19. //API key for anti-captcha.com
  20. const anticaptchaAPIKey = 'API_KEY_HERE';
  21.  
  22. //access data
  23. const url = 'https://www.netflix.com/login';
  24. const login = 'your@email.com';
  25. const password = 'password';
  26.  
  27. let browser = null;
  28. let page = null;
  29. let token = null;
  30.  
  31.  
  32.  
  33. (async () => {
  34.  
  35.     anticaptcha.setAPIKey(anticaptchaAPIKey);
  36.     const balance = await anticaptcha.getBalance();
  37.     if (balance <= 0) {
  38.         console.log('Buy your anticaptcha balance!');
  39.         return;
  40.     } else {
  41.         console.log('API key balance is '+balance+', continuing');
  42.         // anticaptcha.shutUp(); //uncomment for silent captcha recognition
  43.     }
  44.  
  45.     try {
  46.         console.log('opening browser ..');
  47.  
  48.  
  49.         let options = {
  50.             headless: false,
  51.             ignoreHTTPSErrors: true,
  52.             devtools: true
  53.         };
  54.         console.log(options);
  55.         browser = await pup.launch(options);
  56.  
  57.  
  58.         console.log('creating new page ..');
  59.         page = await browser.newPage();
  60.     } catch (e) {
  61.         failCallback("could not open browser: "+e);
  62.         return false;
  63.     }
  64.  
  65.  
  66.     await page.setRequestInterception(true);
  67.     page.on('request', (request) => {
  68.         if (request.url().indexOf('none') !== -1 && request.url().indexOf('js') !== -1 && request.url().indexOf('components') !== -1) {
  69.             console.log('aborting '+request.url());
  70.             request.abort();
  71.         } else {
  72.             request.continue();
  73.         }
  74.     });
  75.     page.on('response', (response) => {
  76.         if (response.url().indexOf('login') !== -1 && response.request().method() === 'POST') {
  77.             console.log("\n\n==== captcha check response ====\n\n");
  78.             console.log('status: '+response.status());
  79.             if (response.status() !== 302) {
  80.                 failCallback("captcha result not accepted");
  81.             } else {
  82.                 successCallback("successfully passed test");
  83.             }
  84.         }
  85.     });
  86.  
  87.     console.log('solving captcha');
  88.  
  89.     try {
  90.         token = await anticaptcha.solveRecaptchaV3Enterprise(url,'6Lf8hrcUAAAAAIpQAFW2VFjtiYnThOjZOA5xvLyR',0.9,'');
  91.     } catch (e) {
  92.         failCallback("could not solve captcha");
  93.         return;
  94.     }
  95.  
  96.     console.log('token is ready: '+token);
  97.  
  98.  
  99.     try {
  100.         await page.goto(url, {
  101.             waitUntil: "domcontentloaded"
  102.         });
  103.     } catch (e) {
  104.         console.log('err while loading the page: '+e);
  105.     }
  106.  
  107.     // await delay(5000);
  108.  
  109.  
  110.     console.log('adding modifed script');
  111.     try {
  112.  
  113.         const path = require('path');
  114.         let file = fs.readFileSync(path.resolve('.', '_netflix.js'), 'utf8');
  115.         file = file.replace('RECAPTCHA_TOKEN', token);
  116.         await page.addScriptTag({ content: file });
  117.     } catch (e) {
  118.         console.log('failed to insert script: '+e);
  119.     }
  120.  
  121.     await delay(3000);
  122.  
  123.     console.log('filling form ..');
  124.  
  125.     const loginInput= await page.$(`#id_userLoginId`)
  126.     await loginInput.focus();
  127.     await page.type(`#id_userLoginId`,login)
  128.  
  129.     await delay(1000);
  130.  
  131.     const passwordInput= await page.$(`#id_password`)
  132.     await passwordInput.focus();
  133.     await page.type(`#id_password`,password)
  134.  
  135.  
  136.     await delay(1000);
  137.  
  138.     console.log('clicking the button');
  139.  
  140.     await Promise.all([
  141.         page.click("#appMountPoint > div > div.login-body > div > div > div.hybrid-login-form-main > form > button"),
  142.         page.waitForNavigation({ waitUntil: 'networkidle0' }),
  143.     ]);
  144.  
  145.  
  146.  
  147. })();
  148.  
  149.  
  150.  
  151. function delay(time) {
  152.    return new Promise(function(resolve) {
  153.        setTimeout(resolve, time)
  154.    });
  155. }
  156.  
  157.  
  158.  
  159. function successCallback() {
  160.     console.log('Successfully passed: ');
  161.     // console.log('closing browser .. ');
  162.     // browser.close();
  163. }
  164.  
  165. function failCallback(code) {
  166.     console.log('Failed to pass: '+code);
  167.     // console.log('closing browser .. ');
  168.     // browser.close();
  169. }
  170.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement