Patey

Untitled

Feb 26th, 2022
686
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.26 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$lwb3GViLl0J0ntNk5BAWe2WtkbjSBMXtSkDCtZUkVhVPiz5X37WflWL4k3ZUusdoyh7IOUlSXE1jUHxIrg29p.";
  8.  
  9. char null[] = { '\0' };
  10.  
  11. #define MAX_LEN 10
  12. list<char*> pwlist;
  13.  
  14. int check_password(char* pw, char* salt, char* hash)
  15. {
  16.     char* res = crypt(pw, salt);
  17.     for (int i = 0; i < strlen(hash); i++)
  18.         if (res[i] != hash[i]) return 0;
  19.     cout << "match !!!" << "\n";
  20.     cout << "password " << pw << "\n";
  21.     cout << "hashes to " << res << "\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.     int i, current_len;
  31.  
  32.     for (i = 0; i < strlen(charset); i++) {
  33.         new_password = new char[2];
  34.         new_password[0] = charset[i];
  35.         new_password[1] = '\0';
  36.         pwlist.push_back(new_password);
  37.     }
  38.     while (true) {
  39.  
  40.         if (pwlist.empty()) return null;
  41.  
  42.         current_password = pwlist.front();
  43.         current_len = strlen(current_password);
  44.  
  45.         if (check_password(current_password, salt, target))
  46.             return current_password;
  47.  
  48.  
  49.         if (current_len < MAX_LEN) {
  50.             for (i = 0; i < strlen(charset); i++) {
  51.                 new_password = new char[current_len + 2];
  52.                 memcpy(new_password, current_password, current_len);
  53.                 if (new_password[current_len - 1] == '!' or new_password[current_len - 1] == '@' or new_password[current_len - 1] == '#')
  54.                 {
  55.                     if(i>4)
  56.                         new_password[current_len] = charset[i];
  57.                 }
  58.                 else
  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', '1', '2', '!','@','#', '\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