Compare commits
6 commits
Author | SHA1 | Date | |
---|---|---|---|
ad13b411d1 | |||
1523aff981 | |||
74f4478c32 | |||
e3b7cf162b | |||
9fdcba128f | |||
11ae78cc2f |
|
@ -20,7 +20,7 @@
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include "brutethread.h"
|
#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()
|
void brutethread::run()
|
||||||
{
|
{
|
||||||
|
@ -31,11 +31,11 @@ void brutethread::run()
|
||||||
const QByteArray generatedHash = generator->generateChecksum(content);
|
const QByteArray generatedHash = generator->generateChecksum(content);
|
||||||
for (const QByteArray &hash : checksums) {
|
for (const QByteArray &hash : checksums) {
|
||||||
if (!strictMatch && 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;
|
QTextStream(stdout) << "MATCH: " << generator->formatName() << " Checksum " << hash << " Start " << begin+seek << " End " << begin+seek+length << Qt::endl;
|
||||||
emit matched();
|
emit matched();
|
||||||
}
|
}
|
||||||
else if (strictMatch && generatedHash.length() == hash.length() && generatedHash == hash) {
|
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();
|
emit matched();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ class brutethread : public QThread
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
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();
|
void run();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -42,6 +42,7 @@ private:
|
||||||
QByteArray fileContent;
|
QByteArray fileContent;
|
||||||
bool strictMatch;
|
bool strictMatch;
|
||||||
quint64 length;
|
quint64 length;
|
||||||
|
quint64 begin;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void matched();
|
void matched();
|
||||||
|
|
|
@ -21,10 +21,18 @@
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
checksum_lib::checksum_lib(PluginFormatFunction formatFunc, PluginHash32Function hash32Func, PluginHashSzFunction hashSzFunc) : hash32Func(hash32Func)
|
||||||
|
{
|
||||||
|
p_formatName = QString::fromUtf8(formatFunc());
|
||||||
|
p_checksumSize = hashSzFunc();
|
||||||
|
p_funcBit = 32;
|
||||||
|
}
|
||||||
|
|
||||||
checksum_lib::checksum_lib(PluginFormatFunction formatFunc, PluginHash64Function hash64Func, PluginHashSzFunction hashSzFunc) : hash64Func(hash64Func)
|
checksum_lib::checksum_lib(PluginFormatFunction formatFunc, PluginHash64Function hash64Func, PluginHashSzFunction hashSzFunc) : hash64Func(hash64Func)
|
||||||
{
|
{
|
||||||
p_formatName = QString::fromUtf8(formatFunc());
|
p_formatName = QString::fromUtf8(formatFunc());
|
||||||
p_checksumSize = hashSzFunc();
|
p_checksumSize = hashSzFunc();
|
||||||
|
p_funcBit = 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray checksum_lib::generateChecksum(const QByteArray &data)
|
QByteArray checksum_lib::generateChecksum(const QByteArray &data)
|
||||||
|
@ -32,9 +40,16 @@ QByteArray checksum_lib::generateChecksum(const QByteArray &data)
|
||||||
const size_t size = data.size();
|
const size_t size = data.size();
|
||||||
unsigned char *udata = new unsigned char[size];
|
unsigned char *udata = new unsigned char[size];
|
||||||
std::memcpy(udata, data.constData(), size);
|
std::memcpy(udata, data.constData(), size);
|
||||||
const u_int64_t hash = hash64Func(udata, size);
|
if (p_funcBit == 32) {
|
||||||
free(udata);
|
const u_int32_t hash = hash32Func(udata, size);
|
||||||
return QByteArray::number((quint64)hash, 16);
|
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()
|
const QString checksum_lib::formatName()
|
||||||
|
|
|
@ -24,21 +24,25 @@
|
||||||
typedef int (*PluginHashSzFunction)();
|
typedef int (*PluginHashSzFunction)();
|
||||||
typedef const char* (*PluginFormatFunction)();
|
typedef const char* (*PluginFormatFunction)();
|
||||||
typedef const char* (*PluginVersionFunction)();
|
typedef const char* (*PluginVersionFunction)();
|
||||||
|
typedef u_int32_t (*PluginHash32Function)(unsigned char*, size_t);
|
||||||
typedef u_int64_t (*PluginHash64Function)(unsigned char*, size_t);
|
typedef u_int64_t (*PluginHash64Function)(unsigned char*, size_t);
|
||||||
|
|
||||||
class checksum_lib : public checksum
|
class checksum_lib : public checksum
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
explicit checksum_lib(PluginFormatFunction formatFunc, PluginHash32Function hash32Func, PluginHashSzFunction hashSzFunc);
|
||||||
explicit checksum_lib(PluginFormatFunction formatFunc, PluginHash64Function hash64Func, PluginHashSzFunction hashSzFunc);
|
explicit checksum_lib(PluginFormatFunction formatFunc, PluginHash64Function hash64Func, PluginHashSzFunction hashSzFunc);
|
||||||
QByteArray generateChecksum(const QByteArray &data);
|
QByteArray generateChecksum(const QByteArray &data);
|
||||||
const QString formatName();
|
const QString formatName();
|
||||||
int checksumSize();
|
int checksumSize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
PluginHash32Function hash32Func;
|
||||||
PluginHash64Function hash64Func;
|
PluginHash64Function hash64Func;
|
||||||
QString p_formatName;
|
QString p_formatName;
|
||||||
int p_checksumSize;
|
int p_checksumSize;
|
||||||
|
int p_funcBit;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CHECKSUM_LIB_H
|
#endif // CHECKSUM_LIB_H
|
||||||
|
|
21
src/main.cpp
21
src/main.cpp
|
@ -36,7 +36,7 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QCoreApplication a(argc, argv);
|
QCoreApplication a(argc, argv);
|
||||||
a.setApplicationName("checkbrute");
|
a.setApplicationName("checkbrute");
|
||||||
a.setApplicationVersion("0.2.1");
|
a.setApplicationVersion("0.3.3");
|
||||||
|
|
||||||
QCommandLineParser commandLineParser;
|
QCommandLineParser commandLineParser;
|
||||||
commandLineParser.addHelpOption();
|
commandLineParser.addHelpOption();
|
||||||
|
@ -49,7 +49,8 @@ int main(int argc, char *argv[])
|
||||||
QCommandLineOption lengthsOption = QCommandLineOption("lengths", "Lengths to use for bruteforcing.", "lengths");
|
QCommandLineOption lengthsOption = QCommandLineOption("lengths", "Lengths to use for bruteforcing.", "lengths");
|
||||||
QCommandLineOption threadsOption = QCommandLineOption("threads", "Threads to use for bruteforcing.", "threads");
|
QCommandLineOption threadsOption = QCommandLineOption("threads", "Threads to use for bruteforcing.", "threads");
|
||||||
QCommandLineOption strictOption = QCommandLineOption(QStringList() << "s" << "strict", "Match checksums strict.");
|
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);
|
commandLineParser.process(a);
|
||||||
|
|
||||||
QTextStream(stderr) << "INFO: Launch " << a.applicationName() << " " << a.applicationVersion() << "..." << Qt::endl;
|
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 bruteforceFile = args.at(0);
|
||||||
const QString checksumsFile = args.at(1);
|
const QString checksumsFile = args.at(1);
|
||||||
const bool strictHash = commandLineParser.isSet(strictOption);
|
const bool strictHash = commandLineParser.isSet(strictOption);
|
||||||
|
const bool testEnabled = commandLineParser.isSet(testOption);
|
||||||
|
|
||||||
if (strictHash) {
|
if (strictHash) {
|
||||||
QTextStream(stderr) << "INFO: Strict matching enabled" << Qt::endl;
|
QTextStream(stderr) << "INFO: Strict matching enabled" << Qt::endl;
|
||||||
|
@ -111,17 +113,30 @@ int main(int argc, char *argv[])
|
||||||
QTextStream(stderr) << "INFO: Load plugin " << fileName << "..." << Qt::endl;
|
QTextStream(stderr) << "INFO: Load plugin " << fileName << "..." << Qt::endl;
|
||||||
QLibrary plugin(filePath);
|
QLibrary plugin(filePath);
|
||||||
if (plugin.load()) {
|
if (plugin.load()) {
|
||||||
|
PluginHash32Function hash32Func = (PluginHash32Function)plugin.resolve("checkbrute_hash32");
|
||||||
PluginHash64Function hash64Func = (PluginHash64Function)plugin.resolve("checkbrute_hash64");
|
PluginHash64Function hash64Func = (PluginHash64Function)plugin.resolve("checkbrute_hash64");
|
||||||
PluginHashSzFunction hashSzFunc = (PluginHashSzFunction)plugin.resolve("checkbrute_hashsz");
|
PluginHashSzFunction hashSzFunc = (PluginHashSzFunction)plugin.resolve("checkbrute_hashsz");
|
||||||
PluginFormatFunction formatFunc = (PluginFormatFunction)plugin.resolve("checkbrute_format");
|
PluginFormatFunction formatFunc = (PluginFormatFunction)plugin.resolve("checkbrute_format");
|
||||||
PluginVersionFunction versionFunc = (PluginVersionFunction)plugin.resolve("checkbrute_version");
|
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;
|
||||||
|
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";
|
QString version = "undefined";
|
||||||
const char *format = formatFunc();
|
const char *format = formatFunc();
|
||||||
if (versionFunc)
|
if (versionFunc)
|
||||||
version = QString::fromUtf8(versionFunc());
|
version = QString::fromUtf8(versionFunc());
|
||||||
checksum_map[format] = new checksum_lib(formatFunc, hash64Func, hashSzFunc);
|
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;
|
||||||
|
if (testEnabled)
|
||||||
|
QTextStream(stderr) << "TEST: " << format << " checkbrute -> " << QString::number(hash64Func((unsigned char*)"checkbrute", 7), 16) << Qt::endl;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
QTextStream(stderr) << "WARNING: Failed loading plugin " << fileName << "!" << Qt::endl;
|
QTextStream(stderr) << "WARNING: Failed loading plugin " << fileName << "!" << Qt::endl;
|
||||||
|
|
|
@ -142,9 +142,10 @@ mainthread::mainthread(const QString &bruteforceFile, const QString &checksumsFi
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear unneeded bytes
|
// Clear unneeded bytes
|
||||||
if (begin != 0 && end != (quint64)fileContent.size()) {
|
if (begin != 0 || end != (quint64)fileContent.size()) {
|
||||||
fileContent = fileContent.mid(begin, end - begin);
|
fileContent = fileContent.mid(begin, end - begin);
|
||||||
fileContent.squeeze();
|
fileContent.squeeze();
|
||||||
|
QTextStream(stderr) << "INFO: Bruteforce Start " << begin << " End " << end << Qt::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lenghts_str.isEmpty()) {
|
if (!lenghts_str.isEmpty()) {
|
||||||
|
@ -267,7 +268,7 @@ void mainthread::run()
|
||||||
if (threads >= mthreads)
|
if (threads >= mthreads)
|
||||||
eventLoop.exec();
|
eventLoop.exec();
|
||||||
QTextStream(stderr) << "[" << std::distance(lengths.constBegin(), it) + 1 << "/" << lengthsCount << "] [" << min << "/" << max << "] Bruteforcing...\r";
|
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, &QThread::finished, this, &mainthread::threadFinished);
|
||||||
QObject::connect(thread, &brutethread::matched, this, &mainthread::matched);
|
QObject::connect(thread, &brutethread::matched, this, &mainthread::matched);
|
||||||
thread->start(QThread::LowPriority);
|
thread->start(QThread::LowPriority);
|
||||||
|
@ -278,7 +279,7 @@ void mainthread::run()
|
||||||
if (threads >= mthreads)
|
if (threads >= mthreads)
|
||||||
eventLoop.exec();
|
eventLoop.exec();
|
||||||
QTextStream(stderr) << "[" << std::distance(lengths.constBegin(), it) + 1 << "/" << lengthsCount << "] [" << clength << "/" << max << "] Bruteforcing...\r";
|
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, &QThread::finished, this, &mainthread::threadFinished);
|
||||||
QObject::connect(thread, &brutethread::matched, this, &mainthread::matched);
|
QObject::connect(thread, &brutethread::matched, this, &mainthread::matched);
|
||||||
thread->start(QThread::LowPriority);
|
thread->start(QThread::LowPriority);
|
||||||
|
@ -290,7 +291,7 @@ void mainthread::run()
|
||||||
if (threads >= mthreads)
|
if (threads >= mthreads)
|
||||||
eventLoop.exec();
|
eventLoop.exec();
|
||||||
QTextStream(stderr) << "[" << std::distance(lengths.constBegin(), it) + 1 << "/" << lengthsCount << "] [" << clength << "/" << max << "] Bruteforcing...\r";
|
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, &QThread::finished, this, &mainthread::threadFinished);
|
||||||
QObject::connect(thread, &brutethread::matched, this, &mainthread::matched);
|
QObject::connect(thread, &brutethread::matched, this, &mainthread::matched);
|
||||||
thread->start(QThread::LowPriority);
|
thread->start(QThread::LowPriority);
|
||||||
|
|
Loading…
Reference in a new issue