Patey

Untitled

Mar 3rd, 2022
935
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <list>
  3. #include <cstring>
  4. #include <crypt.h>
  5. using namespace std;
  6. string target_salt = "$6$SvT3dVpN$";
  7. string target_pw_hash = "$6$SvT3dVpN$JhGxjcfNohXabpUDTbVMSKjJjLAOWg40Tu6fd8r2G1fmVRuKtXG.v506DJColxY.2RnG5whjAR/0BsjZTxrOa1";
  8.  
  9. char null[] = { '\0' };
  10.  
  11. #define MAX_LEN 19
  12. list<char*> pwlist;
  13.  
  14. int check_password(char* pw, char* salt, char* hash)
  15. {
  16.     char* res = crypt(pw, salt);
  17.     cout << "password " << pw << "\n";
  18.     cout << "hashes to " << res << "\n";
  19.     for (int i = 0; i < strlen(hash); i++)
  20.         if (res[i] != hash[i]) return 0;
  21.     cout << "match !!!" << "\n";
  22.     return 1;
  23. }
  24.  
  25.  
  26. char* exhaustive_search(char* charset, char* salt, char* target)
  27. {
  28.     char* current_password;
  29.     char* new_password;
  30.     char* pass_cst;
  31.     int i, current_len, len_cst;
  32.    
  33.     pass_cst=new char[14];
  34.     memcpy(pass_cst,">>>sec22_is<<<",14);
  35.     len_cst = strlen(pass_cst);
  36.     for (i = 0; i < strlen(charset); i++) {
  37.        
  38.         new_password = new char[len_cst + 2];
  39.                 memcpy(new_password, pass_cst,len_cst);
  40.                 new_password[len_cst] = charset[i];
  41.                 new_password[len_cst+1] = '\0';
  42.                 pwlist.push_back(new_password);
  43.     }
  44.     while (true) {
  45.  
  46.         if (pwlist.empty())
  47.             return null;
  48.        
  49.         current_password = pwlist.front();
  50.         current_len = strlen(current_password);
  51.       // if(current_len == MAX_LEN){
  52.         if (check_password(current_password, salt, target))
  53.             return current_password;
  54.             //}
  55.         if(current_len < MAX_LEN){
  56.             for (i = 0; i < strlen(charset); i++){
  57.                 new_password = new char[current_len + 2];
  58.                 memcpy(new_password, current_password, current_len);
  59.                 new_password[current_len] = charset[i];
  60.                 new_password[current_len+1] = '\0';
  61.                 pwlist.push_back(new_password);
  62.             }
  63.         }
  64.  
  65.         pwlist.pop_front();
  66.     }
  67. }
  68. int main()
  69. {
  70.     char* salt;
  71.     char* target;
  72.     char* password;
  73.  
  74.     char charset[] = { 'a', 'b', 'c', 'd', 'e', 'f','g','h','i','j','k','l','m','n','o','p','q','u','r','s','t','v','w','x','y','z','1','2','3','4','5','6','7','8','9','0','!','@','^','#','$','%','&','*','(',')','\0' };
  75.     salt = new char[target_salt.length() + 1];
  76.     copy(target_salt.begin(), target_salt.end(), salt);
  77.     target = new char[target_pw_hash.length() + 1];
  78.     copy(target_pw_hash.begin(), target_pw_hash.end(), target);
  79.  
  80.     password = exhaustive_search(charset, salt, target);
  81.     if (strlen(password) != 0) cout << "Password successfuly recovered: " <<
  82.         password << " \n";
  83.     else cout << "Failure to find password, try distinct character set of size \n";
  84. }
Advertisement
Add Comment
Please, Sign In to add comment