Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.06 KB | None | 0 0
  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.substring(0, stripes.indexOf('/', stripes.indexOf('//') + 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. .cookies.get({url: null})
  193. .then(function (cookies) {
  194. console.log(cookies);
  195. })
  196. .then(function () {
  197. console.log('///');
  198. }).catch(function (err) {
  199. console.log('error ', err);
  200. console.error(util.inspect(error));
  201. });
  202. }
  203. }
  204.  
  205. function party(nm, i) {
  206. nm.exists(config.splashUniqueIdentifier)
  207. .then(function (isSplash) {
  208. if (isSplash) {
  209. if (config.singleSuccess) {
  210. killSwitch(nm);
  211. }
  212. return nm.html(`./page-source/${new Date().toString()}.html`, "HTMLComplete")
  213. .then(function () {
  214. return nm.cookies.get({url: null})
  215. .then(function (cookies) {
  216. console.log(chalk.bgBlack.yellow('******************************************'));
  217. console.log(chalk.bgBlack.yellow('Passed Splash On Browser ' + (i + 1) + ' Extracting Information...'));
  218. console.log(chalk.bgBlack.yellow('Passed Time ' + (i + 1) + ' ' + Date()));
  219. console.log(chalk.bgBlack.yellow('******************************************'));
  220.  
  221. console.log(chalk.bgBlack.cyan('******************************************'));
  222. console.log(chalk.bgBlack.cyan('Complete Cookie Output'));
  223. console.log(chalk.bgBlack.cyan('******************************************'));
  224. console.log(JSON.stringify(cookies));
  225.  
  226.  
  227. console.log(chalk.bgBlack.green('******************************************'));
  228. console.log(chalk.bgBlack.green('Suspected HMAC Cookie(s):'));
  229. console.log(chalk.bgBlack.green('******************************************'));
  230. console.log(JSON.stringify(_.filter(cookies, function (cookie) {
  231. return _.includes(cookie.value, 'hmac');
  232. })));
  233. console.log(chalk.bgBlack.green('******************************************'));
  234. }).then(function () {
  235. return nm.evaluate(function () {
  236. var action = document.querySelector('#flashproductform');
  237. if (action) {
  238. action = action.getAttribute('action');
  239. return action.substr(action.indexOf('clientId=') + 9, action.length);
  240. } else {
  241. return ''
  242. }
  243. });
  244. }).then(function (clientid) {
  245. console.log(chalk.bgBlack.green('******************************************'));
  246. console.log(chalk.bgBlack.green('Client ID:'));
  247. console.log(chalk.bgBlack.green('******************************************'));
  248. console.log(chalk.bgBlack.yellow('Browser ' + (i + 1) + ': ') + clientid);
  249. console.log(chalk.bgBlack.green('******************************************'));
  250. return nm.cookies.set({
  251. name: 'd3stripesClientId',
  252. value: clientid,
  253. path: '/',
  254. url: stripesCookieDomain
  255. })
  256. }).then(function () {
  257. return nm.evaluate(function () {
  258. if (window.captchaResponse) {
  259. return window.captchaResponse.toString();
  260. } else {
  261. return '';
  262. }
  263. });
  264. }).then(function (dupFunction) {
  265. var matches = dupFunction.match(/name=\"([A-Za-z0-9\-]+)\"/),
  266. dupCookie = matches && matches.length > 1 ? matches[1] : '';
  267. console.log(chalk.bgBlack.green('******************************************'));
  268. console.log(chalk.bgBlack.green('Captcha-Dup:'));
  269. console.log(chalk.bgBlack.green('******************************************'));
  270. if (matches) {
  271. console.log(chalk.bgBlack.yellow('Browser ' + (i + 1) + ': ') + matches[1]);
  272. }
  273. else {
  274. console.log(chalk.bgBlack.yellow('Browser ' + (i + 1) + ': ') + dupFunction.substr(dupFunction.indexOf("$('#flashproductform').append"), dupFunction.length));
  275. }
  276. console.log(chalk.bgBlack.green('******************************************'));
  277. return nm.cookies.set({
  278. name: 'd3stripesDuplicate',
  279. value: dupCookie,
  280. path: '/',
  281. url: stripesCookieDomain
  282. })
  283. }).then(function () {
  284. return nm.evaluate(function () {
  285. var sitekey = document.querySelector('[data-sitekey]');
  286. if (sitekey) {
  287. return sitekey.getAttribute('data-sitekey');
  288. } else {
  289. return '';
  290. }
  291. });
  292. }).then(function (sitekey) {
  293. console.log(chalk.bgBlack.green('******************************************'));
  294. console.log(chalk.bgBlack.green('Site Key:'));
  295. console.log(chalk.bgBlack.green('******************************************'));
  296. console.log(chalk.bgBlack.yellow('Browser ' + (i + 1) + ': ') + sitekey);
  297. console.log(chalk.bgBlack.green('******************************************'));
  298. console.log(chalk.bgBlack.yellow('******************************************'));
  299. console.log(chalk.bgBlack.yellow('End Of Input For Browser ' + (i + 1)));
  300. console.log(chalk.bgBlack.yellow('******************************************') + '\n\n\n\n');
  301. return nm.cookies.set([
  302. {
  303. name: 'd3stripesSiteKey',
  304. value: sitekey,
  305. path: '/',
  306. url: stripesCookieDomain
  307. },
  308. {
  309. name: 'd3stripesSku',
  310. value: config.SKU,
  311. path: '/',
  312. url: stripesCookieDomain
  313. },
  314. {
  315. name: 'd3stripesLocale',
  316. value: config.locale,
  317. path: '/',
  318. url: stripesCookieDomain
  319. }
  320. ])
  321. }).then(function () {
  322. if (config.hmacOnly) {
  323. nm.end();
  324. } else {
  325. return nm.show();
  326. }
  327. }).then(function () {
  328. if (config.fuckNikeTalk && !config.hmacOnly) {
  329. return nm.cookies.get({url: null})
  330. .then(function (cookies) {
  331. cookieArr[i] = cookieTransform(cookies);
  332. }).then(function () {
  333. soleiusMartyrium(i);
  334. });
  335. }
  336.  
  337. if (!uploadedSource && config.enableSourceUpload) {
  338. uploadedSource = true;
  339. return nm.evaluate(function () {
  340. return document.querySelector('html').outerHTML;
  341. }).then(function (html) {
  342. postPageSource(html);
  343. }).catch(function (error) {
  344. console.error('an error has occurred: ' + error);
  345. console.error(util.inspect(error));
  346. nm.end();
  347. });
  348. }
  349. }).catch(function (error) {
  350. console.error('an error has occurred: ' + error);
  351. console.error(util.inspect(error));
  352. nm.end();
  353. });
  354. }).catch(function (error) {
  355. console.error('an error has occurred: ' + error);
  356. console.error(util.inspect(error));
  357. nm.end();
  358. });
  359. } else {
  360. return nm
  361. .wait(config.waitTime)
  362. .then(function () {
  363. return nm.cookies.clearAll()
  364. })
  365. .then(function () {
  366. return nm.clearCache()
  367. })
  368. .then(function () {
  369. return nm.refresh();
  370. })
  371. .then(function () {
  372. party(nm, i);
  373. }).catch(function (error) {
  374. console.error('an error has occurred: ' + error);
  375. console.error(util.inspect(error));
  376. nm.end();
  377. });
  378. }
  379. }).catch(function (error) {
  380. console.error('an error has occurred: ' + error);
  381. nm.end();
  382. });
  383. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement