Universal Code Execution by Chaining Messages in Browser Extensions
Browser extensions with wildcard content scripts and insecure postMessage handlers allow any website to send messages that are forwarded to native applications, which may handle them dangerously. This can lead to code execution on the victim's machine, as demonstrated by a smart card extension that loads a DLL from a user-controlled path.
Published on spaceraccoon.dev
By chaining various messaging APIs in browsers and browser extensions, I demonstrate how we can jump from web pages to “universal code execution”, breaking both Same Origin Policy and the browser sandbox. I provide two new vulnerability disclosures affecting millions of users as examples.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the content script's postMessage handler does not validate the origin of messages, and the background script forwards messages to a native application that unsafely uses user-supplied input to load a library.
Impact
An attacker could achieve full command execution on the victim's machine, but only if the victim has installed the extension and the matching native application.
What the attacker needed
Victim has the extension installed; victim has the native application installed; victim visits a malicious webpage
How it was found
- Victim visits a malicious webpage while the extension is installed.
- The page triggers a download of a malicious DLL file to the victim's Downloads folder.
- The page sends a postMessage with action GetCertLib and PKCS11Lib pointing to the downloaded file.
- The content script forwards the message to the background script.
- The background script passes the message to the native application.
- The native application loads the DLL from the specified path, resulting in code execution.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
Browser extensions often have a part that runs on every webpage (content script) and a part that runs in the background. If the content script accepts messages from any webpage without checking where they come from, a malicious site can send instructions that the background script passes to a native program on your computer. That native program might then do something dangerous like load a file from a location the attacker controls, leading to code execution.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.