Facebook
From Commodious Hog, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 256
  1. var Nightmare = require('nightmare');
  2. var _ = require('lodash');
  3. var request = require('request');
  4. var config = require('./config');
  5. var chalk = require('chalk');
  6. var wait = require('nightmare-wait-for-url');
  7. var util = require('util');
  8.  
  9. var uploadedSource = false;
  10.  
  11. var cookieArr = new Array(config.partySize);
  12.  
  13.  
  14. function cookieTransform(cookies) {
  15.     var updated = [];
  16.     _.each(cookies, function (cookie) {
  17.         var url = '';
  18.         if (cookie.secure) {
  19.             url += 'https://';
  20.         } else {
  21.             url += 'http://';
  22.         }
  23.  
  24.         if (cookie.domain.startsWith('.')) {
  25.             url += 'www';
  26.         }
  27.  
  28.         url += cookie.domain;
  29.  
  30.         updated.push(_.assign({url: url}, _.omit(cookie, 'domain')))
  31.     });
  32.  
  33.     return updated;
  34. }
  35.  
  36. function getStripesUrl() {
  37.     var stripes = config.stripesUrl,
  38.         portIndex = stripes.indexOf(':', stripes.indexOf(':') + 1);
  39.  
  40.     if (portIndex > -1) {
  41.         return stripes.substring(0, portIndex)
  42.     } else {
  43.         return stripes.match(/(http.*\/\/.*)\//)[1];
  44.     }
  45. }
  46.  
  47. Nightmare.action('show',
  48.     function (name, options, parent, win, renderer, done) {
  49.         parent.respondTo('show', function (done) {
  50.             win.show();
  51.             done();
  52.         });
  53.         done();
  54.     },
  55.     function (done) {
  56.         this.child.call('show', done);
  57.     });
  58.  
  59. Nightmare.action('hide',
  60.     function (name, options, parent, win, renderer, done) {
  61.         parent.respondTo('hide', function (done) {
  62.             win.hide();
  63.             done();
  64.         });
  65.         done();
  66.     },
  67.     function (done) {
  68.         this.child.call('hide', done);
  69.     });
  70.  
  71.  
  72. Nightmare.action('clearCache',
  73.     function (name, options, parent, win, renderer, done) {
  74.         parent.respondTo('clearCache', function (done) {
  75.             win.webContents.session.clearCache(done);
  76.             done();
  77.  
  78.         });
  79.         done();
  80.     },
  81.     function (done) {
  82.         this.child.call('clearCache', done);
  83.     });
  84.  
  85.  
  86. Nightmare.action('printUserAgent',
  87.     function (name, options, parent, win, renderer, done) {
  88.         parent.respondTo('printUserAgent', function (done) {
  89.             done(null, win.webContents.getUserAgent());
  90.         });
  91.         done();
  92.     },
  93.     function (done) {
  94.         this.child.call('printUserAgent', done);
  95.     });
  96.  
  97. Nightmare.action('keepTitle',
  98.     function (name, options, parent, win, renderer, done) {
  99.         parent.respondTo('keepTitle', function (done) {
  100.             win.on('page-title-updated', function (event) {
  101.                 event.preventDefault()
  102.             });
  103.             done();
  104.         });
  105.         done();
  106.     },
  107.     function (done) {
  108.         this.child.call('keepTitle', done);
  109.     });
  110.  
  111. function postPageSource(src) {
  112.     request.post({
  113.         url: 'https://snippets.glot.io/snippets',
  114.         json: true,
  115.         headers: {
  116.             'Authorization': 'Token d94a031a-d97a-4276-887e-ed4894875579'
  117.         },
  118.         body: {
  119.             "language": "plaintext",
  120.             "title": config.splashUrl,
  121.             "public": true,
  122.             "files": [{"name": "productpage.html", "content": src}]
  123.         }
  124.     })
  125. }
  126.  
  127.  
  128. var browserArr = new Array(config.partySize);
  129.  
  130. var stripesCookieDomain = getStripesUrl();
  131.  
  132. _.each(browserArr, function (browser, i) {
  133.     browserArr[i] = Nightmare({
  134.         show: false,
  135.         alwaysOnTop: false,
  136.         webPreferences: {
  137.             partition: i
  138.         }
  139.     }).useragent(config.userAgent)
  140.         .cookies.clearAll()
  141.         .clearCache()
  142.         .cookies.set(cookieTransform(config.gCookies));
  143.  
  144.     setTimeout(function () {
  145.         browserArr[i]
  146.             .goto(config.splashUrl)
  147.             .then(function () {
  148.                 party(browserArr[i], i);
  149.             }).catch(function (error) {
  150.             console.error('an error has occurred: ' + error);
  151.             console.error(util.inspect(error));
  152.             browserArr[i].end();
  153.         });
  154.     }, 1000 * i);
  155. });
  156.  
  157. function killSwitch(nm) {
  158.     _.each(browserArr, function (browser) {
  159.         if (browser !== nm) {
  160.             browser.end();
  161.         }
  162.     });
  163. }
  164.  
  165. function soleiusMartyrium(i) {
  166.     var stripes = Nightmare({
  167.         show: true,
  168.         alwaysOnTop: false,
  169.         title: Date(),
  170.         waitTimeout: 120000,
  171.         webPreferences: {
  172.             partition: i
  173.         }
  174.     }).useragent(config.userAgent)
  175.         .keepTitle()
  176.         .cookies.set(cookieArr[i]);
  177.  
  178.    if (config.fuckGmail) {
  179.     stripes
  180.         .goto('https://www.gmail.com')
  181.         .waitForUrl(/^https:\/\/mail\.google\.com\/mail.*/)
  182.         .goto(config.stripesUrl)
  183.         .then(function () {
  184.             console.log('///');
  185.         }).catch(function (err) {
  186.         console.log('error ', err);
  187.         console.error(util.inspect(error));
  188.     });
  189.     } else {
  190.         stripes
  191.             .goto(config.stripesUrl)
  192.             .then(function () {
  193.                 console.log('///');
  194.             }).catch(function (err) {
  195.             console.log('error ', err);
  196.             console.error(util.inspect(error));
  197.         });
  198.     }
  199. }
  200.  
  201. function party(nm, i) {
  202.     nm.exists(config.splashUniqueIdentifier)
  203.         .then(function (isSplash) {
  204.             if (isSplash) {
  205.                 if (config.singleSuccess) {
  206.                     killSwitch(nm);
  207.                 }
  208.                 return nm.html(`./page-source/${new Date().toString()}.html`, "HTMLComplete")
  209.                     .then(function () {
  210.                         return nm.cookies.get({url: null})
  211.                             .then(function (cookies) {
  212.                                 console.log(chalk.bgBlack.yellow('******************************************'));
  213.                                 console.log(chalk.bgBlack.yellow('Passed Splash On Browser ' + (i + 1) + ' Extracting Information...'));
  214.                                 console.log(chalk.bgBlack.yellow('Passed Time ' + (i + 1) + ' ' + Date()));
  215.                                 console.log(chalk.bgBlack.yellow('******************************************'));
  216.  
  217.                                 console.log(chalk.bgBlack.cyan('******************************************'));
  218.                                 console.log(chalk.bgBlack.cyan('Complete Cookie Output'));
  219.                                 console.log(chalk.bgBlack.cyan('******************************************'));
  220.                                 console.log(JSON.stringify(cookies));
  221.  
  222.  
  223.                                 console.log(chalk.bgBlack.green('******************************************'));
  224.                                 console.log(chalk.bgBlack.green('Suspected HMAC Cookie(s):'));
  225.                                 console.log(chalk.bgBlack.green('******************************************'));
  226.                                 console.log(JSON.stringify(_.filter(cookies, function (cookie) {
  227.                                     return _.includes(cookie.value, 'hmac');
  228.                                 })));
  229.                                 console.log(chalk.bgBlack.green('******************************************'));
  230.                             }).then(function () {
  231.                                 return nm.evaluate(function () {
  232.                                     var action = document.querySelector('#flashproductform');
  233.                                     if (action) {
  234.                                         action = action.getAttribute('action');
  235.                                         return action.substr(action.indexOf('clientId=') + 9, action.length);
  236.                                     } else {
  237.                                         return ''
  238.                                     }
  239.                                 });
  240.                             }).then(function (clientid) {
  241.                                 console.log(chalk.bgBlack.green('******************************************'));
  242.                                 console.log(chalk.bgBlack.green('Client ID:'));
  243.                                 console.log(chalk.bgBlack.green('******************************************'));
  244.                                 console.log(chalk.bgBlack.yellow('Browser ' + (i + 1) + ': ') + clientid);
  245.                                 console.log(chalk.bgBlack.green('******************************************'));
  246.                                 return nm.cookies.set({
  247.                                     name: 'd3stripesClientId',
  248.                                     value: clientid,
  249.                                     path: '/',
  250.                                     url: stripesCookieDomain
  251.                                 })
  252.                             }).then(function () {
  253.                                 return nm.evaluate(function () {
  254.                                     if (window.captchaResponse) {
  255.                                         return window.captchaResponse.toString();
  256.                                     } else {
  257.                                         return '';
  258.                                     }
  259.                                 });
  260.                             }).then(function (dupFunction) {
  261.                                 var matches = dupFunction.match(/name=\"([A-Za-z0-9\-]+)\"/),
  262.                                     dupCookie = matches && matches.length > 1 ? matches[1] : '';
  263.                                 console.log(chalk.bgBlack.green('******************************************'));
  264.                                 console.log(chalk.bgBlack.green('Captcha-Dup:'));
  265.                                 console.log(chalk.bgBlack.green('******************************************'));
  266.                                 if (matches) {
  267.                                     console.log(chalk.bgBlack.yellow('Browser ' + (i + 1) + ': ') + matches[1]);
  268.                                 }
  269.                                 else {
  270.                                     console.log(chalk.bgBlack.yellow('Browser ' + (i + 1) + ': ') + dupFunction.substr(dupFunction.indexOf("$('#flashproductform').append"), dupFunction.length));
  271.                                 }
  272.                                 console.log(chalk.bgBlack.green('******************************************'));
  273.                                 return nm.cookies.set({
  274.                                     name: 'd3stripesDuplicate',
  275.                                     value: dupCookie,
  276.                                     path: '/',
  277.                                     url: stripesCookieDomain
  278.                                 })
  279.                             }).then(function () {
  280.                                 return nm.evaluate(function () {
  281.                                     var sitekey = document.querySelector('[data-sitekey]');
  282.                                     if (sitekey) {
  283.                                         return sitekey.getAttribute('data-sitekey');
  284.                                     } else {
  285.                                         return '';
  286.                                     }
  287.                                 });
  288.                             }).then(function (sitekey) {
  289.                                 console.log(chalk.bgBlack.green('******************************************'));
  290.                                 console.log(chalk.bgBlack.green('Site Key:'));
  291.                                 console.log(chalk.bgBlack.green('******************************************'));
  292.                                 console.log(chalk.bgBlack.yellow('Browser ' + (i + 1) + ': ') + sitekey);
  293.                                 console.log(chalk.bgBlack.green('******************************************'));
  294.                                 console.log(chalk.bgBlack.yellow('******************************************'));
  295.                                 console.log(chalk.bgBlack.yellow('End Of Input For Browser ' + (i + 1)));
  296.                                 console.log(chalk.bgBlack.yellow('******************************************') + '\n\n\n\n');
  297.                                 return nm.cookies.set([
  298.                                     {
  299.                                         name: 'd3stripesSiteKey',
  300.                                         value: sitekey,
  301.                                         path: '/',
  302.                                         url: stripesCookieDomain
  303.                                     },
  304.                                     {
  305.                                         name: 'd3stripesSku',
  306.                                         value: config.SKU,
  307.                                         path: '/',
  308.                                         url: stripesCookieDomain
  309.                                     },
  310.                                     {
  311.                                         name: 'd3stripesLocale',
  312.                                         value: config.locale,
  313.                                         path: '/',
  314.                                         url: stripesCookieDomain
  315.                                     }
  316.                                 ])
  317.                             }).then(function () {
  318.                                 if (config.hmacOnly) {
  319.                                     nm.end();
  320.                                 } else {
  321.                                     return nm.show();
  322.                                 }
  323.                             }).then(function () {
  324.                                 if (config.fuckNikeTalk && !config.hmacOnly) {
  325.                                     return nm.cookies.get({url: null})
  326.                                         .then(function (cookies) {
  327.                                             cookieArr[i] = cookieTransform(cookies);
  328.                                         }).then(function () {
  329.                                             soleiusMartyrium(i);
  330.                                         });
  331.                                 }
  332.  
  333.                                 if (!uploadedSource && config.enableSourceUpload) {
  334.                                     uploadedSource = true;
  335.                                     return nm.evaluate(function () {
  336.                                         return document.querySelector('html').outerHTML;
  337.                                     }).then(function (html) {
  338.                                         postPageSource(html);
  339.                                     }).catch(function (error) {
  340.                                         console.error('an error has occurred: ' + error);
  341.                                         console.error(util.inspect(error));
  342.                                         nm.end();
  343.                                     });
  344.                                 }
  345.                             }).catch(function (error) {
  346.                                 console.error('an error has occurred: ' + error);
  347.                                 console.error(util.inspect(error));
  348.                                 nm.end();
  349.                             });
  350.                     }).catch(function (error) {
  351.                         console.error('an error has occurred: ' + error);
  352.                         console.error(util.inspect(error));
  353.                         nm.end();
  354.                     });
  355.             } else {
  356.                 return nm
  357.                     .wait(config.waitTime)
  358.                     .then(function () {
  359.                         return nm.cookies.clearAll()
  360.                     })
  361.                     .then(function () {
  362.                         return nm.clearCache()
  363.                     })
  364.                     .then(function () {
  365.                         return nm.refresh();
  366.                     })
  367.                     .then(function () {
  368.                         party(nm, i);
  369.                     }).catch(function (error) {
  370.                         console.error('an error has occurred: ' + error);
  371.                         console.error(util.inspect(error));
  372.                         nm.end();
  373.                     });
  374.             }
  375.         }).catch(function (error) {
  376.         console.error('an error has occurred: ' + error);
  377.         nm.end();
  378.     });
  379. }
  380.  
  381.