From aa3efb449f4979398c60e64ed072c7a5b8feb90d Mon Sep 17 00:00:00 2001
From: Syping <schiedelrafael@keppe.org>
Date: Sun, 25 Oct 2020 00:24:45 +0200
Subject: [PATCH 1/9] strict mode bruteforcing
---
src/brutethread.cpp | 8 ++++--
src/brutethread.h | 3 +-
src/main.cpp | 20 +++++--------
src/mainthread.cpp | 69 ++++++++++++++++++++++++++++-----------------
4 files changed, 58 insertions(+), 42 deletions(-)
diff --git a/src/brutethread.cpp b/src/brutethread.cpp
index 56b5fb0..a821d2e 100644
--- a/src/brutethread.cpp
+++ b/src/brutethread.cpp
@@ -19,7 +19,7 @@
#include <QTextStream>
#include "brutethread.h"
-brutethread::brutethread(const QByteArray &fileContent, quint64 length, QVector<checksum*> checksum_vector, QVector<QByteArray> checksums) : checksum_vector(checksum_vector), checksums(checksums), fileContent(fileContent), length(length) {}
+brutethread::brutethread(const QByteArray &fileContent, quint64 length, QVector<checksum*> checksum_vector, QVector<QByteArray> checksums, bool strictMatch) : checksum_vector(checksum_vector), checksums(checksums), fileContent(fileContent), strictMatch(strictMatch), length(length) {}
void brutethread::run()
{
@@ -29,7 +29,11 @@ void brutethread::run()
const QByteArray content = fileContent.mid(seek, length);
const QByteArray generatedHash = generator->generateChecksum(content).toHex();
for (const QByteArray &hash : checksums) {
- if (generatedHash.left(hash.length()) == hash) {
+ if (!strictMatch && generatedHash.left(hash.length()) == hash) {
+ QTextStream(stdout) << "MATCH: " << generator->formatName() << " Checksum " << hash << " Start " << seek << " End " << seek+length << Qt::endl;
+ emit matched();
+ }
+ else if (strictMatch && generatedHash.length() == hash.length() && generatedHash == hash) {
QTextStream(stdout) << "MATCH: " << generator->formatName() << " Checksum " << hash << " Start " << seek << " End " << seek+length << Qt::endl;
emit matched();
}
diff --git a/src/brutethread.h b/src/brutethread.h
index e6d3574..d011af9 100644
--- a/src/brutethread.h
+++ b/src/brutethread.h
@@ -33,13 +33,14 @@ class brutethread : public QThread
{
Q_OBJECT
public:
- explicit brutethread(const QByteArray &fileContent, quint64 length, QVector<checksum*> checksum_vector, QVector<QByteArray> checksums);
+ explicit brutethread(const QByteArray &fileContent, quint64 length, QVector<checksum*> checksum_vector, QVector<QByteArray> checksums, bool strictMatch);
void run();
private:
QVector<checksum*> checksum_vector;
QVector<QByteArray> checksums;
QByteArray fileContent;
+ bool strictMatch;
quint64 length;
signals:
diff --git a/src/main.cpp b/src/main.cpp
index c633619..a85a050 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -32,7 +32,7 @@ int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
a.setApplicationName("checkbrute");
- a.setApplicationVersion("0.1");
+ a.setApplicationVersion("0.1.1");
QCommandLineParser commandLineParser;
commandLineParser.addHelpOption();
@@ -86,27 +86,21 @@ int main(int argc, char *argv[])
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-224"] = new checksum_qt(QCryptographicHash::Sha224, "SHA2-224");
checksum_map["SHA2-256"] = new checksum_qt(QCryptographicHash::Sha256, "SHA2-256");
+ checksum_map["SHA2-384"] = new checksum_qt(QCryptographicHash::Sha384, "SHA2-384");
checksum_map["SHA2-512"] = new checksum_qt(QCryptographicHash::Sha512, "SHA2-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
- // 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())
diff --git a/src/mainthread.cpp b/src/mainthread.cpp
index eb51326..5209d38 100644
--- a/src/mainthread.cpp
+++ b/src/mainthread.cpp
@@ -26,29 +26,6 @@
mainthread::mainthread(const QString &bruteforceFile, const QString &checksumsFile, const QString &algorithms, const QString &start, const QString &stop, const QString &lenghts_str, const QString &threads_str, bool strictHash, const std::map<std::string,checksum*> &checksum_map) : checksum_map(checksum_map), strictHash(strictHash)
{
- if (!algorithms.isEmpty()) {
- for (const QString &algorithm : algorithms.split(',')) {
- std::map<std::string,checksum*>::const_iterator it;
- it = checksum_map.find(algorithm.toUpper().toStdString());
- if (it != checksum_map.end()) {
- QTextStream(stderr) << "INFO: Using " << QString::fromStdString(it->first) << " algorithm" << Qt::endl;
- checksum_vector << it->second;
- }
- }
- }
- else {
- std::map<std::string,checksum*>::const_iterator it;
- for (it = checksum_map.begin(); it != checksum_map.end(); it++) {
- QTextStream(stderr) << "INFO: Using " << QString::fromStdString(it->first) << " algorithm" << Qt::endl;
- checksum_vector << it->second;
- }
- }
- if (checksum_vector.isEmpty()) {
- QTextStream(stderr) << "ERROR: No algorithms are used!" << Qt::endl;
- initialised = false;
- return;
- }
-
QFile bruteforceFileHandler(bruteforceFile);
if (bruteforceFileHandler.open(QIODevice::ReadOnly)) {
QTextStream(stderr) << "INFO: Reading source file " << bruteforceFile << "..." << Qt::endl;
@@ -92,6 +69,46 @@ mainthread::mainthread(const QString &bruteforceFile, const QString &checksumsFi
return;
}
+ if (!algorithms.isEmpty()) {
+ for (const QString &algorithm : algorithms.split(',')) {
+ std::map<std::string,checksum*>::const_iterator it;
+ it = checksum_map.find(algorithm.toUpper().toStdString());
+ if (it != checksum_map.end()) {
+ QTextStream(stderr) << "INFO: Using " << QString::fromStdString(it->first) << " algorithm" << Qt::endl;
+ checksum_vector << it->second;
+ }
+ }
+ }
+ else {
+ std::map<std::string,checksum*>::const_iterator it;
+ for (it = checksum_map.begin(); it != checksum_map.end(); it++) {
+ const int checksumSize = it->second->checksumSize();
+ if (!strictHash) {
+ for (const QByteArray &hash : checksums) {
+ if (checksumSize >= hash.count() / 2) {
+ QTextStream(stderr) << "INFO: Using " << QString::fromStdString(it->first) << " algorithm" << Qt::endl;
+ checksum_vector << it->second;
+ break;
+ }
+ }
+ }
+ else {
+ for (const QByteArray &hash : checksums) {
+ if (checksumSize == hash.count() / 2) {
+ QTextStream(stderr) << "INFO: Using " << QString::fromStdString(it->first) << " algorithm" << Qt::endl;
+ checksum_vector << it->second;
+ break;
+ }
+ }
+ }
+ }
+ }
+ if (checksum_vector.isEmpty()) {
+ QTextStream(stderr) << "ERROR: No algorithms are used!" << Qt::endl;
+ initialised = false;
+ return;
+ }
+
if (!start.isEmpty()) {
bool startOk;
begin = start.toULongLong(&startOk);
@@ -250,7 +267,7 @@ void mainthread::run()
if (threads >= mthreads)
eventLoop.exec();
QTextStream(stderr) << "[" << std::distance(lengths.constBegin(), it) + 1 << "/" << lengthsCount << "] [" << min << "/" << max << "] Bruteforcing...\r";
- brutethread *thread = new brutethread(fileContent, min, checksum_vector, checksums);
+ brutethread *thread = new brutethread(fileContent, min, checksum_vector, checksums, strictHash);
QObject::connect(thread, &QThread::finished, this, &mainthread::threadFinished);
QObject::connect(thread, &brutethread::matched, this, &mainthread::matched);
thread->start(QThread::LowPriority);
@@ -261,7 +278,7 @@ void mainthread::run()
if (threads >= mthreads)
eventLoop.exec();
QTextStream(stderr) << "[" << std::distance(lengths.constBegin(), it) + 1 << "/" << lengthsCount << "] [" << clength << "/" << max << "] Bruteforcing...\r";
- brutethread *thread = new brutethread(fileContent, clength, checksum_vector, checksums);
+ brutethread *thread = new brutethread(fileContent, clength, checksum_vector, checksums, strictHash);
QObject::connect(thread, &QThread::finished, this, &mainthread::threadFinished);
QObject::connect(thread, &brutethread::matched, this, &mainthread::matched);
thread->start(QThread::LowPriority);
@@ -273,7 +290,7 @@ void mainthread::run()
if (threads >= mthreads)
eventLoop.exec();
QTextStream(stderr) << "[" << std::distance(lengths.constBegin(), it) + 1 << "/" << lengthsCount << "] [" << clength << "/" << max << "] Bruteforcing...\r";
- brutethread *thread = new brutethread(fileContent, clength, checksum_vector, checksums);
+ brutethread *thread = new brutethread(fileContent, clength, checksum_vector, checksums, strictHash);
QObject::connect(thread, &QThread::finished, this, &mainthread::threadFinished);
QObject::connect(thread, &brutethread::matched, this, &mainthread::matched);
thread->start(QThread::LowPriority);
From 3fe82665013a719e68b966759abc4c5e23f06a76 Mon Sep 17 00:00:00 2001
From: Syping <schiedelrafael@keppe.org>
Date: Sun, 25 Oct 2020 02:54:22 +0200
Subject: [PATCH 2/9] plugin support
---
CMakeLists.txt | 4 ++++
src/brutethread.cpp | 3 ++-
src/checkbrute.h | 26 ++++++++++++++++++++++++
src/checksum_lib.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++
src/checksum_lib.h | 44 ++++++++++++++++++++++++++++++++++++++++
src/checksum_qt.cpp | 2 +-
src/checksum_qt.h | 2 +-
src/main.cpp | 44 ++++++++++++++++++++++++++++++++++------
8 files changed, 164 insertions(+), 9 deletions(-)
create mode 100644 src/checkbrute.h
create mode 100644 src/checksum_lib.cpp
create mode 100644 src/checksum_lib.h
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 08ce949..dd7be16 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -18,13 +18,16 @@ set(CHECKBRUTE_SOURCES
src/mainthread.cpp
src/brutethread.cpp
src/checksum.cpp
+ src/checksum_lib.cpp
src/checksum_qt.cpp
)
set(CHECKBRUTE_HEADERS
src/mainthread.h
src/brutethread.h
+ src/checkbrute.h
src/checksum.h
+ src/checksum_lib.h
src/checksum_qt.h
)
@@ -33,6 +36,7 @@ add_executable(checkbrute
${CHECKBRUTE_SOURCES}
)
+target_compile_definitions(checkbrute PRIVATE "CHECKBRUTE_PLUGINS=\"${CMAKE_INSTALL_PREFIX}/share/checkbrute/plugins\"")
target_link_libraries(checkbrute PRIVATE Qt5::Core)
install(TARGETS checkbrute DESTINATION bin)
diff --git a/src/brutethread.cpp b/src/brutethread.cpp
index a821d2e..13e0beb 100644
--- a/src/brutethread.cpp
+++ b/src/brutethread.cpp
@@ -16,6 +16,7 @@
* responsible for anything with use of the software, you are self responsible.
*****************************************************************************/
+#include <QDebug>
#include <QTextStream>
#include "brutethread.h"
@@ -27,7 +28,7 @@ void brutethread::run()
for (quint64 seek = 0; seek + length < size; seek++) {
for (checksum *generator : checksum_vector) {
const QByteArray content = fileContent.mid(seek, length);
- const QByteArray generatedHash = generator->generateChecksum(content).toHex();
+ const QByteArray generatedHash = generator->generateChecksum(content);
for (const QByteArray &hash : checksums) {
if (!strictMatch && generatedHash.left(hash.length()) == hash) {
QTextStream(stdout) << "MATCH: " << generator->formatName() << " Checksum " << hash << " Start " << seek << " End " << seek+length << Qt::endl;
diff --git a/src/checkbrute.h b/src/checkbrute.h
new file mode 100644
index 0000000..dbfb3bb
--- /dev/null
+++ b/src/checkbrute.h
@@ -0,0 +1,26 @@
+/*****************************************************************************
+* 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.
+*****************************************************************************/
+
+#ifndef CHECKBRUTE_H
+#define CHECKBRUTE_H
+
+#ifndef CHECKBRUTE_PLUGINS
+#define CHECKBRUTE_PLUGINS "/usr/local/share/checkbrute/plugins"
+#endif
+
+#endif // CHECKBRUTE_H
diff --git a/src/checksum_lib.cpp b/src/checksum_lib.cpp
new file mode 100644
index 0000000..c929fe5
--- /dev/null
+++ b/src/checksum_lib.cpp
@@ -0,0 +1,48 @@
+/*****************************************************************************
+* 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.
+*****************************************************************************/
+
+#include "checksum_lib.h"
+#include <iostream>
+#include <cstdint>
+#include <cstring>
+
+checksum_lib::checksum_lib(PluginFormatFunction formatFunc, PluginHash64Function hash64Func, PluginHashSzFunction hashSzFunc) : hash64Func(hash64Func)
+{
+ p_formatName = QString::fromUtf8(formatFunc());
+ p_checksumSize = hashSzFunc();
+}
+
+QByteArray checksum_lib::generateChecksum(const QByteArray &data)
+{
+ const size_t size = data.size();
+ unsigned char *udata = new unsigned char[size];
+ std::memcpy(udata, data.constData(), size);
+ const u_int64_t hash = hash64Func(udata, size);
+ free(udata);
+ return QByteArray::number((quint64)hash, 16);
+}
+
+const QString checksum_lib::formatName()
+{
+ return p_formatName;
+}
+
+int checksum_lib::checksumSize()
+{
+ return p_checksumSize;
+}
diff --git a/src/checksum_lib.h b/src/checksum_lib.h
new file mode 100644
index 0000000..ea6bd22
--- /dev/null
+++ b/src/checksum_lib.h
@@ -0,0 +1,44 @@
+/*****************************************************************************
+* 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.
+*****************************************************************************/
+
+#ifndef CHECKSUM_LIB_H
+#define CHECKSUM_LIB_H
+
+#include "checksum.h"
+
+typedef int (*PluginHashSzFunction)();
+typedef const char* (*PluginFormatFunction)();
+typedef const char* (*PluginVersionFunction)();
+typedef u_int64_t (*PluginHash64Function)(unsigned char*, size_t);
+
+class checksum_lib : public checksum
+{
+ Q_OBJECT
+public:
+ explicit checksum_lib(PluginFormatFunction formatFunc, PluginHash64Function hash64Func, PluginHashSzFunction hashSzFunc);
+ QByteArray generateChecksum(const QByteArray &data);
+ const QString formatName();
+ int checksumSize();
+
+private:
+ PluginHash64Function hash64Func;
+ QString p_formatName;
+ int p_checksumSize;
+};
+
+#endif // CHECKSUM_LIB_H
diff --git a/src/checksum_qt.cpp b/src/checksum_qt.cpp
index 7c69284..fdcd560 100644
--- a/src/checksum_qt.cpp
+++ b/src/checksum_qt.cpp
@@ -23,7 +23,7 @@ checksum_qt::checksum_qt(QCryptographicHash::Algorithm algorithm, const QString
QByteArray checksum_qt::generateChecksum(const QByteArray &data)
{
- return QCryptographicHash::hash(data, algorithm);
+ return QCryptographicHash::hash(data, algorithm).toHex();
}
const QString checksum_qt::formatName()
diff --git a/src/checksum_qt.h b/src/checksum_qt.h
index 95a58f0..3fdd03c 100644
--- a/src/checksum_qt.h
+++ b/src/checksum_qt.h
@@ -36,4 +36,4 @@ private:
QString name;
};
-#endif // CHECKSUM_MD5_H
+#endif // CHECKSUM_QT5_H
diff --git a/src/main.cpp b/src/main.cpp
index a85a050..5eb42ac 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -22,17 +22,21 @@
#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.1.1");
+ a.setApplicationVersion("0.2");
QCommandLineParser commandLineParser;
commandLineParser.addHelpOption();
@@ -85,11 +89,11 @@ int main(int argc, char *argv[])
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-224"] = new checksum_qt(QCryptographicHash::Sha224, "SHA2-224");
- checksum_map["SHA2-256"] = new checksum_qt(QCryptographicHash::Sha256, "SHA2-256");
- checksum_map["SHA2-384"] = new checksum_qt(QCryptographicHash::Sha384, "SHA2-384");
- checksum_map["SHA2-512"] = new checksum_qt(QCryptographicHash::Sha512, "SHA2-512");
+ 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");
@@ -101,6 +105,34 @@ int main(int argc, char *argv[])
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()) {
+ 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 && 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;
+ }
+ 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())
From d115b6fc8ba7ab296b799fd649bd1b3c036164f4 Mon Sep 17 00:00:00 2001
From: Syping <schiedelrafael@keppe.org>
Date: Sun, 25 Oct 2020 03:33:30 +0100
Subject: [PATCH 3/9] minor string fix
---
src/main.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main.cpp b/src/main.cpp
index 5eb42ac..1e5efee 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -36,7 +36,7 @@ int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
a.setApplicationName("checkbrute");
- a.setApplicationVersion("0.2");
+ a.setApplicationVersion("0.2.1");
QCommandLineParser commandLineParser;
commandLineParser.addHelpOption();
@@ -121,7 +121,7 @@ int main(int argc, char *argv[])
if (versionFunc)
version = QString::fromUtf8(versionFunc());
checksum_map[format] = new checksum_lib(formatFunc, hash64Func, hashSzFunc);
- QTextStream(stderr) << "INFO: " << format << " Plugin " << fileName << " loaded" << Qt::endl;
+ QTextStream(stderr) << "INFO: " << format << " plugin " << fileName << " loaded" << Qt::endl;
}
else {
QTextStream(stderr) << "WARNING: Failed loading plugin " << fileName << "!" << Qt::endl;
From 11ae78cc2fec1c3a17ecd5530e1dd3aadb4abf4c Mon Sep 17 00:00:00 2001
From: Syping <schiedelrafael@keppe.org>
Date: Sun, 25 Oct 2020 14:17:36 +0100
Subject: [PATCH 4/9] 32 bit hash function introduced
---
src/checksum_lib.cpp | 21 ++++++++++++++++++---
src/checksum_lib.h | 4 ++++
src/main.cpp | 13 +++++++++++--
3 files changed, 33 insertions(+), 5 deletions(-)
diff --git a/src/checksum_lib.cpp b/src/checksum_lib.cpp
index c929fe5..60e1f7d 100644
--- a/src/checksum_lib.cpp
+++ b/src/checksum_lib.cpp
@@ -21,10 +21,18 @@
#include <cstdint>
#include <cstring>
+checksum_lib::checksum_lib(PluginFormatFunction formatFunc, PluginHash32Function hash32Func, PluginHashSzFunction hashSzFunc) : hash32Func(hash32Func)
+{
+ p_formatName = QString::fromUtf8(formatFunc());
+ p_checksumSize = hashSzFunc();
+ p_funcBit = 64;
+}
+
checksum_lib::checksum_lib(PluginFormatFunction formatFunc, PluginHash64Function hash64Func, PluginHashSzFunction hashSzFunc) : hash64Func(hash64Func)
{
p_formatName = QString::fromUtf8(formatFunc());
p_checksumSize = hashSzFunc();
+ p_funcBit = 32;
}
QByteArray checksum_lib::generateChecksum(const QByteArray &data)
@@ -32,9 +40,16 @@ QByteArray checksum_lib::generateChecksum(const QByteArray &data)
const size_t size = data.size();
unsigned char *udata = new unsigned char[size];
std::memcpy(udata, data.constData(), size);
- const u_int64_t hash = hash64Func(udata, size);
- free(udata);
- return QByteArray::number((quint64)hash, 16);
+ if (p_funcBit == 32) {
+ const u_int32_t hash = hash32Func(udata, size);
+ free(udata);
+ return QByteArray::number((quint32)hash, 16);
+ }
+ else {
+ const u_int64_t hash = hash64Func(udata, size);
+ free(udata);
+ return QByteArray::number((quint64)hash, 16);
+ }
}
const QString checksum_lib::formatName()
diff --git a/src/checksum_lib.h b/src/checksum_lib.h
index ea6bd22..f706c2c 100644
--- a/src/checksum_lib.h
+++ b/src/checksum_lib.h
@@ -24,21 +24,25 @@
typedef int (*PluginHashSzFunction)();
typedef const char* (*PluginFormatFunction)();
typedef const char* (*PluginVersionFunction)();
+typedef u_int32_t (*PluginHash32Function)(unsigned char*, size_t);
typedef u_int64_t (*PluginHash64Function)(unsigned char*, size_t);
class checksum_lib : public checksum
{
Q_OBJECT
public:
+ explicit checksum_lib(PluginFormatFunction formatFunc, PluginHash32Function hash32Func, PluginHashSzFunction hashSzFunc);
explicit checksum_lib(PluginFormatFunction formatFunc, PluginHash64Function hash64Func, PluginHashSzFunction hashSzFunc);
QByteArray generateChecksum(const QByteArray &data);
const QString formatName();
int checksumSize();
private:
+ PluginHash32Function hash32Func;
PluginHash64Function hash64Func;
QString p_formatName;
int p_checksumSize;
+ int p_funcBit;
};
#endif // CHECKSUM_LIB_H
diff --git a/src/main.cpp b/src/main.cpp
index 1e5efee..71f7d76 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -36,7 +36,7 @@ int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
a.setApplicationName("checkbrute");
- a.setApplicationVersion("0.2.1");
+ a.setApplicationVersion("0.3");
QCommandLineParser commandLineParser;
commandLineParser.addHelpOption();
@@ -111,11 +111,20 @@ int main(int argc, char *argv[])
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 && hash64Func && hashSzFunc) {
+ 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;
+ }
+ else if (formatFunc && hash64Func && hashSzFunc) {
QString version = "undefined";
const char *format = formatFunc();
if (versionFunc)
From 9fdcba128f093d29e6d045cd8e1deebc29c9ce18 Mon Sep 17 00:00:00 2001
From: Syping <schiedelrafael@keppe.org>
Date: Sun, 25 Oct 2020 14:42:31 +0100
Subject: [PATCH 5/9] fix bit detection
---
src/checksum_lib.cpp | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/checksum_lib.cpp b/src/checksum_lib.cpp
index 60e1f7d..86dff1e 100644
--- a/src/checksum_lib.cpp
+++ b/src/checksum_lib.cpp
@@ -25,14 +25,14 @@ checksum_lib::checksum_lib(PluginFormatFunction formatFunc, PluginHash32Function
{
p_formatName = QString::fromUtf8(formatFunc());
p_checksumSize = hashSzFunc();
- p_funcBit = 64;
+ p_funcBit = 32;
}
checksum_lib::checksum_lib(PluginFormatFunction formatFunc, PluginHash64Function hash64Func, PluginHashSzFunction hashSzFunc) : hash64Func(hash64Func)
{
p_formatName = QString::fromUtf8(formatFunc());
p_checksumSize = hashSzFunc();
- p_funcBit = 32;
+ p_funcBit = 64;
}
QByteArray checksum_lib::generateChecksum(const QByteArray &data)
@@ -44,11 +44,13 @@ QByteArray checksum_lib::generateChecksum(const QByteArray &data)
const u_int32_t hash = hash32Func(udata, size);
free(udata);
return QByteArray::number((quint32)hash, 16);
+ return QByteArray();
}
else {
const u_int64_t hash = hash64Func(udata, size);
free(udata);
return QByteArray::number((quint64)hash, 16);
+ return QByteArray();
}
}
From e3b7cf162be05364bd996a5591e56b62378373ca Mon Sep 17 00:00:00 2001
From: Syping <schiedelrafael@keppe.org>
Date: Sun, 25 Oct 2020 16:35:15 +0100
Subject: [PATCH 6/9] add -t test function
---
src/main.cpp | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/main.cpp b/src/main.cpp
index 71f7d76..00088aa 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -36,7 +36,7 @@ int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
a.setApplicationName("checkbrute");
- a.setApplicationVersion("0.3");
+ a.setApplicationVersion("0.3.1");
QCommandLineParser commandLineParser;
commandLineParser.addHelpOption();
@@ -49,7 +49,8 @@ int main(int argc, char *argv[])
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);
+ 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;
@@ -62,6 +63,7 @@ int main(int argc, char *argv[])
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;
@@ -123,6 +125,8 @@ int main(int argc, char *argv[])
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";
@@ -131,6 +135,8 @@ int main(int argc, char *argv[])
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;
From 74f4478c326a71cd36b542b8d8fd0aa3bf5e0bdb Mon Sep 17 00:00:00 2001
From: Syping <schiedelrafael@keppe.org>
Date: Sun, 25 Oct 2020 17:30:29 +0100
Subject: [PATCH 7/9] show partial bruteforce
---
src/main.cpp | 2 +-
src/mainthread.cpp | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/main.cpp b/src/main.cpp
index 00088aa..6b82ae4 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -36,7 +36,7 @@ int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
a.setApplicationName("checkbrute");
- a.setApplicationVersion("0.3.1");
+ a.setApplicationVersion("0.3.2");
QCommandLineParser commandLineParser;
commandLineParser.addHelpOption();
diff --git a/src/mainthread.cpp b/src/mainthread.cpp
index 5209d38..5364261 100644
--- a/src/mainthread.cpp
+++ b/src/mainthread.cpp
@@ -142,9 +142,10 @@ mainthread::mainthread(const QString &bruteforceFile, const QString &checksumsFi
}
// Clear unneeded bytes
- if (begin != 0 && end != (quint64)fileContent.size()) {
+ if (begin != 0 || end != (quint64)fileContent.size()) {
fileContent = fileContent.mid(begin, end - begin);
fileContent.squeeze();
+ QTextStream(stderr) << "INFO: Partial bruteforce start " << begin << " stop " << end << Qt::endl;
}
if (!lenghts_str.isEmpty()) {
From 1523aff9817e22f5006b4207db5df820c24914b7 Mon Sep 17 00:00:00 2001
From: Syping <schiedelrafael@keppe.org>
Date: Sun, 25 Oct 2020 19:07:36 +0100
Subject: [PATCH 8/9] Fix 2x return
---
src/checksum_lib.cpp | 2 --
1 file changed, 2 deletions(-)
diff --git a/src/checksum_lib.cpp b/src/checksum_lib.cpp
index 86dff1e..9138767 100644
--- a/src/checksum_lib.cpp
+++ b/src/checksum_lib.cpp
@@ -44,13 +44,11 @@ QByteArray checksum_lib::generateChecksum(const QByteArray &data)
const u_int32_t hash = hash32Func(udata, size);
free(udata);
return QByteArray::number((quint32)hash, 16);
- return QByteArray();
}
else {
const u_int64_t hash = hash64Func(udata, size);
free(udata);
return QByteArray::number((quint64)hash, 16);
- return QByteArray();
}
}
From ad13b411d166bc8ca857ed92c260367cf3321697 Mon Sep 17 00:00:00 2001
From: Syping <schiedelrafael@keppe.org>
Date: Sun, 25 Oct 2020 19:16:08 +0100
Subject: [PATCH 9/9] improve Start End output
---
src/brutethread.cpp | 6 +++---
src/brutethread.h | 3 ++-
src/main.cpp | 2 +-
src/mainthread.cpp | 8 ++++----
4 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/src/brutethread.cpp b/src/brutethread.cpp
index 13e0beb..46d3fb4 100644
--- a/src/brutethread.cpp
+++ b/src/brutethread.cpp
@@ -20,7 +20,7 @@
#include <QTextStream>
#include "brutethread.h"
-brutethread::brutethread(const QByteArray &fileContent, quint64 length, QVector<checksum*> checksum_vector, QVector<QByteArray> checksums, bool strictMatch) : checksum_vector(checksum_vector), checksums(checksums), fileContent(fileContent), strictMatch(strictMatch), length(length) {}
+brutethread::brutethread(const QByteArray &fileContent, quint64 length, quint64 begin, QVector<checksum*> checksum_vector, QVector<QByteArray> checksums, bool strictMatch) : checksum_vector(checksum_vector), checksums(checksums), fileContent(fileContent), strictMatch(strictMatch), length(length), begin(begin) {}
void brutethread::run()
{
@@ -31,11 +31,11 @@ void brutethread::run()
const QByteArray generatedHash = generator->generateChecksum(content);
for (const QByteArray &hash : checksums) {
if (!strictMatch && generatedHash.left(hash.length()) == hash) {
- QTextStream(stdout) << "MATCH: " << generator->formatName() << " Checksum " << hash << " Start " << seek << " End " << seek+length << Qt::endl;
+ QTextStream(stdout) << "MATCH: " << generator->formatName() << " Checksum " << hash << " Start " << begin+seek << " End " << begin+seek+length << Qt::endl;
emit matched();
}
else if (strictMatch && generatedHash.length() == hash.length() && generatedHash == hash) {
- QTextStream(stdout) << "MATCH: " << generator->formatName() << " Checksum " << hash << " Start " << seek << " End " << seek+length << Qt::endl;
+ QTextStream(stdout) << "MATCH: " << generator->formatName() << " Checksum " << hash << " Start " << begin+seek << " End " << begin+seek+length << Qt::endl;
emit matched();
}
}
diff --git a/src/brutethread.h b/src/brutethread.h
index d011af9..5f15b8e 100644
--- a/src/brutethread.h
+++ b/src/brutethread.h
@@ -33,7 +33,7 @@ class brutethread : public QThread
{
Q_OBJECT
public:
- explicit brutethread(const QByteArray &fileContent, quint64 length, QVector<checksum*> checksum_vector, QVector<QByteArray> checksums, bool strictMatch);
+ explicit brutethread(const QByteArray &fileContent, quint64 length, quint64 begin, QVector<checksum*> checksum_vector, QVector<QByteArray> checksums, bool strictMatch);
void run();
private:
@@ -42,6 +42,7 @@ private:
QByteArray fileContent;
bool strictMatch;
quint64 length;
+ quint64 begin;
signals:
void matched();
diff --git a/src/main.cpp b/src/main.cpp
index 6b82ae4..c7194c3 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -36,7 +36,7 @@ int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
a.setApplicationName("checkbrute");
- a.setApplicationVersion("0.3.2");
+ a.setApplicationVersion("0.3.3");
QCommandLineParser commandLineParser;
commandLineParser.addHelpOption();
diff --git a/src/mainthread.cpp b/src/mainthread.cpp
index 5364261..6a54fee 100644
--- a/src/mainthread.cpp
+++ b/src/mainthread.cpp
@@ -145,7 +145,7 @@ mainthread::mainthread(const QString &bruteforceFile, const QString &checksumsFi
if (begin != 0 || end != (quint64)fileContent.size()) {
fileContent = fileContent.mid(begin, end - begin);
fileContent.squeeze();
- QTextStream(stderr) << "INFO: Partial bruteforce start " << begin << " stop " << end << Qt::endl;
+ QTextStream(stderr) << "INFO: Bruteforce Start " << begin << " End " << end << Qt::endl;
}
if (!lenghts_str.isEmpty()) {
@@ -268,7 +268,7 @@ void mainthread::run()
if (threads >= mthreads)
eventLoop.exec();
QTextStream(stderr) << "[" << std::distance(lengths.constBegin(), it) + 1 << "/" << lengthsCount << "] [" << min << "/" << max << "] Bruteforcing...\r";
- brutethread *thread = new brutethread(fileContent, min, checksum_vector, checksums, strictHash);
+ brutethread *thread = new brutethread(fileContent, min, begin, checksum_vector, checksums, strictHash);
QObject::connect(thread, &QThread::finished, this, &mainthread::threadFinished);
QObject::connect(thread, &brutethread::matched, this, &mainthread::matched);
thread->start(QThread::LowPriority);
@@ -279,7 +279,7 @@ void mainthread::run()
if (threads >= mthreads)
eventLoop.exec();
QTextStream(stderr) << "[" << std::distance(lengths.constBegin(), it) + 1 << "/" << lengthsCount << "] [" << clength << "/" << max << "] Bruteforcing...\r";
- brutethread *thread = new brutethread(fileContent, clength, checksum_vector, checksums, strictHash);
+ brutethread *thread = new brutethread(fileContent, clength, begin, checksum_vector, checksums, strictHash);
QObject::connect(thread, &QThread::finished, this, &mainthread::threadFinished);
QObject::connect(thread, &brutethread::matched, this, &mainthread::matched);
thread->start(QThread::LowPriority);
@@ -291,7 +291,7 @@ void mainthread::run()
if (threads >= mthreads)
eventLoop.exec();
QTextStream(stderr) << "[" << std::distance(lengths.constBegin(), it) + 1 << "/" << lengthsCount << "] [" << clength << "/" << max << "] Bruteforcing...\r";
- brutethread *thread = new brutethread(fileContent, clength, checksum_vector, checksums, strictHash);
+ brutethread *thread = new brutethread(fileContent, clength, begin, checksum_vector, checksums, strictHash);
QObject::connect(thread, &QThread::finished, this, &mainthread::threadFinished);
QObject::connect(thread, &brutethread::matched, this, &mainthread::matched);
thread->start(QThread::LowPriority);