159 lines
8.3 KiB
C++
159 lines
8.3 KiB
C++
/*****************************************************************************
|
|
* checkbrute Checksum Bruteforcing Tool
|
|
* Copyright (C) 2020 Syping
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
* are permitted provided that the following conditions are met:
|
|
*
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
* this list of conditions and the following disclaimer.
|
|
*
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
* and/or other materials provided with the distribution.
|
|
*
|
|
* This software is provided as-is, no warranties are given to you, we are not
|
|
* responsible for anything with use of the software, you are self responsible.
|
|
*****************************************************************************/
|
|
|
|
// Qt includes
|
|
#include <QCommandLineOption>
|
|
#include <QCommandLineParser>
|
|
#include <QCoreApplication>
|
|
#include <QTextStream>
|
|
#include <QFileInfo>
|
|
#include <QLibrary>
|
|
#include <QThread>
|
|
#include <QDir>
|
|
|
|
// checkbrute includes
|
|
#include "mainthread.h"
|
|
#include "checkbrute.h"
|
|
#include "checksum_qt.h"
|
|
#include "checksum_lib.h"
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
QCoreApplication a(argc, argv);
|
|
a.setApplicationName("checkbrute");
|
|
a.setApplicationVersion("0.3.3");
|
|
|
|
QCommandLineParser commandLineParser;
|
|
commandLineParser.addHelpOption();
|
|
commandLineParser.addVersionOption();
|
|
commandLineParser.addPositionalArgument("source", "Source file to bruteforce.");
|
|
commandLineParser.addPositionalArgument("checksums", "File containing checksums.");
|
|
QCommandLineOption algorithmsOption = QCommandLineOption("algorithms", "Algorithms to use for bruteforcing.", "algorithms");
|
|
QCommandLineOption startOption = QCommandLineOption("start", "Byte to start bruteforcing from.", "start");
|
|
QCommandLineOption stopOption = QCommandLineOption("stop", "Byte when to stop bruteforcing.", "stop");
|
|
QCommandLineOption lengthsOption = QCommandLineOption("lengths", "Lengths to use for bruteforcing.", "lengths");
|
|
QCommandLineOption threadsOption = QCommandLineOption("threads", "Threads to use for bruteforcing.", "threads");
|
|
QCommandLineOption strictOption = QCommandLineOption(QStringList() << "s" << "strict", "Match checksums strict.");
|
|
QCommandLineOption testOption = QCommandLineOption(QStringList() << "t" << "test", "Test checkbrute plugin hashes.");
|
|
commandLineParser.addOptions(QList<QCommandLineOption>() << algorithmsOption << startOption << stopOption << lengthsOption << threadsOption << strictOption << testOption);
|
|
commandLineParser.process(a);
|
|
|
|
QTextStream(stderr) << "INFO: Launch " << a.applicationName() << " " << a.applicationVersion() << "..." << Qt::endl;
|
|
|
|
const QStringList args = commandLineParser.positionalArguments();
|
|
if (args.count() != 2) {
|
|
QTextStream(stderr) << "ERROR: Missing required arguments!" << Qt::endl;
|
|
return 1;
|
|
}
|
|
const QString bruteforceFile = args.at(0);
|
|
const QString checksumsFile = args.at(1);
|
|
const bool strictHash = commandLineParser.isSet(strictOption);
|
|
const bool testEnabled = commandLineParser.isSet(testOption);
|
|
|
|
if (strictHash) {
|
|
QTextStream(stderr) << "INFO: Strict matching enabled" << Qt::endl;
|
|
}
|
|
else {
|
|
QTextStream(stderr) << "INFO: Strict matching disabled" << Qt::endl;
|
|
}
|
|
|
|
if (!QFileInfo(bruteforceFile).isFile()) {
|
|
QTextStream(stderr) << "ERROR: Source file " << bruteforceFile << " doesn't exists!" << Qt::endl;
|
|
return 1;
|
|
}
|
|
|
|
if (!QFileInfo(checksumsFile).isFile()) {
|
|
QTextStream(stderr) << "ERROR: Checksums file " << checksumsFile << " doesn't exists!" << Qt::endl;
|
|
return 1;
|
|
}
|
|
|
|
const QString start = commandLineParser.value(startOption);
|
|
const QString stop = commandLineParser.value(stopOption);
|
|
const QString algorithms = commandLineParser.value(algorithmsOption);
|
|
const QString lengths = commandLineParser.value(lengthsOption);
|
|
const QString threads = commandLineParser.value(threadsOption);
|
|
|
|
std::map<std::string,checksum*> checksum_map;
|
|
checksum_map["MD4"] = new checksum_qt(QCryptographicHash::Md4, "MD4");
|
|
checksum_map["MD5"] = new checksum_qt(QCryptographicHash::Md5, "MD5");
|
|
checksum_map["SHA-1"] = new checksum_qt(QCryptographicHash::Sha1, "SHA-1");
|
|
checksum_map["SHA-224"] = new checksum_qt(QCryptographicHash::Sha224, "SHA-224");
|
|
checksum_map["SHA-256"] = new checksum_qt(QCryptographicHash::Sha256, "SHA-256");
|
|
checksum_map["SHA-384"] = new checksum_qt(QCryptographicHash::Sha384, "SHA-384");
|
|
checksum_map["SHA-512"] = new checksum_qt(QCryptographicHash::Sha512, "SHA-512");
|
|
checksum_map["SHA3-224"] = new checksum_qt(QCryptographicHash::Sha3_224, "SHA3-224");
|
|
checksum_map["SHA3-256"] = new checksum_qt(QCryptographicHash::Sha3_256, "SHA3-256");
|
|
checksum_map["SHA3-384"] = new checksum_qt(QCryptographicHash::Sha3_384, "SHA3-384");
|
|
checksum_map["SHA3-512"] = new checksum_qt(QCryptographicHash::Sha3_512, "SHA3-512");
|
|
#if QT_VERSION >= 0x050902
|
|
checksum_map["Keccak-224"] = new checksum_qt(QCryptographicHash::Keccak_224, "Keccak-224");
|
|
checksum_map["Keccak-256"] = new checksum_qt(QCryptographicHash::Keccak_256, "Keccak-256");
|
|
checksum_map["Keccak-384"] = new checksum_qt(QCryptographicHash::Keccak_384, "Keccak-384");
|
|
checksum_map["Keccak-512"] = new checksum_qt(QCryptographicHash::Keccak_512, "Keccak-512");
|
|
#endif
|
|
|
|
for (const QString &fileName : QDir(CHECKBRUTE_PLUGINS).entryList(QDir::Files, QDir::Name)) {
|
|
const QString filePath = QString("%1/%2").arg(CHECKBRUTE_PLUGINS, fileName);
|
|
if (QLibrary::isLibrary(filePath)) {
|
|
QTextStream(stderr) << "INFO: Load plugin " << fileName << "..." << Qt::endl;
|
|
QLibrary plugin(filePath);
|
|
if (plugin.load()) {
|
|
PluginHash32Function hash32Func = (PluginHash32Function)plugin.resolve("checkbrute_hash32");
|
|
PluginHash64Function hash64Func = (PluginHash64Function)plugin.resolve("checkbrute_hash64");
|
|
PluginHashSzFunction hashSzFunc = (PluginHashSzFunction)plugin.resolve("checkbrute_hashsz");
|
|
PluginFormatFunction formatFunc = (PluginFormatFunction)plugin.resolve("checkbrute_format");
|
|
PluginVersionFunction versionFunc = (PluginVersionFunction)plugin.resolve("checkbrute_version");
|
|
if (formatFunc && hash32Func && hashSzFunc) {
|
|
QString version = "undefined";
|
|
const char *format = formatFunc();
|
|
if (versionFunc)
|
|
version = QString::fromUtf8(versionFunc());
|
|
checksum_map[format] = new checksum_lib(formatFunc, hash32Func, hashSzFunc);
|
|
QTextStream(stderr) << "INFO: " << format << " plugin " << fileName << " loaded" << Qt::endl;
|
|
if (testEnabled)
|
|
QTextStream(stderr) << "TEST: " << format << " checkbrute -> " << QString::number(hash32Func((unsigned char*)"checkbrute", 7), 16) << Qt::endl;
|
|
}
|
|
else if (formatFunc && hash64Func && hashSzFunc) {
|
|
QString version = "undefined";
|
|
const char *format = formatFunc();
|
|
if (versionFunc)
|
|
version = QString::fromUtf8(versionFunc());
|
|
checksum_map[format] = new checksum_lib(formatFunc, hash64Func, hashSzFunc);
|
|
QTextStream(stderr) << "INFO: " << format << " plugin " << fileName << " loaded" << Qt::endl;
|
|
if (testEnabled)
|
|
QTextStream(stderr) << "TEST: " << format << " checkbrute -> " << QString::number(hash64Func((unsigned char*)"checkbrute", 7), 16) << Qt::endl;
|
|
}
|
|
else {
|
|
QTextStream(stderr) << "WARNING: Failed loading plugin " << fileName << "!" << Qt::endl;
|
|
}
|
|
}
|
|
else {
|
|
QTextStream(stderr) << "WARNING: Failed loading plugin " << fileName << "!" << Qt::endl;
|
|
}
|
|
}
|
|
}
|
|
|
|
mainthread instance(bruteforceFile, checksumsFile, algorithms, start, stop, lengths, threads, strictHash, checksum_map);
|
|
QObject::connect(&instance, &mainthread::finished, &a, &QCoreApplication::quit);
|
|
if (!instance.isInitialised())
|
|
return 1;
|
|
|
|
instance.run();
|
|
|
|
return a.exec();
|
|
}
|