AyrA

nodeJS Password cracker

Apr 7th, 2016
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //This is a very specific password cracker for bcrypt.
  2. //It cracks from 0A0 to 99z999 and thus is probably useless for you.
  3. //Made for https://redd.it/4dqeyz
  4. var util=require("util");
  5. var bcrypt=require("bcrypt");
  6. var cluster=require("cluster");
  7. var numCPUs=require("os").cpus().length;;
  8.  
  9. var charset="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
  10. var hash="$2a$10$Cv/hHXntAbMoFbZ9.fFNbeNdi26sc15eo04ruHTfk8xhuza88.xq6";
  11. var id=0;
  12. var last=null;
  13.  
  14. charset=charset.reverse().join("");
  15.  
  16. //The master process needs to do different stuff
  17. if(cluster.isMaster)
  18. {
  19.     var childs=[];
  20.     var hashes=[];
  21.     var count=0;
  22.     var total=0;
  23.     var start=Date.now();
  24.     //spawn one slave for each CPU code in our system.
  25.     for (var i = 0; i < numCPUs; i++)
  26.     {
  27.         childs.push(cluster.fork());
  28.     }
  29.     //display stats once a second
  30.     setInterval(function(){
  31.         //clears screen and moves cursor to top left
  32.         util.print("\u001b[2J\u001b[0;0H");
  33.         console.log("H/s",count);
  34.         console.log("Total",total);
  35.         console.log("Runtime:",((Date.now()-start)/1000)|0,"sec");
  36.         hashes.forEach(function(v,i){
  37.             console.log(i,v);
  38.         });
  39.         count=0;
  40.     },1000);
  41.     //hook to message events from children
  42.     childs.forEach(function(v,i){
  43.         v.on("message",function(m)
  44.         {
  45.             if(m.msg==="count")
  46.             {
  47.                 ++count;
  48.                 ++total;
  49.             }
  50.             hashes[i]=m.hash;
  51.         });
  52.     });
  53. }
  54. else if(cluster.isWorker)
  55. {
  56.     id=cluster.worker.id;
  57.     console.log(id,"started");
  58.     //counts down from 99 to 0 (1st part of password)
  59.     for(var i=99;i>=0;i--)
  60.     {
  61.         //counts down all possible letters (2nd part of password)
  62.         for(var k=0;k<charset.length;k++)
  63.         {
  64.             //counts down from 999 to 0 (3rd part of password)
  65.             //here we don't subtract only one and we have different starting values.
  66.             //Each slave will thus have a different password to test
  67.             for(var j=999-id;j>=0;j-=numCPUs)
  68.             {
  69.                 //if the password is correct, print it and then exit
  70.                 if(bcrypt.compareSync(i+charset[k]+j,hash))
  71.                 {
  72.                     console.log("DONE! Password:",i+charset[k]+j);
  73.                     process.exit();
  74.                 }
  75.                 process.send({msg:"count",hash:i+charset[k]+j});
  76.             }
  77.         }
  78.     }
  79. }
Add Comment
Please, Sign In to add comment