checkbrute/src/main.cpp

119 lines
5.6 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 <QThread>
// checkbrute includes
#include "mainthread.h"
#include "checksum_qt.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
a.setApplicationName("checkbrute");
a.setApplicationVersion("0.1");
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.");
commandLineParser.addOptions(QList<QCommandLineOption>() << algorithmsOption << startOption << stopOption << lengthsOption << threadsOption << strictOption);
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);
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["SHA1"] = new checksum_qt(QCryptographicHash::Sha1, "SHA1");
checksum_map["SHA2-256"] = new checksum_qt(QCryptographicHash::Sha256, "SHA2-256");
checksum_map["SHA2-512"] = new checksum_qt(QCryptographicHash::Sha512, "SHA2-512");
checksum_map["SHA3-256"] = new checksum_qt(QCryptographicHash::Sha3_256, "SHA3-256");
checksum_map["SHA3-512"] = new checksum_qt(QCryptographicHash::Sha3_512, "SHA3-512");
#if QT_VERSION >= 0x050902
checksum_map["Keccak-256"] = new checksum_qt(QCryptographicHash::Keccak_256, "Keccak-256");
checksum_map["Keccak-512"] = new checksum_qt(QCryptographicHash::Keccak_512, "Keccak-512");
#endif
// 224 and 384 bit hashes are partial
if (strictHash) {
checksum_map["SHA2-224"] = new checksum_qt(QCryptographicHash::Sha224, "SHA2-224");
checksum_map["SHA2-384"] = new checksum_qt(QCryptographicHash::Sha384, "SHA2-384");
checksum_map["SHA3-224"] = new checksum_qt(QCryptographicHash::Sha3_224, "SHA3-224");
checksum_map["SHA3-384"] = new checksum_qt(QCryptographicHash::Sha3_384, "SHA3-384");
#if QT_VERSION >= 0x050902
checksum_map["Keccak-224"] = new checksum_qt(QCryptographicHash::Keccak_224, "Keccak-224");
checksum_map["Keccak-384"] = new checksum_qt(QCryptographicHash::Keccak_384, "Keccak-384");
#endif
}
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();
}