#include "lib/md5.h" #include "lib/sha256.h" #include #include #include #include #include #include #include #include #include #include #include #include #include "sys/sysinfo.h" using namespace std; using namespace chrono; #define PBSTR "||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||" #define PBWIDTH 60 enum Error { ERR_UNKNOWN_OPTION, ERR_CANT_OPEN_FILE, ERR_ARGS, ERR_THREADS }; void error(Error n, string file) { switch (n) { case ERR_UNKNOWN_OPTION: cout << "Error, unknown option" << endl; break; case ERR_CANT_OPEN_FILE: cout << "Error, can't open file: "<< file << endl; break; case ERR_ARGS: cout<< "Usage:\ncrack -f [file] -d [dict] -t [threads] --trace [worst performance] --check [sys info]" << endl; break; case ERR_THREADS: cout<< "Error, wrong number of threads" << endl; break; } } enum Info{ CHECK_SYS }; void info(Info i){ struct sysinfo memInfo; sysinfo (&memInfo); long long totalPhysMemBytes = memInfo.totalram; long long totalPhysMemGBytes = (totalPhysMemBytes/(1024*1024*1024)); const auto processor_count = std::thread::hardware_concurrency(); switch (i) { case CHECK_SYS: cout << "Number of threads: " << processor_count << endl; cout << "Total RAM: " << totalPhysMemGBytes << "GB ("<(inFile), istreambuf_iterator(), '\n')+1; return c; } void readFile(string *&words,string &nombre, long long &size){ ifstream fichero; string fila; words = new string[size]; long long i = 0; fichero.open(nombre.c_str(), ios::in); if(fichero.is_open()){ while(!fichero.eof()){ getline(fichero, fila); words[i] = fila; i++; } fichero.close(); } } void readFileDict(char *&dict,string &nombre, long long &sizeWordsDICT){ cout<<"Loading dictionary in memory..."<(j)/static_cast(rangs[1])); } string word = ""; while(dict[j] != '\n' && j<=sizeWordsDICT){ word = word + dict[j]; j++; } word.erase(std::remove(word.begin(), word.end(), '\r' ), word.end()); string wordHashMD5 = hashMD5(word); for(int word2crack=0;word2crack dist(0, sizeof(alphanum)-1); for (int i = 0; i < len; ++i) { tmp_s += alphanum[(int)(dist(mt))]; } return tmp_s; } void outputFileCrack(string *result, long long &sizeMD5){ ofstream fichero("plain.txt"); if(fichero.is_open()){ for(long long i =0;i ThreadVector; long long **rangs; rangs = new long long*[numThreads]; int recovered = 0; //Read hashes to crack, read dict and caculate ranges readFile(wordsMD5,nameFileMD5,sizeMD5); readFileDict(dict,nameFileDict,sizeWordsDICT); fillSplit(rangs,sizeWordsDICT,numThreads); cout<<"Running process with "<(end-begin).count(); cout<<"Time to execution: "<