Back to Blog
Vulnerability Research May 13, 2026 61 views

Analysis of CVE-2021-40444, MSHTML Remote Code Execution

Binary diffing analysis of the MSHTML Remote Code Execution vulnerability CVE-2021-40444 that weaponized Microsoft Word as an attack vector, examining patched DLLs, the exploit chain, and dual-layer protection introduced by Microsoft.

By Shayan Ahmed Khan, Security Researcher, Cytomate

In the month of September 2021, a famous 0-day vulnerability has been reported in many blogs and forums, it was CVE-2021-40444 MSHTML Remote code execution vulnerability and its attack cycle included Microsoft Word as a victim process that initiates the attack. The information on the internet concerning 0-day exploits is always so vague therefore I decided to play with this CVE. On 14th September 2021, Microsoft released a patch for this CVE. Since I am using Windows 10 version 20H2 for x64-based systems, so I downloaded the relevant version of Microsoft update having the code KB5005565 and an immediate previous version with the code KB5005101. Both these updates can be found on the Microsoft Update Catalog.

CVE-2021-40444 Overview

I installed the latest patch updates and found that two files have been modified in Windows System that look suspicious, I extracted files mshtml.dll and urlmon.dll. After that I installed an immediate previous version of that update and extracted the same files. Used IDA Pro to disassemble these binaries and calculated the Binary difference using BinDiff plugin and started looking at all the matched and unmatched functions to find out exactly what the patch was.

In mshtml.dll binary diffing, I found few functions with lower similarity. I quickly suspected the ShellExecURL(IURi *) function because in CVE-2021-40444, MS Word is actually rendering an HTML webpage using mshtml.dll and this function looks relevant.

BinDiff function list showing ShellExecURL

Looked up at the control flow graph of this function and found there are some extra conditional jumps added in the patched binary of mshtml.dll.

Control flow graph of ShellExecURL in patched mshtml.dll

I decompiled the code to understand what the patch is. It looks like Microsoft had added two new functions mainly GetSchemeName and IsValidSchemeName. It checks if a scheme is valid or not using conditions like checking if the URI scheme starts with a non-alphabet and non-ASCII character, for example a ".". If it starts with a dot or some other non-alphabet and non-ASCII character, then the scheme is invalid. Furthermore, the patch also checks if it contains any non-ASCII, non-alphabet, or non-digit character in the rest of the URI string and invalidates if such a character exists.

So, I tested the decompiled code in my Visual Studio environment and dry-ran the malware sample URI, which is invalidated due to numerous reasons. The first character of that URI is a "." which invalidates the scheme, but let's assume the attackers used control.exe instead of .cpl, which bypassed this limitation because now the first character is alphabetic and ASCII. But still this URI is invalidated because in the later conditions, the patch checks all characters from the URI one by one, restricting the use of characters, meaning "." is still present in the URI, so the condition breaks us out of the loop and the scheme is invalidated again.

Decompiled GetSchemeName validation logic
IsValidSchemeName character check loop

Now in the binary diff of urlmon.dll, I found another interesting thing. There was only a single function that had changes in it called CatDirAndFile. Every other function is 100% similar in this binary. I viewed the control flow graph and found many different conditional jumps in the assembly.

BinDiff result for urlmon.dll showing CatDirAndFile
Control flow graph of CatDirAndFile in patched urlmon.dll

We can see in the assembly of this function that there are many conditional jumps in the CFG. That means I found an accurate patch. Now I need to understand what has been changed here. I decompiled the code in IDA Pro to get a better understanding. I found that an extra do-while loop has been added in the patch which simply replaces a forward slash "/" with a backward slash "\" in the path.

Decompiled CatDirAndFile patch, slash replacement loop

How did this simple conversion of forward slash to backward slash patch a 0-day vulnerability? To understand this, I looked at the original malware sample and PoCs of CVE-2021-40444. In the original sample, an HTML file is rendered through Microsoft Word which loads a JavaScript that downloads a temporary .cab file on the system using urlmon.dll. The .cab file extracts a .inf extension file which contains the attacker's arbitrary code in a fixed path (/AppData/Local/Temp/). This extracted .inf file is then executed by mshtml.dll using the .cpl scheme as shown in the original sample JavaScript file.

Original malware JavaScript showing .cab download and .cpl execution

What Microsoft patched is the directory traversal vulnerability: using ../ an attacker can traverse to the parent directory, allowing urlmon.dll to extract the .inf file to the specified path. Now, if the forward slash is converted to a backward slash, directory traversal is not possible and no file will be extracted to the specified folder for execution via ShellExecURL(IURi *) in mshtml.dll.

Moreover, there is a second layer of security added in the mshtml.dll patch: it invalidates any URI that contains a "." in it, meaning that a file with a dot-prefixed scheme like .cpl or a dot-containing filename like .inf cannot be executed by ShellExecURL(IURi *).

Summary

Microsoft had a 0-day vulnerability weaponized into an attack using Microsoft Word. When the document is opened by the victim, the ActiveX object in the document refers to an HTML webpage. When mshtml.dll renders the HTML webpage, it contains JavaScript that downloads a temporary .cab file using urlmon.dll. urlmon.dll then extracts the .cab file into a fixed path by traversing parent directories. The extracted file is a driver file (.inf) containing malicious code. mshtml.dll then executes the .inf file using ShellExecURL via .cpl.

Due to patching the directory traversal vulnerability, attackers can no longer extract files to arbitrary locations using ../ relative paths, so no malicious code executes if no file is extracted. Even if an attacker somehow bypassed this limitation, Microsoft added a second layer: any URI containing a "." is invalidated, preventing any dotted file extension from being executed.

Note: While diffing some patched systems I found that even though patch updates had been installed, the urlmon.dll file had not been updated and the loophole still exists. This is an unlikely condition but does happen sometimes. It is therefore important to verify that the patch is genuinely installed on a system and not just reported as installed.

Originally published on cytomate.net

More from the Blog

Threat Intelligence Nov 29, 2026

The Build-Pipeline Backdoor: Inside the NullReceiver Supply-Chain Campaign

Read More
Deception Nov 29, 2026

Lying to the Machines: The Secret Weapon Against AI Attacks

Read More
Agentic Security Nov 24, 2026

Your AI Coding Agents Need an EDR Too: Introducing cADRe

Read More