mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-10 23:42:46 -07:00
Add support for Mark-of-the-Web
https://redcanary.com/threat-detection-report/techniques/mark-of-the-web-bypass/ https://mikehadlow.blogspot.com/2011/07/detecting-and-changing-files-internet.html https://textslashplain.com/2016/04/04/downloads-and-the-mark-of-the-web/ Closes #19648. PR #19675.
This commit is contained in:
parent
c051ee9409
commit
34f7b75f12
4 changed files with 56 additions and 2 deletions
|
@ -602,6 +602,27 @@ QString Utils::Misc::zlibVersionString()
|
|||
}
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
bool Utils::Misc::applyMarkOfTheWeb(const Path &file, const QString &url)
|
||||
{
|
||||
const QString zoneIDStream = file.toString() + u":Zone.Identifier";
|
||||
HANDLE handle = ::CreateFileW(zoneIDStream.toStdWString().c_str(), GENERIC_WRITE
|
||||
, (FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE)
|
||||
, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
if (handle == INVALID_HANDLE_VALUE)
|
||||
return false;
|
||||
|
||||
// 5.6.1 Zone.Identifier Stream Name
|
||||
// https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fscc/6e3f7352-d11c-4d76-8c39-2516a9df36e8
|
||||
const QByteArray zoneID = QByteArrayLiteral("[ZoneTransfer]\r\nZoneId=3\r\n")
|
||||
+ (!url.isEmpty() ? u"HostUrl=%1\r\n"_s.arg(url).toUtf8() : QByteArray());
|
||||
|
||||
DWORD written = 0;
|
||||
const BOOL writeResult = ::WriteFile(handle, zoneID.constData(), zoneID.size(), &written, nullptr);
|
||||
::CloseHandle(handle);
|
||||
|
||||
return writeResult && (written == zoneID.size());
|
||||
}
|
||||
|
||||
Path Utils::Misc::windowsSystemPath()
|
||||
{
|
||||
static const Path path = []() -> Path
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue