/* Crack a PWDUMP file */ boost::python::dict pwdump(std::string pwdumpFilePath, std::string pathToTables, std::string outputFile, std::string sSessionPathName, std::string sProgressPathName, std::string sPrecalcPathName, std::string output, bool debug, bool keepPrecalcFiles, int enableGPU, unsigned int maxThreads, uint64 maxMem) { std::vector<std::string> vHash; // hash cracker std::vector<std::string> vUserName; // lm cracker std::vector<std::string> vLMHash; // lm cracker std::vector<std::string> vNTLMHash; // lm cracker std::vector<std::string> vPathName; bool resumeSession = false; // Sessions not currently supported CHashSet hashSet; if ( !output.empty() ) { freopen(output.c_str(), "a", stdout); } if ( debug ) { version(debug); } /* Parse file for hashes */ LoadLMHashFromPwdumpFile(pwdumpFilePath, vUserName, vLMHash, vNTLMHash); for (uint32 index = 0; index < vLMHash.size(); index++) { hashSet.AddHash(vLMHash[index].substr(0, 16)); hashSet.AddHash(vLMHash[index].substr(16, 16)); } /* Load rainbow tables */ GetTableList(pathToTables, vPathName); if ( debug ) { std::cout << "[Debug]: Found " << vPathName.size() << " rainbow table file(s)..." << std::endl; } /* Start cracking! */ boost::python::dict results; CCrackEngine* crackEngine = new CCrackEngine(); crackEngine->setSession(sSessionPathName, sProgressPathName, sPrecalcPathName, keepPrecalcFiles); try { crackEngine->Run(vPathName, hashSet, maxThreads, maxMem, resumeSession, debug, enableGPU); results = otherResults(vLMHash, vNTLMHash, vUserName, hashSet, outputFile, debug); } catch (std::exception& error) { if (debug) { std::cout << "[Debug]: Caught a C++ exception, converting to Python exception ..." << std::endl; } delete crackEngine; // Release GIL PyErr_SetString(PyExc_ValueError, error.what()); throw boost::python::error_already_set(); } return results; }
/* Crack a Cain & Abel file */ boost::python::dict cain(std::string cainFilePath, std::string pathToTables, std::string outputFile, std::string sSessionPathName, std::string sProgressPathName, std::string sPrecalcPathName, bool debug, bool keepPrecalcFiles, int enableGPU, unsigned int maxThreads, uint64 maxMem) { std::vector<std::string> vHash; // hash cracker std::vector<std::string> vUserName; // lm cracker std::vector<std::string> vLMHash; // lm cracker std::vector<std::string> vNTLMHash; // lm cracker std::vector<std::string> vPathName; bool resumeSession = false; // Sessions not currently supported CHashSet hashSet; if ( debug ) { version(debug); } /* Parse file for hashes */ LoadLMHashFromCainLSTFile(cainFilePath, vUserName, vLMHash, vNTLMHash); for (uint32 index = 0; index < vLMHash.size(); index++) { hashSet.AddHash(vLMHash[index].substr(0, 16)); hashSet.AddHash(vLMHash[index].substr(16, 16)); } /* Load rainbow tables */ GetTableList(pathToTables, vPathName); if ( debug ) { std::cout << "[Debug]: Found " << vPathName.size() << " rainbow table file(s)..." << std::endl; } /* Start cracking! */ CCrackEngine crackEngine; crackEngine.setSession(sSessionPathName, sProgressPathName, sPrecalcPathName, keepPrecalcFiles); crackEngine.Run(vPathName, hashSet, maxThreads, maxMem, resumeSession, debug, enableGPU); boost::python::dict results = otherResults(vLMHash, vNTLMHash, vUserName, hashSet, outputFile, debug); return results; }
/* Cracks a single hash and returns a Python dictionary */ boost::python::dict crack(boost::python::list& hashes, std::string pathToTables, std::string outputFile, std::string sSessionPathName, std::string sProgressPathName, std::string sPrecalcPathName, std::string output, bool mysqlsha1format, bool debug, bool keepPrecalcFiles, int enableGPU, unsigned int maxThreads, uint64 maxMem) { #ifndef _WIN32 signal(SIGSEGV, handler); // Register segfault handler #endif CHashSet hashSet; bool resumeSession = false; // Sessions not currently supported std::vector<std::string> verifiedHashes; std::vector<std::string> vPathName; if ( !output.empty() ) { freopen(output.c_str(), "a", stdout); } if ( debug ) { std::cout << "[Debug]: List contains " << boost::python::len(hashes) << " hash(es)" << std::endl; } for (unsigned int index = 0; index < boost::python::len(hashes); ++index) { std::string sHash = boost::python::extract<std::string>(hashes[index]); if (NormalizeHash(sHash)) { verifiedHashes.push_back(sHash); } else { std::ostringstream stringBuilder; stringBuilder << "Invalid hash: <" << sHash.c_str() << ">"; std::string message = stringBuilder.str(); PyErr_SetString(PyExc_ValueError, message.c_str()); throw boost::python::error_already_set(); } } std::vector<std::string> sha1AsMysqlSha1; for (unsigned int index = 0; index < verifiedHashes.size(); ++index) { if (mysqlsha1format) { HASHROUTINE hashRoutine; CHashRoutine hr; std::string hashName = "sha1"; int hashLen = 20; hr.GetHashRoutine( hashName, hashRoutine, hashLen ); unsigned char* plain = new unsigned char[hashLen*2]; memcpy( plain, HexToBinary(verifiedHashes[index].c_str(), hashLen*2 ).c_str(), hashLen ); unsigned char hash_output[MAX_HASH_LEN]; hashRoutine( plain, hashLen, hash_output); sha1AsMysqlSha1.push_back(HexToStr(hash_output, hashLen)); hashSet.AddHash( sha1AsMysqlSha1[index] ); } else { hashSet.AddHash(verifiedHashes[index]); } } /* Load rainbow tables */ GetTableList(pathToTables, vPathName); if (debug) { std::cout << "[Debug]: Found " << vPathName.size() << " rainbow table file(s)" << std::endl; } /* Start cracking! */ CCrackEngine crackEngine; crackEngine.setSession(sSessionPathName, sProgressPathName, sPrecalcPathName, keepPrecalcFiles); crackEngine.Run(vPathName, hashSet, maxThreads, maxMem, resumeSession, debug, enableGPU); boost::python::dict results; results = fCrackerResults(verifiedHashes, sha1AsMysqlSha1, hashSet); return results; }