Пример #1
0
bool CChainWalkContext::SetHashRoutine( std::string sHashRoutineName )
{
	CHashRoutine hr;
	hr.GetHashRoutine(sHashRoutineName, m_pHashRoutine, m_nHashLen);
	if (m_pHashRoutine != NULL)
	{
		m_sHashRoutineName = sHashRoutineName;
		return true;
	}
	else
		return false;
}
Пример #2
0
/* 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;
}