Skip to content
Memory corruption Write-up Advanced

Exploiting The Sonos One Speaker Three Different Ways: A Pwn2Own Toronto Highlight

The Sonos One speaker contained multiple vulnerabilities in its SMB and MPEG-TS handling, including an out-of-bounds read in libsmb2, a use-after-free in libsmb2, and a stack buffer overflow in the MPEG-TS parser. Attackers on the same network could exploit these to leak memory addresses and achieve remote code execution.

thezdi Follow

Published on zerodayinitiative.com

Bounty$105,000total stated by author View original

During Pwn2Own Toronto 2022, three different teams successfully exploited the Sonos One Speaker. In total, $105,000 was awarded to the three teams, with the team of Toan Pham and Tri Dang from Qrious Secure winning $60,000 since their entry was first on the schedule.

The ZDI Research Team (@thezdi), on zerodayinitiative.com

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.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 14 min read.

Context

This write-up covers the Sonos One Speaker as targeted during Pwn2Own Toronto 2022. Three different teams successfully exploited the device, and the ZDI Research Team summarises the four unique bugs they used. The total awarded across the three teams was $105,000. The team of Toan Pham and Tri Dang from Qrious Secure won $60,000 because their entry was first on the schedule.

The report explains that part of Pwn2Own involves a random drawing for order. The team selected first gets the full award if successful, and subsequent entries are more likely to suffer bug collisions: if three teams show up with the same exploit, only the first randomly selected one gets full credit. In this event some collisions did occur, but the three teams still used four unique bugs between them.

The relevant software on the speaker is the anacapad daemon, which handles all Sonos-specific functions including accessing music services, LED control and audio playback. Sonos also incorporates the open-source libsmb2 library, with a few modifications, to provide SMB functionality. That library runs within anacapad and can be reached by unauthenticated users to play music via an SMB shared directory. A second relevant surface is the /msprox endpoint, which acts as a proxy for Sonos Speaker array communication and forwards user-supplied SOAP requests to other registered speakers.

Setup

The report does not describe a lab setup, tooling versions or account requirements in detail. What it does state about preconditions is:

  1. The libsmb2 code path can be reached by unauthenticated users to play music via the SMB shared directory.
  2. The /msprox endpoint forwards user-supplied SOAP requests to other registered speakers.
  3. For the libsmb2 info leak, the attacker acts as an SMB server and sends a malformed PDU query directory response to the client.
  4. For the DEVCORE variant of the /msprox bug, the attacker acts like a rogue Sonos Speaker adjacent on the network to the target.
  5. The STAR Labs exploit uses a modified impacket to implement a malicious SMB server.
  6. Sonos enables exploit mitigations, so an information leak is needed before code execution.

The report does not give firmware versions, library versions beyond the binary names it cites (anacapad, libsmb2.so.1), or the exact Pwn2Own contest rules beyond the random draw.

Finding it

The report frames the findings as contest entries rather than as a single researcher's discovery narrative. The bugs are presented by CVE and by which team used them:

CVE Bug Used by
CVE-2023-27354 libsmb2 info leak Qrious Secure only
CVE-2023-27353 (also referenced as CVE-2023-27533/ZDI-23-448) /msprox out-of-bounds read info leak STAR Labs and DEVCORE
CVE-2023-27352 libsmb2 use-after-free leading to RCE Qrious Secure and STAR Labs
CVE-2023-27355 MPEG-TS parser stack buffer overflow leading to RCE DEVCORE only

The report notes that the /msprox bug is referenced in the text as CVE-2023-27533/ZDI-23-448, while the section heading calls it CVE-2023-27353. Both labels appear in the original and are reproduced here as written.

Exploitation

Step 1: CVE-2023-27354, the libsmb2 info leak (Qrious Secure)

Qrious Secure was randomly selected to go first and used a two-bug chain. The first bug was this info leak, and they were the only team to use it during the contest.

The vulnerability is in the way anacapad handles SMBv2 replies from a server, specifically in [redacted](), which processes query directory reply data. The function allocates an smb2_query_directory_reply struct and stores the result in the Protocol Data Unit (PDU) pdu->payload field. It then extracts the output buffer offset and length from the query directory reply sent by the server.

The speaker checks that the output buffer does not overlap with the query directory reply header. The offset is later used to calculate the IOV_OFFSET, and is also used at another point in the code. The output_buffer is later used to decode file information from the directory PDU response in [redacted].

The flaw: the code never checks whether the offset is within the len of a PDU packet. By acting as an SMB server and sending a malformed PDU query directory response with a large offset, the client decodes file information from an out-of-bounds (OOB) memory region and sends that information back to the malicious SMB server as part of a filename. By manipulating the offset, the SMB server can determine libc and heap addresses on the client, which are useful for the next step of the exploit chain.

The report describes the logic and references the relevant code.

Step 2: CVE-2023-27353, the /msprox info leak (STAR Labs and DEVCORE)

Two teams used this bug to kick off their exploit. It resides in the /msprox endpoint. A request to this endpoint is handled by function sub_15DFA0(), which calls sub_1C86C0(). The report shows a code snippet from sub_1C86C0 in the anacapad binary, corresponding to assembly code from address 0x1C876C. The report shows a snippet from sub_1C86C0 that fails to check the return value of snprintf() at [1], and later uses that value as the size of an outgoing HTTP header buffer at [2].

STAR Labs sent a crafted request that provides overly long parameters to the snprintf() call at [1]. The return value from snprintf() (request_len) then exceeds the size of the request buffer, which is 0x1000 bytes. At [2], the code calls ana_server_send_request() to send the contents of the request buffer using request_len as the length. STAR Labs used this out-of-bounds read (OOBR) to leak the address of the .text segment.

DEVCORE took a slightly different route to the same effect. Their exploit relied on acting like a rogue Sonos Speaker adjacent on the network to the target. This let them reach code containing an out-of-bounds read analogous to the one above, resulting in leakage of stack data right after the request_body buffer. The report cites address location 0x1C889C for this path.

Both teams arrived at the same vulnerable code and leaked the data needed to continue their exploit chains.

Step 3: CVE-2023-27352, libsmb2 use-after-free to RCE (Qrious Secure and STAR Labs)

Both Qrious Secure and STAR Labs leveraged a use-after-free (UAF) in libsmb2. Because Qrious Secure was randomly chosen to go first, they won the full $60,000, while the collision resulted in STAR Labs earning $22,500.

The report describes the libsmb2 implementation. smb2_closedir is implemented as shown in the original, and smb2_lazy_readdir is implemented as follows. The main function handling data returned from an SMB server is also shown. The report shows the source snippets and describes the control flow:

Text
(1) smb2_lazy_readdir -> smb2_fetchfiles_async -> smb2_cmd_query_directory_async -> create pdu (PDU) with internal message_id (MID) -> add to wait_queue (3)

When the client receives data from a server (4), it decodes the header (5) and finds the PDU via its message_id (6). smb2_fetchfiles_async() adds the PDU to wait_queue, which holds a callback to fetchfiles_cb() at (7). That callback keeps the dir structure within its private data (8). Before it finishes, it invokes the dir->cb callback at (9).

Back at (6): in a normal scenario the SMB server returns data with the valid message_id as MID, and the callback is triggered before dir is freed in close_dir at (2). If the server sends an invalid message_id (different from MID), the PDU is not found and stays alive in wait_queue, still holding the dir struct pointer. When (2) finishes, the dir pointer is freed and the PDU holds a dangling pointer.

The next time the client reads data from the server, if the server replies with a previously valid message_id of MID, the client decodes the data and finds the corresponding PDU via that MID. The PDU's callback fetchfiles_cb is called and at (4) accesses the dangling pointer. By reallocating the freed dir structure before fetchfiles_cb is called, the attacker can control the value cb and thereby gain control of $PC by pointing cb to maliciously crafted data. Combined with the memory address leak from CVE-2023-27354, this achieves remote code execution.

STAR Labs took a different approach to the same vulnerability. One of the functions added to libsmb2 is smb2_lazy_readdir(). Their trigger:

Text
-- `smb2_opendir()` is called, which will return an `smbdir` (`smb2dir` structure).         -- `smbdir` is later passed into `smb2_lazy_readdir()` together with a custom callback function.

smb2_cmd_query_directory_async() receives a callback function with a defined prototype and any user-defined structure (in this case smb2dir). It inserts a pdu (smb2_pdu) into a request queue waiting to be handled. After a reply is received, the callback is invoked with the received data. The Sonos device passes the smbdir structure as cb_data and populates it inside the callback. This snippet is in sub_109C0() of the libsmb2.so.1 binary, corresponding to assembly code from address 0x10A04.

If wait_for_reply fails, meaning smb2_cmd_query_directory_async did not receive any valid response for its pdu, smb2_closedir is invoked to free the smbdir object. Then smb2_disconnect_share is called. During this process a dangling pointer to smbdir is left in the request queue.

In smb2_disconnect_share, the call chain is wait_for_reply -> smb2_service -> smb2_service_fd -> smb2_read_from_socket -> smb2_read_data. In smb2_read_data, smb2_find_pdu retrieves the pdu based on the message_id of the response packet, which is controllable by the attacker. If the response specifies the message_id of the Query Directory pdu, smb2_find_pdu returns the smb2_cmd_query_directory_async pdu. When pdu->cb is invoked from z_query_directory_cb_109C0, the dangling pointer leads to $PC control.

Reclaiming the freed smb2dir object is done by appending extra data onto the response packet from the server; the client allocates a buffer to store this extra padding data. The exploit uses a modified impacket to implement a malicious SMB server.

The exploit proceeds as follows:

  1. Send a command to the target device to add a new SMB share.
  2. Using a modified smb2QueryDirectory() function in the exploit's impacket SMB server, return a malformed response to the client's smb2_cmd_query_directory request, producing a dangling pointer.
  3. When the client calls smb2_disconnect_share, it sends a disconnect tree request to the server. Using a modified smb2TreeDisconnect function in the impacket SMB server, the exploit returns a Query Directory response with the message_id from step 2. The exploit also appends data to this response to reclaim the smb2dir object in the client.
  4. The exploit gains control of $PC via the overwritten smb2dir->cb pointer and uses ROP to get a shell.

Step 4: CVE-2023-27355, MPEG-TS parser stack buffer overflow (DEVCORE)

This RCE bug was used only by DEVCORE. Due to the random draw this was the third attempt on the Sonos, which left them at a disadvantage as they were more likely to hit a bug collision. They did collide on their info leak, but the RCE portion of their chain was unique and earned its own CVE.

While parsing a .ts audio file, the speaker does not check the length of the Adaptation field, leading to a stack buffer overflow. The bug results from the ability to specify an arbitrary value to the afelen field. The speaker then reads the specified number of bytes into the payload buffer, smashing the stack. The report cites address 0x406604.

Because Sonos enables exploit mitigations, the attacker needs to leak information first. During the contest, the DEVCORE entry first leaked the stack canary, stack address and program base address using CVE-2023-27353. With those values, exploitation is straightforward: the MPEG-TS parser vulnerability is used to overwrite the return address and jump to the exec() wrapper. As the #x19 and #x22 registers are also controllable by the exploit, the attacker can set these registers to a controllable stack buffer and execute arbitrary commands.

The demonstration succeeded, but due to the collision on CVE-2023-27353 the DEVCORE team did not win the full amount. They earned $22,500 for being the third team to exploit the Sonos speaker.

Root cause

There are four distinct root causes in the report:

  1. CVE-2023-27354 (libsmb2 info leak). [redacted]() extracts the output buffer offset and length from the server's query directory reply and checks only that the output buffer does not overlap the reply header. It never checks whether the offset is within the len of the PDU packet. The offset is later used to calculate IOV_OFFSET and to decode file information in [redacted], so a large offset causes decoding from an OOB memory region.
  2. CVE-2023-27353 (/msprox info leak). The code in sub_1C86C0() fails to check the return value of snprintf(). That return value (request_len) is later used as the size of an outgoing HTTP header buffer passed to ana_server_send_request(), even though it can exceed the 0x1000-byte request buffer. The result is an out-of-bounds read that leaks adjacent memory (the .text segment for STAR Labs, stack data after request_body for DEVCORE).
  3. CVE-2023-27352 (libsmb2 UAF). When a server replies with an invalid message_id, the PDU is not found and remains in wait_queue holding a pointer to the dir structure. close_dir then frees dir, leaving a dangling pointer. A later reply with the original MID causes fetchfiles_cb to run against the freed structure, and the attacker can reclaim it and control cb, giving $PC control. The STAR Labs variant reaches the same dangling pointer through smb2_closedir and smb2_disconnect_share, with the message_id of the response packet controllable by the attacker.
  4. CVE-2023-27355 (MPEG-TS parser). The parser does not check the length of the Adaptation field. An arbitrary afelen value causes the speaker to read that many bytes into the payload buffer, overflowing the stack.

On defences: the report states that Sonos enables exploit mitigations, which is why the DEVCORE chain needed an info leak first. It does not enumerate the specific mitigations.

Impact

The report's stated outcomes:

  • CVE-2023-27354 gives an information leak: libc and heap addresses on the client, useful for the next step of the chain.
  • CVE-2023-27353 gives an information leak: the .text segment address (STAR Labs) or stack data after request_body (DEVCORE).
  • CVE-2023-27352, combined with the CVE-2023-27354 leak, achieves remote code execution.
  • CVE-2023-27355, combined with the CVE-2023-27353 leak, achieves remote code execution, with the attacker able to set #x19 and #x22 to a controllable stack buffer and execute arbitrary commands.

The libsmb2 functionality can be reached by unauthenticated users to play music via the SMB shared directory, per the report. The /msprox endpoint forwards user-supplied SOAP requests to other registered speakers, and DEVCORE's variant required the attacker to act like a rogue Sonos Speaker adjacent on the network to the target.

Fix

It states that many of the bugs disclosed during Pwn2Own Toronto are patched, and that the team will continue to disclose details on the blog. Based on the root causes, the fixes that would address them are: bounds-checking the output buffer offset against the PDU len in [redacted](); checking the snprintf() return value before using it as a send length in sub_1C86C0(); ensuring a PDU is removed from wait_queue (or its dir reference invalidated) when close_dir frees the structure; and validating the Adaptation field length against the payload buffer size in the MPEG-TS parser. The report does not confirm that any of these specific changes were made.

Variants to test

  1. Other SMB reply parsers in libsmb2. Look for functions that extract an offset and length from a server-controlled reply and use them to index into a PDU payload without checking the offset against the PDU length. A positive result is a reply with a large offset that causes the client to return data from outside the PDU, for example as a filename in a follow-up request.
  2. Other snprintf() return-value uses. Search for code that passes the return value of snprintf() as a length to a send or copy function. A positive result is a request with overly long parameters that causes the device to send more bytes than the destination buffer holds, leaking adjacent memory.
  3. Other proxy endpoints that forward user-supplied requests. The /msprox endpoint forwards SOAP requests to other registered speakers. Test whether other forwarding paths use attacker-controlled lengths. A positive result is a response containing data from outside the intended buffer.
  4. Other asynchronous request queues with callbacks. Look for patterns where a request is queued with a callback and a pointer to a caller-owned structure, and where a failed or mismatched reply leaves the entry queued. A positive result is a reply with a mismatched message_id followed by a reply with the original message_id, causing the callback to run against freed memory.
  5. Other media parsers. The MPEG-TS bug is a missing length check on the Adaptation field. Test other container or codec parsers with length fields that are copied into fixed buffers. A positive result is a crash or controlled overwrite when the length field is set larger than the buffer.
  6. Rogue adjacent device scenarios. DEVCORE reached the /msprox bug by acting like a rogue Sonos Speaker adjacent on the network. Test whether other device-to-device protocols trust a peer enough to reach parsing code that is not reachable from the normal client interface.
Hero Background
Hero Background From the original on zerodayinitiative.com

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 25 min read.

What happened, in plain words

In 2022, a security contest called Pwn2Own took place in Toronto. In these contests, researchers (people who study software to find its weaknesses) are given real devices and a short amount of time to break into them. The device in this story is a Sonos One smart speaker: a small internet-connected loudspeaker that you control from a phone app and that can play music from streaming services or from files shared on your home network.

Three separate teams managed to break into the speaker. Between them they used four different weaknesses in the speaker's software. The contest organisers paid out a total of $105,000 across the three teams. The team of Toan Pham and Tri Dang from Qrious Secure won $60,000 because their entry was first on the schedule.

The report you are reading is the official write-up from the Zero Day Initiative (ZDI), the organisation that runs Pwn2Own. It explains, bug by bug, what each team did and why it worked. This beginner's version walks through the same material in the same order, but explains every idea from scratch.

A few words you will meet constantly, explained now so the rest makes sense:

  • Vulnerability: a mistake in software that lets someone make it do something the author did not intend. Think of a door that was supposed to be locked but whose latch was installed upside down.
  • Exploit: the actual technique or set of instructions that takes advantage of a vulnerability. The vulnerability is the broken latch; the exploit is the specific shove that opens the door.
  • Bug chain: many real attacks need several vulnerabilities used one after another, like a series of locked doors where opening the first gives you the key to the second. A chain of two bugs is a two-bug chain.
  • Remote code execution (RCE): the strongest outcome in this kind of research. It means the attacker can make the device run commands of their choosing, as if they were sitting at its keyboard.
  • Information leak (info leak): a bug that makes the device reveal a small piece of its internal memory to the attacker. On its own it does not break anything, but it hands the attacker knowledge they need for a later step.
  • Memory: the workspace inside a computer where programs keep their data while running. When software mishandles memory, security bugs appear.

The contest format and why order matters

Before looking at the bugs, the report explains a rule that shaped the whole event. Part of Pwn2Own involves a random drawing for order. The team drawn first gets the full prize if they succeed. Teams drawn later face a bigger risk of a bug collision.

A bug collision means two or more teams independently found and used the same weakness. If three teams show up with the same exploit, only the first one randomly selected gets full credit. The others still demonstrated a real attack, but because it was not new, they receive a reduced award.

In this event some collisions did happen, yet the three teams still used four unique bugs between them. That is the thread the rest of the report follows: which team used which bug, and how the bugs combined.

The software involved

The report names two pieces of software on the speaker that matter.

First, a daemon called anacapad. A daemon is a program that runs quietly in the background on a device, without a visible window, doing a job all the time. This one handles all Sonos-specific functions: accessing music services, controlling the LED lights, and playing audio. When you tap play in the Sonos app, something like anacapad is what actually makes the sound happen.

Second, the open-source libsmb2 library, which Sonos incorporates with a few modifications. A library is a bundle of ready-made code that a program reuses instead of writing everything itself. SMB (Server Message Block) is a standard way for computers to share files and folders over a network; it is the protocol behind the shared folders you may have seen on Windows. libsmb2 is a free implementation of the SMB version 2 protocol. On the speaker it runs inside anacapad and lets the device play music stored in an SMB shared directory on your network.

Crucially, the report says this libsmb2 code path can be reached by unauthenticated users. Unauthenticated means without logging in, without a username or password. So an attacker does not need any account on the speaker to reach this code.

A third surface is the /msprox endpoint. An endpoint is a specific address on a device that accepts requests, like a particular service window in a building. This one acts as a proxy for Sonos Speaker array communication: a proxy is a middleman that receives a request and passes it on to someone else. Here, /msprox forwards a user-supplied SOAP request to other registered speakers. SOAP is an older standard format for sending structured messages between programs, essentially a carefully formatted envelope of text.

Setup and preconditions

The report does not describe a lab setup, tooling versions or account requirements in detail. What it does state about preconditions is:

  1. The libsmb2 code path can be reached by unauthenticated users to play music via the SMB shared directory.
  2. The /msprox endpoint forwards user-supplied SOAP requests to other registered speakers.
  3. For the libsmb2 info leak, the attacker acts as an SMB server and sends a malformed PDU query directory response to the client.
  4. For the DEVCORE variant of the /msprox bug, the attacker acts like a rogue Sonos Speaker adjacent on the network to the target.
  5. The STAR Labs exploit uses a modified impacket to implement a malicious SMB server. impacket is a well-known collection of Python tools for working with network protocols, including SMB; researchers often adapt it to build fake servers.
  6. Sonos enables exploit mitigations, so an information leak is needed before code execution. Exploit mitigations are defensive features built into software that make exploitation harder, for example by randomising where things sit in memory. Because of them, an attacker usually cannot jump straight to running code; they first need to learn some addresses, which is exactly what an info leak provides.

The report does not give firmware versions, library versions beyond the binary names it cites (anacapad, libsmb2.so.1), or the exact Pwn2Own contest rules beyond the random draw.

Finding it

The report frames the findings as contest entries rather than as a single researcher's discovery narrative. The bugs are presented by CVE and by which team used them. A CVE is a public catalogue number for a known vulnerability, so people worldwide can refer to the same bug unambiguously.

CVE Bug Used by
CVE-2023-27354 libsmb2 info leak Qrious Secure only
CVE-2023-27353 (also referenced as CVE-2023-27533/ZDI-23-448) /msprox out-of-bounds read info leak STAR Labs and DEVCORE
CVE-2023-27352 libsmb2 use-after-free leading to RCE Qrious Secure and STAR Labs
CVE-2023-27355 MPEG-TS parser stack buffer overflow leading to RCE DEVCORE only

The report notes that the /msprox bug is referenced in the text as CVE-2023-27533/ZDI-23-448, while the section heading calls it CVE-2023-27353. Both labels appear in the original and are reproduced here as written.

Exploitation

Step 1: CVE-2023-27354, the libsmb2 info leak (Qrious Secure)

Qrious Secure was randomly selected to go first and used a two-bug chain. The first bug was this info leak, and they were the only team to use it during the contest.

To follow this, you need a few memory ideas. When a program receives data over the network, it stores it in a buffer, a reserved chunk of memory. A PDU (Protocol Data Unit) is the package that carries one message of a network protocol; think of it as one envelope with a header (address information) and a payload (the contents). A struct is a small bundle of related values grouped together in memory, like a form with several fields.

The vulnerability is in the way anacapad handles SMBv2 replies from a server, specifically in [redacted](), which processes query directory reply data. A query directory request is simply a client asking a file server "what files are in this folder?". The function allocates an smb2_query_directory_reply struct and stores the result in the PDU's pdu->payload field. It then extracts the output buffer offset and length from the query directory reply sent by the server. An offset is a position, a number saying "start reading this many bytes from the beginning".

The speaker checks that the output buffer does not overlap with the query directory reply header. The offset is later used to calculate the IOV_OFFSET, and is also used at another point in the code. The output_buffer is later used to decode file information from the directory PDU response in [redacted].

The flaw: the code never checks whether the offset is within the len of a PDU packet. In other words, the server says "the file listing starts at position 5000", and the client trusts that number even if the whole packet is only 200 bytes long. Reading past the end of a buffer is called an out-of-bounds (OOB) read: the program reads memory it was never supposed to touch.

By acting as an SMB server and sending a malformed PDU query directory response with a large offset, the client decodes file information from an out-of-bounds (OOB) memory region and sends that information back to the malicious SMB server as part of a filename. This is the clever part: the attacker does not need a separate channel to receive the leaked data. The client itself helpfully sends the out-of-bounds bytes back, disguised as a filename in its next request. By manipulating the offset, the SMB server can determine libc and heap addresses on the client, which are useful for the next step of the exploit chain. libc is the standard C library that every such program uses, and the heap is the area of memory where programs allocate data dynamically at runtime. Knowing where these sit in memory is useful for the next step of the exploit chain.

The report does not include the source snippets for this bug; it describes the logic in prose only.

Step 2: CVE-2023-27353, the /msprox info leak (STAR Labs and DEVCORE)

Two teams used this bug to kick off their exploit. It resides in the /msprox endpoint. A request to this endpoint is handled by function sub_15DFA0(), which calls sub_1C86C0(). Function names like sub_15DFA0 are what you see when a program has been compiled and its original names are gone; the tool that analyses it just labels each block of code by its address.

The report shows a code snippet from sub_1C86C0 in the anacapad binary, corresponding to assembly code from address 0x1C876C. The snippet itself is not reproduced in the text provided; the report describes it as failing to check the return value of snprintf() at [1], and later using that value as the size of an outgoing HTTP header buffer at [2].

To understand this, you need to know what snprintf() does. It is a standard function that builds a piece of text from a template and some values, writing the result into a buffer. It also returns a number: how many characters the finished text would have needed. If the text is too long for the buffer, snprintf() writes only what fits but still returns the larger number. A program that ignores that return value and later uses it as a length is in trouble.

STAR Labs sent a crafted request that provides overly long parameters to the snprintf() call at [1]. The return value from snprintf() (request_len) then exceeds the size of the request buffer, which is 0x1000 bytes. 0x1000 is hexadecimal notation for 4096, a common buffer size. At [2], the code calls ana_server_send_request() to send the contents of the request buffer using request_len as the length. Because request_len is bigger than the buffer, the device sends not just the buffer but also whatever memory sits immediately after it. STAR Labs used this out-of-bounds read (OOBR) to leak the address of the .text segment. The .text segment is the part of a program's memory that holds its executable code; knowing where it is helps an attacker aim at it later.

DEVCORE took a slightly different route to the same effect. Their exploit relied on acting like a rogue Sonos Speaker adjacent on the network to the target. In other words, they acted like a rogue Sonos Speaker adjacent on the network to the target. This let them reach code containing an out-of-bounds read analogous to the one above, resulting in leakage of stack data right after the request_body buffer. The stack is another memory area, used for short-lived data such as the local variables of a function while it runs. The report cites address location 0x1C889C for this path.

Both teams arrived at the same vulnerable code and leaked the data needed to continue their exploit chains.

Step 3: CVE-2023-27352, libsmb2 use-after-free to RCE (Qrious Secure and STAR Labs)

Both Qrious Secure and STAR Labs leveraged a use-after-free (UAF) in libsmb2. Because Qrious Secure was randomly chosen to go first, they won the full $60,000, while the collision resulted in STAR Labs earning $22,500.

A use-after-free is exactly what it sounds like. A program frees a chunk of memory (says "I am done with this, someone else may use it"), but keeps a note of where it was. That stale note is called a dangling pointer. If the program later follows the note and uses the memory, it may be reading or writing whatever a different part of the program has since put there. An attacker who can control what gets placed in that reused memory can steer the program.

The report describes the libsmb2 implementation. smb2_closedir is implemented as shown in the original, and smb2_lazy_readdir is implemented as follows. The main function handling data returned from an SMB server is also shown. The source snippets are not reproduced in the text provided, but the control flow is described:

Text
(1) smb2_lazy_readdir -> smb2_fetchfiles_async -> smb2_cmd_query_directory_async -> create pdu (PDU) with internal message_id (MID) -> add to wait_queue (3)

Line by line, in plain words: the client asks to read a directory (1). That call leads to an asynchronous request, meaning the program sends the request and does not sit waiting; it carries on and handles the reply later. A PDU is created and tagged with an internal message_id (MID), a serial number so the reply can be matched to the request. The PDU is then placed on a wait_queue (3), a list of requests awaiting replies.

When the client receives data from a server (4), it decodes the header (5) and finds the PDU via its message_id (6). smb2_fetchfiles_async() adds the PDU to wait_queue, which holds a callback to fetchfiles_cb() at (7). A callback is a function the program agrees to run later, when a particular event happens; here, when the reply arrives. That callback keeps the dir structure within its private data (8). Before it finishes, it invokes the dir->cb callback at (9).

Back at (6): in a normal scenario the SMB server returns data with the valid message_id as MID, and the callback is triggered before dir is freed in close_dir at (2). If the server sends an invalid message_id (different from MID), the PDU is not found and stays alive in wait_queue, still holding the dir struct pointer. When (2) finishes, the dir pointer is freed and the PDU holds a dangling pointer.

The next time the client reads data from the server, if the server replies with a previously valid message_id of MID, the client decodes the data and finds the corresponding PDU via that MID. The PDU's callback fetchfiles_cb is called and at (4) accesses the dangling pointer. By reallocating the freed dir structure before fetchfiles_cb is called, the attacker can control the value cb and thereby gain control of $PC by pointing cb to maliciously crafted data. $PC is the program counter, the processor register that says which instruction to run next. Controlling it means controlling what the device does next. Combined with the memory address leak from CVE-2023-27354, this achieves remote code execution.

STAR Labs took a different approach to the same vulnerability. One of the functions added to libsmb2 is smb2_lazy_readdir(). Their trigger:

Text
-- `smb2_opendir()` is called, which will return an `smbdir` (`smb2dir` structure).         -- `smbdir` is later passed into `smb2_lazy_readdir()` together with a custom callback function.

In plain words: first the client opens a directory, which gives back a structure describing it (smbdir). That structure is then handed to the lazy read function along with a callback to run when results arrive.

smb2_cmd_query_directory_async() receives a callback function with a defined prototype and any user-defined structure (in this case smb2dir). It inserts a pdu (smb2_pdu) into a request queue waiting to be handled. After a reply is received, the callback is invoked with the received data. The Sonos device passes the smbdir structure as cb_data and populates it inside the callback. This snippet is in sub_109C0() of the libsmb2.so.1 binary, corresponding to assembly code from address 0x10A04.

If wait_for_reply fails, meaning smb2_cmd_query_directory_async did not receive any valid response for its pdu, smb2_closedir is invoked to free the smbdir object. Then smb2_disconnect_share is called. During this process a dangling pointer to smbdir is left in the request queue.

In smb2_disconnect_share, the call chain is wait_for_reply -> smb2_service -> smb2_service_fd -> smb2_read_from_socket -> smb2_read_data. A call chain is simply one function calling the next, like a series of people passing a message along. In smb2_read_data, smb2_find_pdu retrieves the pdu based on the message_id of the response packet, which is controllable by the attacker. If the response specifies the message_id of the Query Directory pdu, smb2_find_pdu returns the smb2_cmd_query_directory_async pdu. When pdu->cb is invoked from z_query_directory_cb_109C0, the dangling pointer leads to $PC control.

Reclaiming the freed smb2dir object is done by appending extra data onto the response packet from the server; the client allocates a buffer to store this extra padding data. The exploit uses a modified impacket to implement a malicious SMB server.

The exploit proceeds as follows:

  1. Send a command to the target device to add a new SMB share.
  2. Using a modified smb2QueryDirectory() function in the exploit's impacket SMB server, return a malformed response to the client's smb2_cmd_query_directory request, producing a dangling pointer.
  3. When the client calls smb2_disconnect_share, it sends a disconnect tree request to the server. Using a modified smb2TreeDisconnect function in the impacket SMB server, the exploit returns a Query Directory response with the message_id from step 2. The exploit also appends data to this response to reclaim the smb2dir object in the client.
  4. The exploit gains control of $PC via the overwritten smb2dir->cb pointer and uses ROP to get shell.

Step 4 mentions ROP, short for return-oriented programming. It is a technique for making a program run a sequence of small existing code fragments, chosen by the attacker, without needing to inject new code. "Get shell" means obtaining a command prompt on the device, the practical goal of remote code execution.

Step 4: CVE-2023-27355, MPEG-TS parser stack buffer overflow (DEVCORE)

This RCE bug was used only by DEVCORE. Due to the random draw this was the third attempt on the Sonos, which left them at a disadvantage as they were more likely to hit a bug collision. They did collide on their info leak, but the RCE portion of their chain was unique and earned its own CVE.

MPEG-TS is a file format for video and audio streams, commonly used for broadcast television and for .ts files. A parser is the part of a program that reads a file format and turns it into something the program can use; it is the reader that interprets the structure of the file. A stack buffer overflow happens when a program copies more data into a fixed-size buffer on the stack than it can hold. The extra data spills over into neighbouring memory, overwriting whatever was there, much like pouring too much water into a glass.

While parsing a .ts audio file, the speaker does not check the length of the Adaptation field, leading to a stack buffer overflow. The bug results from the ability to specify an arbitrary value to the afelen field. afelen is the number that says how long that field is. The speaker then reads the specified number of bytes into the payload buffer, smashing the stack. The report cites address 0x406604.

Because Sonos enables exploit mitigations, the attacker needs to leak information first. During the contest, the DEVCORE entry first leaked the stack canary, stack address and program base address using CVE-2023-27353. A stack canary is a secret value placed on the stack that the program checks before returning from a function; if it has changed, the program knows an overflow happened and stops. Leaking it lets an attacker preserve it while still overwriting other things. With those values, exploitation is straightforward: the MPEG-TS parser vulnerability is used to overwrite the return address and jump to the exec() wrapper. The return address is the note on the stack saying where to go back to when a function finishes; overwriting it redirects the program. An exec() wrapper is a small piece of existing code that starts a program, so jumping to it is a convenient way to run commands. As the #x19 and #x22 registers are also controllable by the exploit, the attacker can set these registers to a controllable stack buffer and execute arbitrary commands. Registers are the processor's tiny, fast storage slots; #x19 and #x22 are two of them on this device's processor.

The demonstration succeeded, but due to the collision on CVE-2023-27353 the DEVCORE team did not win the full amount. They earned $22,500 for being the third team to exploit the Sonos speaker.

Root cause

There are four distinct root causes in the report. A root cause is the underlying mistake that makes a vulnerability possible, as opposed to the symptom you see.

  1. CVE-2023-27354 (libsmb2 info leak). [redacted]() extracts the output buffer offset and length from the server's query directory reply and checks only that the output buffer does not overlap the reply header. It never checks whether the offset is within the len of the PDU packet. The offset is later used to calculate IOV_OFFSET and to decode file information in [redacted], so a large offset causes decoding from an OOB memory region.
  2. CVE-2023-27353 (/msprox info leak). The code in sub_1C86C0() fails to check the return value of snprintf(). That return value (request_len) is later used as the size of an outgoing HTTP header buffer passed to ana_server_send_request(), even though it can exceed the 0x1000-byte request buffer. The result is an out-of-bounds read that leaks adjacent memory (the .text segment for STAR Labs, stack data after request_body for DEVCORE).
  3. CVE-2023-27352 (libsmb2 UAF). When a server replies with an invalid message_id, the PDU is not found and remains in wait_queue holding a pointer to the dir structure. close_dir then frees dir, leaving a dangling pointer. A later reply with the original MID causes fetchfiles_cb to run against the freed structure, and the attacker can reclaim it and control cb, giving $PC control. The STAR Labs variant reaches the same dangling pointer through smb2_closedir and smb2_disconnect_share, with the message_id of the response packet controllable by the attacker.
  4. CVE-2023-27355 (MPEG-TS parser). The parser does not check the length of the Adaptation field. An arbitrary afelen value causes the speaker to read that many bytes into the payload buffer, overflowing the stack.

On defences: the report states that Sonos enables exploit mitigations, which is why the DEVCORE chain needed an info leak first. It does not enumerate the specific mitigations.

Impact

The report's stated outcomes:

  • CVE-2023-27354 gives an information leak: libc and heap addresses on the client, useful for the next step of the chain.
  • CVE-2023-27353 gives an information leak: the .text segment address (STAR Labs) or stack data after request_body (DEVCORE).
  • CVE-2023-27352, combined with the CVE-2023-27354 leak, achieves remote code execution.
  • CVE-2023-27355, combined with the CVE-2023-27353 leak, achieves remote code execution, with the attacker able to set #x19 and #x22 to a controllable stack buffer and execute arbitrary commands.

The libsmb2 functionality can be reached by unauthenticated users to play music via the SMB shared directory, per the report. The /msprox endpoint forwards user-supplied SOAP requests to other registered speakers, and DEVCORE's variant required the attacker to act like a rogue Sonos Speaker adjacent on the network to the target.

Fix

A patch is an update that fixes a bug. It states that many of the bugs disclosed during Pwn2Own Toronto are patched, and that the team will continue to disclose details on the blog. Based on the root causes, the fixes that would address them are: bounds-checking the output buffer offset against the PDU len in [redacted](); checking the snprintf() return value before using it as a send length in sub_1C86C0(); ensuring a PDU is removed from wait_queue (or its dir reference invalidated) when close_dir frees the structure; and validating the Adaptation field length against the payload buffer size in the MPEG-TS parser. The report does not confirm that any of these specific changes were made.

Variants to test

These are ideas for further research, written for people who want to look for similar bugs elsewhere.

  1. Other SMB reply parsers in libsmb2. Look for functions that extract an offset and length from a server-controlled reply and use them to index into a PDU payload without checking the offset against the PDU length. A positive result is a reply with a large offset that causes the client to return data from outside the PDU, for example as a filename in a follow-up request.
  2. Other snprintf() return-value uses. Search for code that passes the return value of snprintf() as a length to a send or copy function. A positive result is a request with overly long parameters that causes the device to send more bytes than the destination buffer holds, leaking adjacent memory.
  3. Other proxy endpoints that forward user-supplied requests. The /msprox endpoint forwards SOAP requests to other registered speakers. Test whether other forwarding paths use attacker-controlled lengths. A positive result is a response containing data from outside the intended buffer.
  4. Other asynchronous request queues with callbacks. Look for patterns where a request is queued with a callback and a pointer to a caller-owned structure, and where a failed or mismatched reply leaves the entry queued. A positive result is a reply with a mismatched message_id followed by a reply with the original message_id, causing the callback to run against freed memory.
  5. Other media parsers. The MPEG-TS bug is a missing length check on the Adaptation field. Test other container or codec parsers with length fields that are copied into fixed buffers. A positive result is a crash or controlled overwrite when the length field is set larger than the buffer.
  6. Rogue adjacent device scenarios. DEVCORE reached the /msprox bug by acting like a rogue Sonos Speaker adjacent on the network. Test whether other device-to-device protocols trust a peer enough to reach parsing code that is not reachable from the normal client interface.
Hero Background
Hero Background From the original on zerodayinitiative.com

Glossary

  • anacapad: the background program (daemon) on the Sonos speaker that handles Sonos-specific functions such as music services, LED control and audio playback.
  • API: a defined way for one piece of software to ask another to do something, like a service counter with set procedures.
  • Asynchronous: a style of programming where a request is sent and the program carries on rather than waiting; the reply is handled later by a callback.
  • Buffer: a reserved area of memory used to hold data, often of a fixed size.
  • Bug chain: several vulnerabilities used one after another to achieve a larger goal.
  • Bug collision: when two or more teams independently use the same vulnerability in a contest, so only the first gets full credit.
  • Callback: a function a program agrees to run later, when a particular event (such as a reply arriving) happens.
  • Call chain: a sequence where one function calls another, which calls another, and so on.
  • CVE: a public catalogue number for a known vulnerability, so people worldwide can refer to the same bug unambiguously.
  • Daemon: a program that runs quietly in the background on a device, without a visible window.
  • Dangling pointer: a stored memory address that points to memory which has already been freed and may now hold something else.
  • Endpoint: a specific address on a device that accepts requests, like a particular service window in a building.
  • Exploit mitigations: defensive features built into software that make exploitation harder, for example by randomising where things sit in memory.
  • Heap: the area of memory where programs allocate data dynamically at runtime.
  • impacket: a well-known collection of Python tools for working with network protocols, including SMB; researchers often adapt it to build fake servers.
  • Information leak (info leak): a bug that makes a device reveal a small piece of its internal memory to the attacker.
  • libc: the standard C library that such programs use, containing common functions.
  • Library: a bundle of ready-made code that a program reuses instead of writing everything itself.
  • libsmb2: a free implementation of the SMB version 2 protocol, incorporated by Sonos with modifications.
  • MPEG-TS: a file format for video and audio streams, commonly used for broadcast television and for .ts files.
  • Offset: a position, a number saying how many bytes from the beginning to start reading.
  • Out-of-bounds (OOB) read: reading memory outside the intended buffer, which the program was never supposed to touch.
  • Parser: the part of a program that reads a file format and turns it into something the program can use.
  • Patch: an update that fixes a bug.
  • PDU (Protocol Data Unit): the package that carries one message of a network protocol, with a header and a payload.
  • Proxy: a middleman that receives a request and passes it on to someone else.
  • Pwn2Own: a security contest in which researchers try to break into real devices within a time limit.
  • Query directory: a request asking a file server what files are in a folder.
  • Registers: the processor's tiny, fast storage slots; #x19 and #x22 are two of them on this device's processor.
  • Remote code execution (RCE): making a device run commands of the attacker's choosing from a distance.
  • Return address: the note on the stack saying where to go back to when a function finishes.
  • ROP (return-oriented programming): a technique for making a program run a sequence of small existing code fragments chosen by the attacker, without injecting new code.
  • SMB (Server Message Block): a standard way for computers to share files and folders over a network.
  • snprintf(): a standard function that builds text from a template into a buffer and returns how many characters the finished text would have needed.
  • SOAP: an older standard format for sending structured messages between programs.
  • Stack: a memory area used for short-lived data such as a function's local variables while it runs.
  • Stack buffer overflow: copying more data into a fixed-size buffer on the stack than it can hold, so the extra data overwrites neighbouring memory.
  • Stack canary: a secret value placed on the stack that the program checks before returning from a function, to detect overflows.
  • Struct: a small bundle of related values grouped together in memory.
  • Unauthenticated: without logging in, without a username or password.
  • Use-after-free (UAF): using memory after it has been freed, when it may already hold something else.
  • $PC (program counter): the processor register that says which instruction to run next; controlling it means controlling what the device does next.
  • .text segment: the part of a program's memory that holds its executable code.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.