CGC_Codes

fightmilk captcha bypass

Nov 11th, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const path = require('path');
  2. const faker = require('faker');
  3. const Nightmare = require('nightmare');
  4. require('nightmare-upload')(Nightmare);
  5.  
  6. const SELECTOR = {
  7.  
  8.   captcha: `[style="color:white;font-weight:bold;padding-left:25px;font-size:18px;background:url('/PartnerRegistrationForm-portlet/images/capchaback.png') no-repeat;"]`,
  9.   name: '[name=_partneractionclass_WAR_PartnerRegistrationFormportlet_name]',
  10.   telno: '[name=_partneractionclass_WAR_PartnerRegistrationFormportlet_telno]',
  11.   email: '[name=_partneractionclass_WAR_PartnerRegistrationFormportlet_email]',
  12.   fax: '[name=_partneractionclass_WAR_PartnerRegistrationFormportlet_fax]',
  13.   tinno: '[name=_partneractionclass_WAR_PartnerRegistrationFormportlet_tinno]',
  14.   attachfile: '[name=_partneractionclass_WAR_PartnerRegistrationFormportlet_attachfile]',
  15.   exe: '[name=exe]',
  16.   usercode: '[name=_partneractionclass_WAR_PartnerRegistrationFormportlet_usercode]',
  17.   submit: 'button[type=submit]',
  18. };
  19.  
  20. const insa = (url, options) => {
  21.   let insaWait = null;
  22.  
  23.   const nightmare = Nightmare(Object.assign({
  24.     show: true,
  25.     typeInterval: 32,
  26.   }, options));
  27.  
  28.  
  29.   const errorHandler = (error) => {
  30.     clearInterval(insaWait);
  31.     nightmare.halt();
  32.     console.error(error);
  33.   };
  34.  
  35.   const run = (subscribe) => {
  36.    
  37.     nightmare
  38.      
  39.       .wait(SELECTOR.captcha)
  40.  
  41.       .evaluate((_selector) => {
  42.         let interval = null;
  43.  
  44.         return new Promise((resolve) => {
  45.           interval = setInterval(() => {
  46.             if (document.querySelector(_selector.captcha) !== null) {
  47.               clearInterval(interval);
  48.               resolve(document.querySelector(_selector.captcha).innerHTML);
  49.             }
  50.           }, 500);
  51.         });
  52.       }, SELECTOR)
  53.       .then((token) => {
  54.        
  55.         if (!token || token.length !== 11) {
  56.           console.log('> token clear');
  57.           clearInterval(insaWait);
  58.           run(subscribe);
  59.           return;
  60.         }
  61.  
  62.        
  63.         const [name, telno, email, fax, tinno] = [
  64.           faker.name.findName(),
  65.           faker.phone.phoneNumber().replace(/ x.+$/, ''),
  66.           faker.internet.email(),
  67.           faker.phone.phoneNumber().replace(/ x.+$/, ''),
  68.           faker.phone.phoneNumber().replace(/ x.+$/, ''),
  69.         ];
  70.  
  71.        
  72.         nightmare
  73.           .type(SELECTOR.name, name)
  74.           .type(SELECTOR.telno, telno)
  75.           .type(SELECTOR.email, email)
  76.           .type(SELECTOR.fax, fax)
  77.           .type(SELECTOR.tinno, tinno)
  78.           .upload(SELECTOR.attachfile, path.resolve('./Fight-Milk.pdf'))
  79.           .type(SELECTOR.usercode, token)
  80.           .click(SELECTOR.submit)
  81.           .then(() => {
  82.            
  83.             if (insaWait !== null) {
  84.               clearInterval(insaWait);
  85.             }
  86.  
  87.  
  88.             insaWait = setInterval(() => {
  89.               nightmare
  90.                
  91.                 .wait(SELECTOR.name)
  92.                 .evaluate((_selector) => {
  93.                   let interval = null;
  94.  
  95.                   return new Promise((resolve) => {
  96.                     interval = setInterval(() => {
  97.                       if (document.querySelector(_selector.name) !== null) {
  98.                         clearInterval(interval);
  99.                         resolve(document.querySelector(_selector.name).value);
  100.                       }
  101.                     }, 500);
  102.                   });
  103.                 }, SELECTOR)
  104.                 .then((nameValue) => {
  105.                  
  106.                   if (typeof nameValue === 'string' && nameValue.length === 0) {
  107.                     if (subscribe) {
  108.                       subscribe({ name, telno, email, fax, tinno });
  109.                     }
  110.  
  111.                    
  112.                     clearInterval(insaWait);
  113.                     run(subscribe);
  114.                   }
  115.                 });
  116.             }, 1000);
  117.           }, errorHandler);
  118.       }, errorHandler);
  119.   };
  120.  
  121.   try {
  122.     nightmare.goto(url);
  123.   } catch (error) {
  124.     errorHandler(error);
  125.   }
  126.  
  127.   return {
  128.     run,
  129.     insaWait,
  130.     nightmare,
  131.   };
  132. };
  133.  
  134. module.exports = insa;
Advertisement
Add Comment
Please, Sign In to add comment