Advertisement
Guest User

main

a guest
Jun 21st, 2011
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.11 KB | None | 0 0
  1. /*
  2.  
  3. w3b_cr4ck v1.0
  4.  
  5. */
  6.  
  7.  
  8. #include <iostream>
  9. #include <fstream>
  10. #include <string>
  11. #include <ctime>
  12.  
  13. #include "parse_args.hpp"
  14.  
  15. using namespace std;
  16.  
  17.  
  18. bool VERBOSE = false;
  19. bool RANDOMIZE = false;
  20.  
  21. enum Hash_Type { NaN = -1, MD5 = 1, SHA1 = 2 } HT = NaN;
  22.  
  23.  
  24. int w3b_cr4ck(int, int, string);
  25.  
  26.  
  27.  
  28. char *display_date_time() {
  29.    
  30.     time_t uts;
  31.     struct tm *time_info;
  32.  
  33.     time(&uts);
  34.     time_info = localtime(&uts);
  35.    
  36.     return(asctime(time_info));
  37.    
  38. }
  39.  
  40.  
  41.  
  42. bool set_hash_type(string hash) {
  43.    
  44.     for(unsigned int x = 0; x < hash.length(); x++)
  45.     {
  46.          if(!(((hash[x] > (0x2F)) && (hash[x] < (0x3A))) || ((hash[x] > (0x60)) && (hash[x] < (0x67)))))
  47.          {
  48.               cout << "\n\n~! hash is invalid !~\n\n";
  49.               return(false);
  50.          }
  51.     }
  52.      
  53.     switch(hash.length())
  54.     {
  55.          case(32):
  56.               HT = MD5;
  57.               if(VERBOSE) cout << "\nHASH TYPE : MD5\n";
  58.               return(true);
  59.          case(40):
  60.               HT = SHA1;
  61.               if(VERBOSE) cout << "\nHASH TYPE : SHA1\n";
  62.               return(true);
  63.          default:
  64.               cout << "\n\n~! hash is invalid !~\n\n";
  65.               return(false);
  66.     }
  67.    
  68. }
  69.  
  70.  
  71.  
  72. int main(int argc, char *argv[]) {
  73.    
  74.     cout << "\nw3b_cr4ck started " << display_date_time();
  75.    
  76.     options opts = parse_args(argc, argv);
  77.    
  78.     if(!opts.single_hash.empty())
  79.     {
  80.          if(set_hash_type(opts.single_hash))
  81.          {
  82.               if(VERBOSE) cout << "attempting to crack " << opts.single_hash;
  83.              
  84.               w3b_cr4ck(HT, opts.top, opts.single_hash);
  85.              
  86.          } else return(-1);
  87.          
  88.     } else { // file of hashes
  89.          
  90.          ifstream FILE(opts.file_loc.c_str());
  91.          
  92.          if(FILE.is_open())
  93.          {
  94.               char hash[41];
  95.               float cracked = 0, total = 0;
  96.              
  97.               if(VERBOSE) cout << endl << opts.file_loc.c_str() << "opened succesfully!\n\n";
  98.              
  99.               while(1337)
  100.               {
  101.                    FILE.getline(hash, 41);
  102.                    
  103.                    if(FILE.eof()) break;
  104.                    
  105.                    if(set_hash_type(hash))
  106.                    {
  107.                         if(VERBOSE) cout << "attempting to crack " << hash << endl;
  108.                        
  109.                         cracked += w3b_cr4ck(HT, opts.top, hash);
  110.                        
  111.                         total += 1;
  112.                        
  113.                    } else cout << "\nskipping to the next hash\n";
  114.                    
  115.               }
  116.              
  117.               if(VERBOSE)
  118.               {
  119.                    cout.precision(4);
  120.                    
  121.                    cout << "\ncracked (" << cracked << " / " << total << ") valid hashes [ " << ((cracked*100)/total) << "% ]\n";
  122.               }
  123.              
  124.          } else {
  125.          
  126.               cout << "\n\n~! Unable to open file !~\n\n";
  127.              
  128.               return(-1);
  129.              
  130.          }
  131.          
  132.     }
  133.    
  134.     return(0);
  135.    
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement