Last update: June 21, 2022
Windows uses a simple technique to keep track of which binary files were downloaded from the Internet (or a network share).
Each downloaded file is is tagged with a hidden NTFS Alternate Data Stream file named Zone.Identifier. You can check for the presence of this “Mark of the Web” (MotW) using dir /r or programmatically, and you can view the contents of the MotW stream using Notepad:
Within the file, the
ZoneTransfer element contains a
ZoneId element with the ordinal value of the URLMon Zone from which the file came1. The value
3 indicates that the file is from the Internet Zone2.
Aside: One common question is “Why does the file contain a Zone Id rather than the original URL? There’s a lot of cool things that we could do if a URL was preserved!” The answer is mostly related to privacy—storing a URL within a hidden data stream is a foot gun that would likely lead to accidental disclosure of private URLs. This problem isn’t just theoretical—the Alternate Data Stream is only one mechanism used for MotW. Another mechanism involves writing a
<!--saved from url=http://example.com> comment to HTML markup; that form does include a raw URL. A few years ago, attackers noticed that they could use Google to search for files containing a MOTW of the form
<!--saved from url(0042)ftp://username:firstname.lastname@example.org –> and collect credentials. Oops. Update: Microsoft apparently decided the tradeoff was worth it. Windows 10+ includes the referrer URL, source URL and other information.
Browsers and other internet clients (e.g. email and chat programs) can participate in the MOTW-marking system by using the IAttachmentExecute interface’s methods or by writing the Alternate Data Stream directly. Chrome uses
IAttachmentExecute and thus includes the URL information on Windows 10. Firefox writes the Alternate Data Stream directly (and as of February 2021, it too includes the URL information).
Handling Marked Files
Windows and some applications treat files with a Mark-of-the-Web differently than those without. For instance, examining a downloaded executable file’s properties shows the following notice:
More importantly, attempting to run the executable using Windows Explorer or ShellExecute() will first trigger evaluation using SmartScreen Application Reputation (Win8+) and any installed anti-virus scanners. The file’s digital signature will be checked, and execution will be confirmed with the user, either using the older Attachment Execution Services prompt, or the newer UAC elevation prompt:
Microsoft Office documents bearing a MotW open in Protected View, a security sandbox that attempts to block many forms of malicious content, and starting in 2022, macros are disabled in Internet-sourced documents.
Trivia: Some applications inherit protections against files bearing a MotW, but don’t have any user-interface that explains what is going on. For instance, if you download a CHM with a MotW, its HTML content will not render until you unblock it using the “Always ask before opening this file” or the “Unblock” button:
What Could Go Wrong?
With such a simple scheme, what could go wrong? Unfortunately, quite a lot.
Internet Clients Must Participate
The first hurdle is that Internet clients must explicitly mark their downloads using the Mark-of-the-Web, either by calling
IAttachmentExecute or by writing the Alternate Data Stream directly. Most popular clients will do so, but support is neither universal nor comprehensive.
For instance, for a few years, Firefox failed to mark downloads if the user used the Open command instead of Save.
In other cases, some browser plugins may allow attackers to save files to disk and bypass MotW tagging.
Microsoft Outlook (tested v2010) and Microsoft Windows Live Mail Desktop (tested v2012 16.4.3563.0918) both tag message attachments with a MotW you double-click on an attachment or right-click and choose Save As. Unfortunately, however, both clients fail to tag attachments if the user uses drag-and-drop to copy the attachment to somewhere in their filesystem. This oversight is likely to be seen in many different clients, owing to the complexity in determining the drop destination.
Target File System Must Be NTFS
The Zone.Identifier stream can only be saved in an NTFS stream. These streams are not available on FAT32-formatted devices (e.g. some USB Flash drives), CD/DVDs, or the new ReFS file system introduced with Windows Server 2012.
If you copy a file tagged with a MotW to a non-NTFS filesystem (or try to save it to such a file system to start with), the Mark of the Web is omitted and the protection is lost.
Originating Location Must Be Internet or Restricted Zone
The IAttachmentExecute:Save API will not write the MotW unless the URL provided in the SetSource method is in a zone configured to write it (e.g. Trusted, Internet or Restricted Sites zone).
On some systems, code may have added domains to the user’s Trusted Sites zone without their knowledge.
On other systems, a proxy configuration script may cause Internet sites to be treated as belonging to the Intranet zone.
The Attachment Execution Services API also will not write a MoTW to a download if that Zone’s setting for
Launching applications and unsafe files is set to
Normally, Windows will howl if this unsafe configuration is set for the Internet Zone, but there’s a registry key that turns off the “Your security settings are unsafe” warning bar:
Not Disabled by Policy
Writing of the MoTW can be suppressed in the AttachmentExecuteServices API via Group Policy. In
GPEdit.msc, see Administrative Templates > Windows Components > Attachment Manager >
Do not preserve zone information in file attachments
A value of
1 will prevent the MoTW from being written to files.
Source scheme must be HTTP/HTTPS/FILE/FTP-like
If the source of the download is a
data URI, the browser has no great way to know what marking to put on the file.
blob URIs have a similar issue, but because blob URIs only exist within a security context (
https://example can create
blob:https://example/guid) you can write that security context’s URL as the MoTW to ensure proper handling.
For data URIs or other anonymous sources, writing a default of
about:internet is a common conservative choice to ensure that the file was treated as if it came from the Internet Zone. Similarly,
about:untrusted causes the file to be treated as originating from the Restricted Sites Zone.
Origin Laundering via Archives
One simple trick that attackers use to try to circumvent MotW protections is to enclose their data within an archive like a
.RAR file, or a virtual disk like a
.iso file. Attackers may go further and add a password to block virus scanners; the password is provided to the victim in the attacking webpage or email.
In order to remain secure, archive extractors must correctly propagate the MotW from the archive file itself to each file extracted from the archive.
Despite being one of the worst ZIP clients available, Windows Explorer gets this right:
In contrast, 7-zip does not reliably get this right. Malware within a 7-zip archive can be extracted without propagation of the MotW. 7-zip v15.14 will add a MotW if you double-click an exe within an archive, but not if you extract it first. The older 7-zip v9.2 did not tag with MotW either way.
A quick look at popular archive extractors shows:
- Windows Explorer – Not vulnerable
- WinRar 5.31 – Not vulnerable
- WinZip 20.0.11649 – Not vulnerable
- 7-Zip 15.14 – Vulnerable (bug); 7-Zip 22.0 – Optional
- IZArc 4.2 – Vulnerable (Developer says: “Will be fixed in next version“)
Update: A researcher has surveyed the current MoTW-propagation landscape as of May 2022.
SmartScreen & the User May Unmark
Finally, users may unmark files using the Unblock button on the file’s Properties dialog in Windows Explorer, or by unticking the “Always ask before opening this file” checkbox on the pre-launch security prompt.
Similarly, on systems with Microsoft SmartScreen, SmartScreen itself may unmark the file (actually, it replaces the
ZoneId with an (undocumented) field of AppZoneId=4) Update March 2022: SmartScreen now seems to have changed to write a separate
SmartScreen alternate stream, rather than modifying the
Mark-of-the-Web is valuable, but fragile.
1 This is an oversimplification. The
ZoneId value written is the least-privileged zone of the calculated zones for the caller-supplied Source URL and the Referrer URL. Interestingly, this means that if you download a Trusted Zone file from a link on an Internet Zone webpage, it will be treated as if it had originated from the Internet Zone.
There are other (surprising) nuances as well.
First, if either the Source or Referrer is not supplied, it is treated as “Local Machine Zone”; a caller can pass
about:internet as a generic “Internet Zone” URL, or
about:untrusted as a generic “Restricted Sites” URL. Using a generic URL can be necessary if the file is sourced from a non-basic URL like
blob: or one that is over 2083 characters (
Second, the determination of what zone is “least-privileged” diverges from the standard order for Windows Security Zones. The MoTW code orders the Zones as
Local Machine <
Trusted. The standard ordering in URLMon is
Third, the Zone Marking code is hard-coded to avoid writing a MoTW to a file whose “least-privileged” zone is
Local Machine. This seems reasonable (otherwise copying a file from the local computer to the local computer could add a MoTW), but, coupled with the non-standard ordering of Zones, results in a surprising outcome. To wit, if you call the API with a Source URL in the Trusted Zone, but do not supply a Referrer URL (say, because the user entered the URL in the address bar, or the download link has a
rel=noreferrer attribute), no MoTW is written to the file (test case).
2 The Windows Zone identifier constants are
Local Machine Zone is
0, but the API will not write a
Zone.Identifier stream for a file whose