jack.cpp (2557B)
1 #include <iostream> 2 #include <time.h> 3 #include <cstdio> 4 5 /* blackjack21 */ 6 7 #include <string> 8 #include <cstring> 9 #include <fstream> 10 11 #include "lib/md5.h" 12 #include "lib/sha1.h" 13 #include "lib/sha256.h" 14 #include "lib/sha512.h" 15 16 using namespace std; 17 18 bool verbose; 19 20 void crack(string hash, string file, int alg); 21 22 void 23 interface(int f, char *exename) 24 { 25 printf( "BlackJack21 - small password cracking program v2.1\n" 26 "MCD, 2017\n\n"); 27 if (f == 1) 28 printf( "Supported: md5, sha1, sha256, sha512\n\n" 29 "Usage: %s [HASH-TYPE] [HASH] [DICTIONARY] [-v]\n", 30 exename); 31 } 32 33 int 34 main(int argc, char* argv[]) 35 { 36 if(argc < 4) { interface(1, argv[0]); 37 exit(0); 38 } else if(argc == 4 || argc == 5) { 39 string type = argv[1]; 40 string hash = argv[2]; 41 string dict = argv[3]; 42 std::ifstream file(dict); 43 if(file.is_open()) { 44 45 if (argc == 5) 46 verbose = true; 47 else 48 verbose = false; 49 50 interface(0, argv[0]); 51 cout <<"Hashing algorithm: " << type << "\nCracking...\n\n"; 52 if (type == "MD5" || type == "md5") crack(hash, dict, 0); 53 else if(type == "SHA1" || type == "sha1") crack(hash, dict, 1); 54 else if(type == "SHA256" || type == "sha256") crack(hash, dict, 2); 55 else if(type == "SHA512" || type == "sha512") crack(hash, dict, 3); 56 } else { 57 interface(1, argv[0]); 58 printf("File could not be found.\n"); 59 exit(1); 60 } 61 } else { 62 interface(1, argv[0]); 63 } 64 65 exit(1); 66 } 67 68 int 69 iterate(string filename) 70 { 71 int tries = 0; 72 std::ifstream file(filename); 73 string pass; 74 while(file >> pass) { 75 tries++; 76 } 77 78 return tries; 79 } 80 81 void 82 crack(string hash, string filename, int alg) 83 { 84 int lines = iterate(filename); 85 int tries = 0; 86 std::ifstream file(filename); 87 string pass; 88 89 /* hide cursor */ 90 printf("\e[?25l"); 91 92 clock_t t; 93 t = clock(); 94 95 while(file >> pass) { 96 97 tries++; 98 99 string hash_sum = ""; 100 if (alg == 0) hash_sum = md5(pass); 101 else if (alg == 1) hash_sum = sha1(pass); 102 else if (alg == 2) hash_sum = sha256(pass); 103 else if (alg == 3) hash_sum = sha512(pass); 104 105 if (hash_sum == hash) { 106 cout << "\n\n[" << tries << "] - PASSWORD FOUND - " << pass << "\n\n"; 107 108 t = clock() - t; 109 double time_taken = ((double)t) / CLOCKS_PER_SEC; 110 printf("Elapsed time: %fs\n", time_taken); 111 112 printf("\e[?25h"); 113 exit(0); 114 } else { 115 if (verbose == true) 116 cout << "[" << tries << "] - Failed attempt - " << pass << endl; 117 else 118 printf("\rTried %d of %d lines", tries, lines ); 119 } 120 } 121 t = clock() - t; 122 double time_taken = ((double)t) / CLOCKS_PER_SEC; 123 printf("Elapsed time: %.2fs\n", time_taken); 124 printf("\e[?25h"); 125 }