int main(int argc, char* argv[]) { #ifdef _WIN32 if (argc != 4) { Usage(); return 0; } string sWildCharPathName = argv[1]; string sInputType = argv[2]; string sInput = argv[3]; // vPathName vector<string> vPathName; GetTableList(sWildCharPathName, vPathName); #else if (argc < 4) { Usage(); return 0; } string sInputType = argv[argc - 2]; string sInput = argv[argc - 1]; // vPathName vector<string> vPathName; GetTableList(argc, argv, vPathName); #endif if (vPathName.size() == 0) { printf("no rainbow table found\n"); return 0; } // fCrackerType, vHash, vUserName, vLMHash bool fCrackerType; // true: hash cracker, false: lm cracker vector<string> vHash; // hash cracker vector<string> vUserName; // lm cracker vector<string> vLMHash; // lm cracker vector<string> vNTLMHash; // lm cracker if (sInputType == "-h") { fCrackerType = true; string sHash = sInput; if (NormalizeHash(sHash)) vHash.push_back(sHash); else printf("invalid hash: %s\n", sHash.c_str()); } else if (sInputType == "-l") { fCrackerType = true; string sPathName = sInput; vector<string> vLine; if (ReadLinesFromFile(sPathName, vLine)) { int i; for (i = 0; i < vLine.size(); i++) { string sHash = vLine[i]; if (NormalizeHash(sHash)) vHash.push_back(sHash); else printf("invalid hash: %s\n", sHash.c_str()); } } else printf("can't open %s\n", sPathName.c_str()); } else if (sInputType == "-f") { fCrackerType = false; string sPathName = sInput; LoadLMHashFromPwdumpFile(sPathName, vUserName, vLMHash, vNTLMHash); } else { Usage(); return 0; } if (fCrackerType && vHash.size() == 0) return 0; if (!fCrackerType && vLMHash.size() == 0) return 0; // hs CHashSet hs; if (fCrackerType) { int i; for (i = 0; i < vHash.size(); i++) hs.AddHash(vHash[i]); } else { int i; for (i = 0; i < vLMHash.size(); i++) { hs.AddHash(vLMHash[i].substr(0, 16)); hs.AddHash(vLMHash[i].substr(16, 16)); } } // Run CCrackEngine ce; ce.Run(vPathName, hs); // Statistics //printf("statistics\n"); //printf("-------------------------------------------------------\n"); //printf("plaintext found: %d of %d (%.2f%%)\n", hs.GetStatHashFound(), // hs.GetStatHashTotal(), // 100.0f * hs.GetStatHashFound() / hs.GetStatHashTotal()); //printf("total disk access time: %.2f s\n", ce.GetStatTotalDiskAccessTime()); //printf("total cryptanalysis time: %.2f s\n", ce.GetStatTotalCryptanalysisTime()); //printf("total chain walk step: %d\n", ce.GetStatTotalChainWalkStep()); //printf("total false alarm: %d\n", ce.GetStatTotalFalseAlarm()); //printf("total chain walk step due to false alarm: %d\n", ce.GetStatTotalChainWalkStepDueToFalseAlarm()); //printf("\n"); // Result //printf("result\n"); //printf("-------------------------------------------------------\n"); if (fCrackerType) { int i; for (i = 0; i < vHash.size(); i++) { string sPlain, sBinary; if (!hs.GetPlain(vHash[i], sPlain, sBinary)) { sPlain = "<notfound>"; sBinary = "<notfound>"; } //printf("%s %s hex:%s\n", vHash[i].c_str(), sPlain.c_str(), sBinary.c_str()); } } else { int i; for (i = 0; i < vLMHash.size(); i++) { string sPlain1, sBinary1; bool fPart1Found = hs.GetPlain(vLMHash[i].substr(0, 16), sPlain1, sBinary1); if (!fPart1Found) { sPlain1 = "<notfound>"; sBinary1 = "<notfound>"; } string sPlain2, sBinary2; bool fPart2Found = hs.GetPlain(vLMHash[i].substr(16, 16), sPlain2, sBinary2); if (!fPart2Found) { sPlain2 = "<notfound>"; sBinary2 = "<notfound>"; } string sPlain = sPlain1 + sPlain2; string sBinary = sBinary1 + sBinary2; // Correct case if (fPart1Found && fPart2Found) { unsigned char NTLMHash[16]; int nHashLen; ParseHash(vNTLMHash[i], NTLMHash, nHashLen); if (nHashLen != 16) printf("debug: nHashLen mismatch\n"); string sNTLMPassword; if (LMPasswordCorrectCase(sPlain, NTLMHash, sNTLMPassword)) { sPlain = sNTLMPassword; sBinary = HexToStr((const unsigned char*)sNTLMPassword.c_str(), sNTLMPassword.size()); } else printf("case correction for password %s fail!\n", sPlain.c_str()); } // Display //printf("%-14s %s hex:%s\n", vUserName[i].c_str(), // sPlain.c_str(), // sBinary.c_str()); } } return 0; }
boost::python::dict otherResults(std::vector<std::string>& vLMHash, std::vector<std::string>& vNTLMHash, std::vector<std::string>& vUserName, CHashSet& hashSet, std::string& outputFile, bool debug) { boost::python::dict results; bool writeOutput = (outputFile == "" ? true:false); for (uint32 index = 0; index < vLMHash.size(); index++) { std::string sPlain1, sBinary1; bool fPart1Found = hashSet.GetPlain(vLMHash[index].substr(0, 16), sPlain1, sBinary1); if (!fPart1Found) { sPlain1 = "<Not Found>"; sBinary1 = "<Not Found>"; } std::string sPlain2, sBinary2; bool fPart2Found = hashSet.GetPlain(vLMHash[index].substr(16, 16), sPlain2, sBinary2); if (!fPart2Found) { sPlain2 = "<Not Found>"; sBinary2 = "<Not Found>"; } std::string sPlain = sPlain1 + sPlain2; std::string sBinary = sBinary1 + sBinary2; // Correct case if (fPart1Found && fPart2Found) { unsigned char NTLMHash[16]; int nHashLen; ParseHash(vNTLMHash[index], NTLMHash, nHashLen); if (nHashLen != 16) std::cout << "[Debug]: nHashLen mismatch" << std::endl; std::string sNTLMPassword; if (LMPasswordCorrectCase(sPlain, NTLMHash, sNTLMPassword)) { sPlain = sNTLMPassword; sBinary = HexToStr( (const unsigned char*) sNTLMPassword.c_str(), sNTLMPassword.size()); if (writeOutput) { if (!writeResultLineToFile(outputFile, vNTLMHash[index].c_str(), sPlain.c_str(), sBinary.c_str())) { std::string message = "Couldn't write final result to file!"; PyErr_SetString(PyExc_IOError, message.c_str()); throw boost::python::error_already_set(); } } } else { if ( debug ) { std::cout << "[Debug]: " << vUserName[index].c_str() << "\t" << sPlain.c_str() << "\thex:" << sBinary.c_str() << std::endl << "[Debug]: Failed case correction, trying unicode correction for: " << sPlain.c_str() << std::endl; } LM2NTLMcorrector corrector; if (corrector.LMPasswordCorrectUnicode(sBinary, NTLMHash, sNTLMPassword)) { sPlain = sNTLMPassword; sBinary = corrector.getBinary(); if (writeOutput) { if (!writeResultLineToFile(outputFile, vNTLMHash[index].c_str(), sPlain.c_str(), sBinary.c_str())) { std::string message = "Couldn't write final result to file!"; PyErr_SetString(PyExc_IOError, message.c_str()); throw boost::python::error_already_set(); } } } else if ( debug ) { std::cout << "[Debug]: unicode correction for password " << sPlain.c_str() << " failed!" << std::endl; } } } results[vUserName[index].c_str()] = sPlain.c_str(); } return results; }