Saving web page embedding file: resources allows accessing SMB resources
When saving a web page, Firefox accessed embedded file: resources pointing to SMB shares, even though such resources are blocked during normal viewing over HTTP/HTTPS. An attacker could host a malicious page that, when saved, causes the victim's Windows credentials (username and NTLM hash) to be sent to an attacker-controlled SMB server.
Originally disclosed on Mozilla
- Fixed in 8 months
- Paid in 8 months
- Disclosed after 8 months
Created attachment 8960284
poc.zip
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:59.0) Gecko/20100101 Firefox/59.0
Build ID: 20180315233128
Steps to reproduce:
Loading a file: resource is blocked when viewing pages over HTTP/HTTPS. However, when saving the page, any embedded file: resources are accessed. This may expose the user to SMB Relay Attacks, allowing to steal Windows user credentials.
Steps to reproduce:
Some definitions:
Victim pc: the "victim's pc".
HTTP server: a remote machine running a webserver.
SMB server: a remote machine hosting "smbtrap", a Python-based SMB server that steals Windows user credentials.
1. HTTP server: From the attached ZIP, upload poc.html to this machine, so it can be accessed through e.g.
http://192.168.1.128/poc.html
2. SMB server: Make sure to use Python 2.7.x. Also, install the Tornado 4.4.2 package, e.g. through "pip":
sudo pip install tornado==4.4.2
3. SMB server: Make sure the host machine has the IP address 192.168.1.128 (or change the hardcoded address in poc.html).
4. SMB server: Download "smbtrap2.py" and "quickcrack.py" from
https://github.com/CylanceSPEAR/SMBTrap/tree/master/smbtrap
and run SMBtrap through
sudo python smbtrap2.py
5. Victim pc: Open Firefox, and navigate to
http://192.168.1.128/poc.html
6. Victim pc: Save the web page to disk (File > Save Page As)
7. Victim pc: Observe that SMBtrap receives the user's username and NTLM password hash.
See also attached screenshot "smbtrap_output.png" (in the ZIP) for example output.
Note: quickcrack.py contains a small "dictionary" for demonstration purposes. If the victim's password is one of those listed, SMBtrap will be able to derive the actual password from the NTLM hash.
Actual results:
Firefox accesses the file: resource, which is a path to an SMB resource. This may expose the user to SMB Relay attacks.
Expected results:
Firefox should not have accessed the file: resource when the web page is served over HTTP/HTTPS.
What the report shows
The target is Firefox's handling of file: resources embedded in a web page. The researcher, Björn Ruytenberg, reported that Firefox blocks a file: resource while a page is being viewed over HTTP or HTTPS, but that the same resource is fetched when the user saves the page to disk. The asset is listed as Core: DOM: Core & HTML, the weakness as information disclosure, and the severity as medium. The report does not describe a fix or a bounty.
The proof of concept uses three machines: the victim's PC, an HTTP server serving the page, and an SMB server running SMBTrap, a Python-based SMB server that captures Windows credentials. The page is uploaded to the HTTP server and reached at a private address, and the SMB server is configured to answer on that same address. The report notes that the hardcoded address in poc.html must be changed if the host does not use it.
The SMB server setup requires Python 2.7.x and the Tornado 4.4.2 package:
sudo pip install tornado==4.4.2
The two scripts are taken from the SMBTrap repository and started with:
sudo python smbtrap2.py
The reproduction steps are:
- Upload
poc.htmlfrom the attached ZIP to the HTTP server so it is reachable at a URL such ashttp://[redacted]/poc.html. - Install Tornado 4.4.2 on the SMB server and make sure the host uses the address hardcoded in the page.
- Download
smbtrap2.pyandquickcrack.pyfrom the SMBTrap repository and run SMBTrap. - On the victim PC, open Firefox and navigate to the page.
- On the victim PC, save the page with File > Save Page As.
- Observe that SMBTrap receives the user's username and NTLM password hash.
The report refers to a screenshot, smbtrap_output.png, inside the ZIP as an example of the captured output. It also notes that quickcrack.py contains a small dictionary for demonstration: if the victim's password is in that list, SMBTrap can derive the actual password from the NTLM hash.
The actual result is that Firefox accesses the file: resource, which is a path to an SMB resource. The expected result is that Firefox should not access the file: resource when the page is served over HTTP or HTTPS.
Root cause
The report records the observed difference in behaviour: a file: resource is blocked while the page is viewed over HTTP or HTTPS, but is accessed when the page is saved. It does not identify the code responsible.
Impact
Because the fetched file: path can point at an SMB share, the victim's machine authenticates to the attacker's SMB server while saving the page. The report states that this may expose the user to SMB relay attacks, and that SMBTrap receives the user's username and NTLM password hash. The report notes that if the victim's password is one of those listed in the dictionary, SMBTrap will be able to derive the actual password from the NTLM hash. The report hedges with "may", and the outcome depends on the victim saving the page.
How this kind of bug works
Browsers enforce a boundary between remote origins and the local file system: a document loaded over HTTP or HTTPS should not be able to read file: URLs, because doing so would let any web page probe the user's disk. The same boundary has to hold in every feature that touches subresources, not only in the renderer. Saving a page is one such feature: it enumerates the document's subresources and fetches them so they can be written to disk. If that enumeration runs without the origin check, a remote page can name a file: URL as an image, stylesheet or similar subresource and have the browser fetch it on the user's behalf.
On Windows, a file: URL can resolve to a UNC path, so the fetch becomes an outbound SMB connection. Windows automatically presents the logged-in user's credentials to the SMB server during authentication, and the server receives the username and an NTLM challenge-response. That response can be relayed to another service that accepts NTLM, or cracked offline. The defences are the origin check on every subresource fetch, including save and print paths, and network-side controls that stop workstations from authenticating to untrusted SMB hosts.
How to test for it
- Identify features that fetch subresources outside normal rendering: save page, print to file, reader mode, page archiving, thumbnail generation, and any export or download flow.
- Build a page served over HTTP or HTTPS whose subresources point at
file:URLs, including UNC-style paths on Windows, and confirm that normal rendering blocks them. - Trigger the alternate feature and watch for outbound connections. A listener on the target host, or a capture on the network, shows whether the browser resolved the path.
- A positive result is an outbound SMB or file access that occurs only through the alternate feature, with the request carrying the user's credentials or reading a local file.
- Common false positives: the resource was already cached from a local page, the test page was itself opened from disk rather than over HTTP, or the browser prompted the user before accessing the path. Repeat with a clean profile and a page served remotely to rule these out.
How it is fixed
Hunting notes
This class of bug hides in secondary code paths that reuse the document's resource list: saving, printing, archiving, previews and exports. Recon signals include features that serialise a page or its resources, and any place where a remote document's subresources are handled by code that also serves local content. To make a report land, show the blocked behaviour during normal rendering next to the successful fetch through the alternate path, capture the outbound connection with the credential material it carries, and keep the proof of concept minimal so the difference between the two paths is unambiguous.
What happened, in plain words
Firefox is a web browser. When you open a web page, the browser downloads not just the page itself but also the things the page is made of: images, stylesheets, scripts. These extra pieces are called subresources. A web page can also point at things stored on your own computer, using a special kind of address that starts with file:. For example, file:///C:/Users/me/photo.png means "a file on this machine".
Browsers deliberately keep a wall between web pages and your local files. A page that came from the internet over HTTP or HTTPS should not be able to make the browser read files from your disk, because otherwise any website could quietly look around your computer. Firefox enforces this wall while it is displaying a page: a file: resource embedded in a page served over HTTP or HTTPS is blocked.
The researcher, Björn Ruytenberg, found that the wall has a gap. When you save a web page to disk with File > Save Page As, Firefox collects the page's subresources so it can write them next to the saved page. In that saving step, the file: resource was not blocked, and Firefox fetched it. The report lists the affected area as Core: DOM: Core & HTML, the weakness as information disclosure, and the severity as medium. It does not describe a fix or a bounty.
Why does fetching a local file matter? On Windows, a file: address can point not only at a disk but at a shared folder on the network, using a protocol called SMB (Server Message Block), the way Windows machines share files. When a Windows computer connects to an SMB share, it proves who it is by sending the logged-in user's username and a scrambled form of the password, called an NTLM hash. If an attacker controls the machine on the other end, they receive those credentials. This is the basis of an SMB relay attack: the attacker passes the captured proof on to another service that trusts it, or tries to unscramble the hash offline to recover the real password.
How the researcher demonstrated it
The proof of concept uses three machines: the victim's PC, an HTTP server that hosts the malicious page, and an SMB server running a tool called SMBTrap, a Python-based SMB server that captures Windows credentials. The page is uploaded to the HTTP server and reached at a private address, and the SMB server is set up to answer on that same address. The report notes that the address hardcoded in poc.html must be changed if the host does not use it.
The SMB server needs Python 2.7.x and the Tornado 4.4.2 package, installed with:
sudo pip install tornado==4.4.2
pip is Python's package installer, and this line downloads and installs the exact version of Tornado the tool expects. The two scripts are taken from the SMBTrap repository and started with:
sudo python smbtrap2.py
sudo runs the command with administrator rights, and python smbtrap2.py starts the credential-capturing server.
The reproduction steps are:
- Upload
poc.htmlfrom the attached ZIP to the HTTP server so it is reachable at a URL such ashttp://[redacted]/poc.html. - Install Tornado 4.4.2 on the SMB server and make sure the host uses the address hardcoded in the page.
- Download
smbtrap2.pyandquickcrack.pyfrom the SMBTrap repository and run SMBTrap. - On the victim PC, open Firefox and navigate to the page.
- On the victim PC, save the page with File > Save Page As.
- Observe that SMBTrap receives the user's username and NTLM password hash.
Step 4 alone does not trigger the fetch: while the page is viewed over HTTP or HTTPS, the file: resource is blocked. Step 5 is the trigger: saving the page causes the file: resource to be accessed. Step 6 is the proof: the attacker's server has received the victim's username and NTLM password hash after the victim saved the page.
The report refers to a screenshot, smbtrap_output.png, inside the ZIP as an example of the captured output. It also notes that quickcrack.py contains a small dictionary for demonstration: if the victim's password is in that list, SMBTrap can derive the actual password from the NTLM hash.
The actual result is that Firefox accesses the file: resource, which is a path to an SMB resource. The expected result is that Firefox should not access the file: resource when the page is served over HTTP or HTTPS.
Why it happens
The report records the observed difference: a file: resource is blocked while the page is viewed over HTTP or HTTPS, but is accessed when the page is saved. It does not identify the code responsible.
In general, how this kind of bug works
Browsers enforce a boundary between remote origins and the local file system: a document loaded over HTTP or HTTPS should not be able to read file: URLs, because doing so would let any web page probe the user's disk. The same boundary has to hold in every feature that touches subresources, not only in the renderer. Saving a page is one such feature: it enumerates the document's subresources and fetches them so they can be written to disk. If that enumeration runs without the origin check, a remote page can name a file: URL as an image, stylesheet or similar subresource and have the browser fetch it on the user's behalf.
On Windows, a file: URL can resolve to a UNC path, so the fetch becomes an outbound SMB connection. Windows automatically presents the logged-in user's credentials to the SMB server during authentication, and the server receives the username and an NTLM challenge-response. That response can be relayed to another service that accepts NTLM, or cracked offline. The defences are the origin check on every subresource fetch, including save and print paths, and network-side controls that stop workstations from authenticating to untrusted SMB hosts.
In general, how to test for it
- Identify features that fetch subresources outside normal rendering: save page, print to file, reader mode, page archiving, thumbnail generation, and any export or download flow.
- Build a page served over HTTP or HTTPS whose subresources point at
file:URLs, including UNC-style paths on Windows, and confirm that normal rendering blocks them. - Trigger the alternate feature and watch for outbound connections. A listener on the target host, or a capture on the network, shows whether the browser resolved the path.
- A positive result is an outbound SMB or file access that occurs only through the alternate feature, with the request carrying the user's credentials or reading a local file.
- Common false positives: the resource was already cached from a local page, the test page was itself opened from disk rather than over HTTP, or the browser prompted the user before accessing the path. Repeat with a clean profile and a page served remotely to rule these out.
In general, how it is fixed
In general, where to look for it
This class of bug hides in secondary code paths that reuse the document's resource list: saving, printing, archiving, previews and exports. Recon signals include features that serialise a page or its resources, and any place where a remote document's subresources are handled by code that also serves local content. To make a report land, show the blocked behaviour during normal rendering next to the successful fetch through the alternate path, capture the outbound connection with the credential material it carries, and keep the proof of concept minimal so the difference between the two paths is unambiguous.
Glossary
- Subresource: an image, stylesheet, script or other file that a web page loads in addition to the page itself.
file:URL: an address that points at a file on the local computer or a network share, rather than at a website.- HTTP/HTTPS: the protocols browsers use to fetch web pages from servers over the network.
- Origin: the combination of scheme, host and port that identifies where a page came from; browsers use it to decide what a page may access.
- Renderer: the part of the browser that draws a page and loads its subresources.
- Serialise: to turn a page and its resources into a form that can be written to disk, as happens when saving.
- SMB: Server Message Block, the Windows protocol for sharing files and folders over a network.
- UNC path: a Windows network path such as
\\server\sharethat points at a shared folder on another machine. - NTLM hash: a scrambled form of a Windows password that the computer sends to prove its identity during authentication.
- SMB relay attack: capturing a victim's authentication attempt and passing it on to another service that accepts it, or cracking it offline.
- SMBTrap: a Python-based SMB server used in the report to capture Windows credentials.
- Tornado: a Python package the SMBTrap tool depends on.
pip: Python's package installer.sudo: a command that runs another command with administrator rights.- Proof of concept (PoC): a minimal setup that demonstrates a bug really works.
- Information disclosure: a weakness where data that should stay private is exposed to someone who should not see it.
- False positive: a test result that looks like a bug but is caused by something else.