Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <list>
- #include <cstring>
- #include <crypt.h>
- #define MAX_LEN 5
- using namespace std;
- char null[] = {'\0'};
- string SALT = "$6$XPmWkpus$";
- string ENCRYPTED_PASS = "$6$XPmWkpus$jZiSDOKdMMRZQhaCLULUO9baoau4D3Vot7tKNFqJQkStExZp9afA9rHnZ6iih8khjfkZLUbgKWIvIKQUKr7dL1";
- list<char*> pwlist;
- list<char*> correct_pwlist;
- char* available_chars = "abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()";
- char* prefix = ">>>:::sec20f:::<<<";
- char* suffix = "@x(h";
- int LEN_PREFIX = 18;
- int LEN_SUFFIX = 4;
- // check if the pw and salt are matching the hash
- int check_password(char* pw, char* salt, char* hash)
- {
- char* new_pw = new char[MAX_LEN + LEN_SUFFIX + LEN_PREFIX + 1];
- memcpy(new_pw, prefix, LEN_PREFIX);
- strcat(new_pw, pw);
- strcat(new_pw, suffix);
- printf("%s\n", new_pw);
- char* res = crypt(new_pw, salt);
- for (unsigned i = 0; i<strlen(hash); i++)
- if (res[i]!=hash[i])
- return 0;
- cout << "match !!!" << "\n";
- return 1;
- }
- // builds passwords from the given character set
- // and verifies if they match the target
- char* exhaustive_search(char* salt, char* target)
- {
- char* current_password;
- char* new_password;
- char* pw;
- int current_len;
- // set first 3 chars of pw
- pw = new char[6];
- pwlist.push_back(pw);
- correct_pwlist.push_back(pw);
- while(true){
- // test if queue is not empty and return null if so
- if (correct_pwlist.empty())
- return null;
- // get the current current_password from queue
- current_password = correct_pwlist.front();
- current_len = strlen(current_password);
- // check if current password is the target password, if yes return the current_password
- if(current_len == MAX_LEN && check_password(current_password, salt, target))
- return current_password;
- // else generates new passwords from the current one by appending each possible ASCII char
- current_len = strlen(pwlist.front());
- while(current_len < MAX_LEN){
- current_password = pwlist.front();
- current_len = strlen(current_password);
- for (int ch = 0; ch < strlen(available_chars); ch++){
- new_password = new char[current_len + 2];
- memcpy(new_password, current_password, current_len);
- new_password[current_len] = char(available_chars[ch]);
- new_password[current_len+1] = '\0';
- pwlist.push_back(new_password);
- if (strlen(new_password) == MAX_LEN){
- correct_pwlist.push_back(new_password);
- }
- }
- pwlist.pop_front();
- if(current_len == MAX_LEN - 1){
- break;
- }
- }
- // now remove the front element as it didn't match the password
- correct_pwlist.pop_front();
- }
- }
- int main()
- {
- char* salt;
- char* target;
- char* password;
- //convert the salt from string to char*
- salt = new char[SALT.length()+1];
- copy(SALT.begin(), SALT.end(), salt);
- //convert the hash from string to char*
- target = new char[ENCRYPTED_PASS.length()+1];
- copy(ENCRYPTED_PASS.begin(), ENCRYPTED_PASS.end(), target);
- //start the search
- password = exhaustive_search(salt, target);
- if (strlen(password)!= 0)
- cout << "Password successfuly cracked: " << password << " \n";
- else
- cout << "Failure to find password \n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement