Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <list>
- #include <cstring>
- #include <crypt.h>
- using namespace std;
- string target_salt = "$6$vRG0kupk$";
- string target_pw_hash = "$6$vRG0kupk$CjyuwyAIoOO1lu5VIOtrtGb0WJZCAxqYZ7h8rpfguszS.EuDJCGoX1d8b30Ird.VnHruFS7T2cKWxfnuvkjxZ1";
- #define MAX_LEN 8
- list<char*> pwlist;
- int check_password(char* pw, char* salt, char* hash)
- {
- char* pass_true,*pass_cst;
- pass_true = new char [110];
- int len;
- for(int i=0;i<strlen(pw);i++)
- {
- if(pw[i]=='a')
- {
- pass_cst=new char[3];
- strcpy(pass_cst,"the");
- strcat(pass_true,pass_cst);
- }
- if(pw[i]=='b')
- {
- pass_cst=new char[3];
- strcpy(pass_cst,"big");
- strcat(pass_true,pass_cst);
- }
- if(pw[i]=='c')
- {
- pass_cst=new char[5];
- strcpy(pass_cst,"brown");
- strcat(pass_true,pass_cst);
- }
- if(pw[i]=='d')
- {
- pass_cst=new char[3];
- strcpy(pass_cst,"fox");
- strcat(pass_true,pass_cst);
- }
- if(pw[i]=='e')
- {
- pass_cst=new char[2];
- strcpy(pass_cst,"or");
- strcat(pass_true,pass_cst);
- }
- if(pw[i]=='f')
- {
- pass_cst=new char[5];
- strcpy(pass_cst,"small");
- strcat(pass_true,pass_cst);
- }
- if(pw[i]=='g')
- {
- pass_cst=new char[4];
- strcpy(pass_cst,"gray");
- strcat(pass_true,pass_cst);
- }
- if(pw[i]=='h')
- {
- pass_cst=new char[8];
- strcpy(pass_cst,"elephant");
- strcat(pass_true,pass_cst);
- }
- pass_true[strlen(pass_true)]='\0';
- }
- char* res = crypt(pass_true, salt);
- cout << "password " << pass_true << "\n";
- cout << "hashes to " << res << "\n";
- for (int i = 0; i<strlen(hash); i++)
- if (res[i]!=hash[i])
- return 0;
- cout << "match !!!" << "\n";
- return 1;
- }
- char* exhaustive_search(char* charset, char* salt, char* target)
- {
- char* current_password;
- char* new_password; int i, current_len;
- for (i = 0; i<strlen(charset); i++)
- {
- new_password = new char[2];
- new_password[0] = charset[i];
- new_password[1] = '\0';
- pwlist.push_back(new_password);
- }
- while(true){
- if (pwlist.empty()) return NULL;
- current_password = pwlist.front();
- current_len = strlen(current_password);
- int k=1,a[8]={0};
- if(current_password[0]!='a')
- k=0;
- if(current_password[7]!='d')
- k=0;
- for(int i=0;i<current_len-1;i++)
- {
- for(int j=i+1;j<current_len;j++)
- {
- if(current_password[i]==current_password[j])
- k=0;
- }
- }
- if(k)
- {
- if (check_password(current_password, salt, target))
- return current_password;
- }
- if(current_len < MAX_LEN){
- for (i = 0; i < strlen(charset); i++)
- {
- new_password = new char[current_len + 2];
- memcpy(new_password, current_password, current_len);
- new_password[current_len] = charset[i];
- new_password[current_len+1] = '\0';
- pwlist.push_back(new_password);
- }
- }
- pwlist.pop_front();
- }
- }
- int main()
- {
- char* salt;
- char* target;
- char* password;
- char charset[] = {'a', 'b', 'c', 'd', 'e', 'f','g','h', '\0'};
- salt = new char[target_salt.length()+1];
- copy(target_salt.begin(), target_salt.end(), salt);
- target = new char[target_pw_hash.length()+1];
- copy(target_pw_hash.begin(), target_pw_hash.end(), target);
- password = exhaustive_search(charset, salt, target);
- if (strlen(password)!= 0) cout << "Password successfuly recovered: " << password << " \n";
- else cout << "Failure to find password, try distinct character set of size \n";
- }
Advertisement
Add Comment
Please, Sign In to add comment