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$SvT3dVpN$";
- string target_pw_hash = "$6$SvT3dVpN$JhGxjcfNohXabpUDTbVMSKjJjLAOWg40Tu6fd8r2G1fmVRuKtXG.v506DJColxY.2RnG5whjAR/0BsjZTxrOa1";
- char null[] = { '\0' };
- #define MAX_LEN 19
- list<char*> pwlist;
- int check_password(char* pw, char* salt, char* hash)
- {
- char* res = crypt(pw, salt);
- cout << "password " << pw << "\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;
- char* pass_cst;
- int i, current_len, len_cst;
- pass_cst=new char[14];
- memcpy(pass_cst,">>>sec22_is<<<",14);
- len_cst = strlen(pass_cst);
- for (i = 0; i < strlen(charset); i++) {
- new_password = new char[len_cst + 2];
- memcpy(new_password, pass_cst,len_cst);
- new_password[len_cst] = charset[i];
- new_password[len_cst+1] = '\0';
- pwlist.push_back(new_password);
- }
- while (true) {
- if (pwlist.empty())
- return null;
- current_password = pwlist.front();
- current_len = strlen(current_password);
- // if(current_len == MAX_LEN){
- 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','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' };
- 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