From aa5274969adb47b6fb10dccfa715c34339a6cc19 Mon Sep 17 00:00:00 2001 From: Tr4il <6537388+Tr4il@users.noreply.github.com> Date: Fri, 8 Mar 2024 12:25:41 +0100 Subject: [PATCH] Applied obfuscation fixes from xompage/ngpost --- src/nntp/NntpArticle.cpp | 35 +++++++++++++++++++++++++++++++---- src/nntp/NntpArticle.h | 3 ++- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/nntp/NntpArticle.cpp b/src/nntp/NntpArticle.cpp index 823b65a3..e405302c 100644 --- a/src/nntp/NntpArticle.cpp +++ b/src/nntp/NntpArticle.cpp @@ -29,13 +29,14 @@ ushort NntpArticle::sNbMaxTrySending = 5; NntpArticle::NntpArticle(NntpFile *file, uint part, qint64 pos, qint64 bytes, - const std::string *from, bool obfuscation): + const std::string *from, bool obfuscateArticles): _nntpFile(file), _part(part), _id(QUuid::createUuid()), _from(from), _subject(nullptr), _body(nullptr), _filePos(pos), _fileBytes(bytes), + _obfuscateArticles(obfuscateArticles), _nbTrySending(0), _msgId() { @@ -43,7 +44,7 @@ NntpArticle::NntpArticle(NntpFile *file, uint part, qint64 pos, qint64 bytes, connect(this, &NntpArticle::posted, _nntpFile, &NntpFile::onArticlePosted, Qt::QueuedConnection); connect(this, &NntpArticle::failed, _nntpFile, &NntpFile::onArticleFailed, Qt::QueuedConnection); - if (!obfuscation) + if (!obfuscateArticles) { std::stringstream ss; ss << _nntpFile->nameWithQuotes().toStdString() << " (" << part << "/" << _nntpFile->nbArticles() << ")"; @@ -54,6 +55,21 @@ NntpArticle::NntpArticle(NntpFile *file, uint part, qint64 pos, qint64 bytes, } } +std::string generateRandomString(int length) +{ + static const char alphanum[] = + "0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz"; + + std::string randomString; + for (int i = 0; i < length; ++i) { + randomString += alphanum[rand() % (sizeof(alphanum) - 1)]; + } + + return randomString; +} + void NntpArticle::yEncBody(const char data[]) { // do the yEnc encoding @@ -63,8 +79,19 @@ void NntpArticle::yEncBody(const char data[]) // format the body std::stringstream ss; + std::string filename; + if (_obfuscateArticles) + { + // Generate a random string for the filename + const int randomStringLength = 32 + (rand() % 31); // between 32-62 length + filename = generateRandomString(randomStringLength); + } + else + filename = _nntpFile->fileName(); + + // Use the generated random string as the filename ss << "=ybegin part=" << _part << " total=" << _nntpFile->nbArticles() << " line=128" - << " size=" << _nntpFile->fileSize() << " name=" << _nntpFile->fileName() << Nntp::ENDLINE + << " size=" << _nntpFile->fileSize() << " name=" << filename << Nntp::ENDLINE << "=ypart begin=" << _filePos + 1 << " end=" << _filePos + _fileBytes << Nntp::ENDLINE << yencBody << Nntp::ENDLINE << "=yend size=" << _fileBytes << " pcrc32=" << std::hex << crc32 << Nntp::ENDLINE @@ -163,4 +190,4 @@ void NntpArticle::dumpToFile(const QString &path, const std::string &articleIdSi file.write(header(articleIdSignature).c_str()); file.write(_body); file.close(); -} +} \ No newline at end of file diff --git a/src/nntp/NntpArticle.h b/src/nntp/NntpArticle.h index 849fd261..a2c09bef 100644 --- a/src/nntp/NntpArticle.h +++ b/src/nntp/NntpArticle.h @@ -53,6 +53,7 @@ class NntpArticle : public QObject const qint64 _filePos; //!< position in the File (for yEnc header) const qint64 _fileBytes; //!< bytes of the original file that are encoded + const bool _obfuscateArticles; ushort _nbTrySending; @@ -138,4 +139,4 @@ void NntpArticle::overwriteMsgId(const QString &serverMsgID){ _msgId = serverMsg ushort NntpArticle::nbMaxTrySending() { return sNbMaxTrySending; } void NntpArticle::setNbMaxRetry(ushort nbMax) { sNbMaxTrySending = nbMax; } -#endif // NntpArticle_H +#endif // NntpArticle_H \ No newline at end of file