Advertisement
Guest User

SSS

a guest
Mar 20th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 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$Iy/hHRfM$";
  7. string target_pw_hash = "$6$Iy/hHRfM$gC.Fw7CbqG.Qc9p9X59Tmo5uEHCf0ZAKCsPZuiYUKcejrsGuZtES1VQiusSTen0NRUPYN0v1z76PwX2G2.v1l1";
  8. char null[] = { '\0' };
  9. #define MAX_LEN 6
  10. list<char*> pwlist;
  11. int check_password(char* pw, char* salt, char* hash)
  12. {
  13. char* res = crypt(pw, salt);
  14. cout << "password " << pw << "\n";
  15. cout << "hashes to " << res << "\n";
  16. for (int i = 0; i < strlen(hash); i++)
  17. if (res[i] != hash[i])
  18. return 0;
  19. cout << "match !!!"
  20. << "\n";
  21. return 1;
  22. }
  23. char* exhaustive_search(char* charset, char* salt, char* target)
  24. {
  25. char* current_password;
  26. char* new_password;
  27. int i, current_len;
  28. for (i = 0; i < strlen(charset); i++) {
  29. new_password = new char[2];
  30. new_password[0] = charset[i];
  31. new_password[1] = '\0';
  32. pwlist.push_back(new_password);
  33. }
  34. while (true) {
  35. if (pwlist.empty())
  36. return null;
  37. current_password = pwlist.front();
  38. current_len = strlen(current_password);
  39. if (check_password(current_password, salt, target))
  40. return current_password;
  41. if (current_len < MAX_LEN) {
  42. for (i = 0; i < strlen(charset); i++) {
  43. new_password = new char[current_len + 2];
  44. memcpy(new_password, current_password, current_len);
  45. new_password[current_len] = charset[i];
  46. new_password[current_len + 1] = '\0';
  47. pwlist.push_back(new_password);
  48. }
  49. }
  50. pwlist.pop_front();
  51. }
  52. }
  53. main()
  54. {
  55. char* salt;
  56. char* target;
  57. char* password;
  58. char charset[] = { 'b', 'o', 'g', 'd', 'a', 'n', '\0' };
  59. salt = new char[target_salt.length() + 1];
  60. copy(target_salt.begin(), target_salt.end(), salt);
  61. target = new char[target_pw_hash.length() + 1];
  62. copy(target_pw_hash.begin(), target_pw_hash.end(), target);
  63. password = exhaustive_search(charset, salt, target);
  64. if (strlen(password) != 0)
  65. cout << "Password successfuly recovered: " << password << " \n";
  66. else
  67. cout << "Failure to find password, try distinct character set of size \n";
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement