Patey

Untitled

Mar 14th, 2022
676
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.58 KB | None | 0 0
  1. #include <iostream>
  2. #include <list>
  3. #include <cstring>
  4. #include <crypt.h>
  5.  
  6. using namespace std;
  7.  
  8. string target_salt = "$6$vRG0kupk$";
  9. string target_pw_hash = "$6$vRG0kupk$CjyuwyAIoOO1lu5VIOtrtGb0WJZCAxqYZ7h8rpfguszS.EuDJCGoX1d8b30Ird.VnHruFS7T2cKWxfnuvkjxZ1";
  10.  
  11. #define MAX_LEN 8
  12.  
  13. list<char*> pwlist;
  14.  
  15. int check_password(char* pw, char* salt, char* hash)
  16. {
  17. char* pass_true,*pass_cst;
  18. pass_true = new char [110];
  19. int len;
  20. for(int i=0;i<strlen(pw);i++)
  21. {
  22.     if(pw[i]=='a')
  23.     {
  24.         pass_cst=new char[3];
  25.         strcpy(pass_cst,"the");
  26.         strcat(pass_true,pass_cst);
  27.     }
  28.      if(pw[i]=='b')
  29.     {
  30.         pass_cst=new char[3];
  31.         strcpy(pass_cst,"big");
  32.         strcat(pass_true,pass_cst);
  33.     }
  34.      if(pw[i]=='c')
  35.     {
  36.         pass_cst=new char[5];
  37.         strcpy(pass_cst,"brown");
  38.         strcat(pass_true,pass_cst);
  39.     }
  40.      if(pw[i]=='d')
  41.     {
  42.         pass_cst=new char[3];
  43.         strcpy(pass_cst,"fox");
  44.         strcat(pass_true,pass_cst);
  45.     }
  46.      if(pw[i]=='e')
  47.     {
  48.         pass_cst=new char[2];
  49.         strcpy(pass_cst,"or");
  50.         strcat(pass_true,pass_cst);
  51.     }
  52.      if(pw[i]=='f')
  53.     {
  54.         pass_cst=new char[5];
  55.         strcpy(pass_cst,"small");
  56.         strcat(pass_true,pass_cst);
  57.     }
  58.      if(pw[i]=='g')
  59.     {
  60.         pass_cst=new char[4];
  61.         strcpy(pass_cst,"gray");
  62.         strcat(pass_true,pass_cst);
  63.     }
  64.      if(pw[i]=='h')
  65.     {
  66.         pass_cst=new char[8];
  67.         strcpy(pass_cst,"elephant");
  68.         strcat(pass_true,pass_cst);
  69.     }
  70.     pass_true[strlen(pass_true)]='\0';
  71. }
  72. char* res = crypt(pass_true, salt);
  73. cout << "password " << pass_true << "\n";
  74.  cout << "hashes to " << res << "\n";
  75.  for (int i = 0; i<strlen(hash); i++)
  76.    if (res[i]!=hash[i])
  77.    return 0;
  78. cout << "match !!!" << "\n";
  79.  return 1;
  80. }
  81.  
  82. char* exhaustive_search(char* charset, char* salt, char* target)
  83. {
  84. char* current_password;
  85. char* new_password; int i, current_len;
  86.  
  87. for (i = 0; i<strlen(charset); i++)
  88. {  
  89.  new_password = new char[2];
  90.  new_password[0] = charset[i];
  91.  new_password[1] = '\0';
  92.  pwlist.push_back(new_password);  
  93. }
  94.  
  95. while(true){    
  96.  
  97.  if (pwlist.empty()) return NULL;
  98.  
  99. current_password = pwlist.front();
  100. current_len = strlen(current_password);
  101.  
  102. int k=1,a[8]={0};
  103. if(current_password[0]!='a')
  104.     k=0;
  105. if(current_password[7]!='d')
  106.     k=0;
  107. for(int i=0;i<current_len-1;i++)
  108. {
  109.     for(int j=i+1;j<current_len;j++)
  110.     {
  111.         if(current_password[i]==current_password[j])
  112.             k=0;
  113.     }
  114. }
  115.  
  116. if(k)
  117. {
  118.     if  (check_password(current_password,   salt,   target))    
  119.         return current_password;
  120.  
  121. }
  122.  if(current_len < MAX_LEN){
  123.  for (i = 0; i < strlen(charset); i++)
  124.  {
  125.      new_password = new char[current_len + 2];
  126.      memcpy(new_password, current_password, current_len);
  127.      new_password[current_len] = charset[i];
  128.      new_password[current_len+1] = '\0';  
  129.      pwlist.push_back(new_password);
  130.  }
  131. }
  132.  pwlist.pop_front();
  133. }
  134. }
  135.  
  136. int main()
  137. {
  138.  char* salt;
  139.   char* target;
  140.     char* password;
  141.  
  142.  char charset[] = {'a', 'b', 'c', 'd', 'e', 'f','g','h', '\0'};  
  143.   salt = new char[target_salt.length()+1];
  144.  copy(target_salt.begin(), target_salt.end(), salt);
  145.  target = new char[target_pw_hash.length()+1];
  146.  copy(target_pw_hash.begin(), target_pw_hash.end(), target);
  147.  
  148.  password = exhaustive_search(charset, salt, target);
  149.  if (strlen(password)!= 0) cout << "Password successfuly recovered: " << password << "  \n";
  150.  else cout << "Failure to find password, try distinct character set of size \n";
  151. }
  152.  
  153.  
Advertisement
Add Comment
Please, Sign In to add comment