Skip to content
Memory corruption Write-up Advanced

TCP/IP Vulnerability CVE2022–34718 PoC Restoration and Analysis

A vulnerability in the Windows TCP/IP driver allows an attacker to overwrite a byte in a kernel object by sending a crafted IPv6 packet with an IPSec ESP extension header. This could potentially lead to remote code execution, though the report only demonstrates a crash and discusses possible exploitation paths.

medium.com

Published on medium.com

Cybersecurity

Numen Cyber Labs, on medium.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. 6 min read.

Context

Microsoft's patch released the month before the write-up addressed a remote code execution vulnerability in the Windows TCP/IP driver, tracked as CVE-2022-34718. The affected component is tcpip.sys, the driver that implements the TCP/IP stack, including IPv6 fragment reassembly and IPSec ESP processing. Microsoft's vulnerability description stated that the flaw is triggered by sending IPv6 packets to nodes that have IPSec enabled.

Numen Cyber Labs set out to understand the vulnerability and to restore a working proof of concept by comparing the August and September builds of tcpip.sys. This article walks through that patch comparison, the construction of the IPSec test environment, the packet crafting, and what the resulting PoC actually does to memory.

TCP/IP Protocol Remote Code Execution Vulnerability CVE-2022–34718 From the original on medium.com

Two protocol specifications are needed to follow the analysis: IPv6 (RFC 2460) and IPSec ESP (RFC 2406).

Setup

The test environment consists of two hosts in a domain environment, each verifying the integrity of all traffic from the other. IPSec is not enabled by default; it is normally used by a VPN or to strengthen the security of other protocols, and has to be configured by an administrator.

In IPSec ESP the encryption mode is selectable. For this work only integrity HASH verification was enabled, using SHA1 to compute the hash, which is the minimum requirement to trigger the vulnerability. No traffic encryption was used, which makes the protocol analysis more intuitive.

From the original on medium.com

The environment is considered correctly set up once the two hosts can reach each other over ICMPv6 under the configured IP security policy.

To send raw IP packets and control every byte of each packet during debugging, a low-level interface is needed. The team used an existing NDIS protocol driver, referring to the code example in Windows Network Communication Program Design Version 2 for compiling and installing the driver. Python users can alternatively use Scapy.

From the original on medium.com

Finding it

Comparing the August and September patch of tcpip.sys showed two functions that needed to be patched.

From the original on medium.com

The repair applied to the first function indicates an error where the memory offset is larger than expected when reassembling IPv6 fragmented data.

The second patched function is less intuitive:

From the original on medium.com

From this patch the team could only tell that, while receiving IPSec ESP packets, packets whose flag bits do not meet the patch conditions are discarded.

Exploitation

Step 1: Attempt to trigger the offset with plain IPv6 fragmentation

The first hypothesis was that an IPv6 fragmented datagram satisfying the patched conditions in Ipv6pReassembleDatagram would be enough to produce the oversized memory offset, without involving IPSec at all. The earlier analysis of the tcpip denial-of-service vulnerability CVE-2021-24086 provided a good entry point for building IPv6 fragments that get reassembled in that function.

Following that reference PoC, the team obtained a set of IPv6 fragments that were reassembled in Ipv6pReassembleDatagram. However, fragments carried only in ordinary IPv6 headers did not affect the parameters constrained by the patch. Reviewing the official vulnerability description together with the second patch led to the conclusion that an IPSec ESP packet is probably needed to control the key parameters of the first patch.

Step 2: Build IPSec traffic that satisfies the second patch

To construct such packets, the encryption algorithm and secret key specified by the protocol must be known. All IPSec encryption is implemented inside the TCP/IP driver. Microsoft exposes a set of WFP (Windows Filtering Platform) APIs at the user layer that can reveal some SA parameters such as the SPI, but the secret key material required for IPSec ESP encryption cannot be obtained directly through them.

By analysing the TCP/IP driver, the team found that the key can be obtained from the driver's MICROSOFT_TCPIP_PROVIDER_Context. In the test environment it was read directly from the BCryptCreateHash parameter in the TCP/IP driver. Since only integrity verification is enabled in this traffic, no encryption key is needed for the payload itself.

The constructed IPSec packets satisfy the restrictions of the second patched function. The second flag constrained by that patch is the type of encrypted data carried in the IPSec ESP packet. When the IPv6 extension header type inside the ESP is less than or equal to 0x2c, the packet is discarded. The affected types are:

  • 0 (IPv6 Hop-by-Hop Option)
  • 0x2b (Routing Header for IPv6)
  • 0x2c (Fragment Header for IPv6)

In the test, the Fragment Header for IPv6 (0x2c) was used.

From the original on medium.com

Step 3: Assemble the final PoC

The IPv6 fragmented data built in step 1 is treated as the data that needs to be encrypted and verified in the ESP protocol. The key detail is that the last flag in the ESP tail structure is set to 0x2c, the extension header type carried by the ESP. The packet is sent after it is assembled.

Because the vulnerability requires sending raw IP packets, the NDIS driver described in Setup is used to control and modify each byte of every packet sent.

Root cause

The patch fundamentally restricts ESP from carrying the IPv6 extension headers listed above inside the IPv6 IPSec protocol. The first patched function, Ipv6pReassembleDatagram, computed a memory offset larger than expected while reassembling IPv6 fragments, and the second patch discards ESP packets whose inner extension header type is 0x2c or lower.

With the current PoC, a byte in the content of the NetIo protocol header object at an arbitrary offset address greater than 0x38 can be overwritten with an arbitrary value, 0x2C in this case. That 0x2c is not the first IPv6 extension header type flag carried in the ESP; it is the IPv6 extension header flag next to the fragment header carried in the ESP, and it can be set arbitrarily.

By constructing accurate extension headers, the ESP packet can be made to crash while parsing the next extension header. If the decrypted ESP content is invalid and does not correspond to the extension header type, the system does not trigger an exception:

From the original on medium.com

Impact

The vulnerability depends on the combination of IPv6 and IPSec. IPv6 is widely deployed, but IPSec is not usually the default option for common VPNs or environments that require traffic encryption; an administrator has to configure it.

The PoC also requires an environment where two IP security policies are set in the domain. Identity is authenticated through the domain first, and only then can vulnerable packets be sent to other trusted domain member targets. Encrypted traffic sent without authentication is not processed, and the pre-shared secret key is needed to complete authentication.

The team suggests two possible exploitation paths, both of which still need further analysis of feasibility:

  1. Analyse the detailed structure of the NetIo protocol header object and test whether the data written can turn the data size or other key data locations into other buffer copy errors, constructing an arbitrary read/write primitive.
  2. Because the modifiable locations are not limited to NetIo protocol header objects, larger offsets can be covered by modifying the length of the ESP packet, so that other objects can be used to construct read/write instructions or code execution.

Fix

Microsoft's patch changes tcpip.sys in two functions. The first corrects the oversized memory offset during IPv6 fragment reassembly. The second discards IPSec ESP packets whose inner IPv6 extension header type is 0x2c or lower, which covers Hop-by-Hop Options, Routing Header and Fragment Header.

Variants to test

  • Send IPv6 fragments carried in ordinary IPv6 headers only, without ESP, and observe whether reassembly in Ipv6pReassembleDatagram still produces an oversized offset. A positive result is a crash or memory corruption without any IPSec involvement.
  • Wrap the fragments in ESP with inner extension header types other than 0x2c, such as 0 or 0x2b, on an unpatched host. A positive result is that the packet is processed rather than discarded and reaches the reassembly path.
  • Vary the length of the ESP packet to push the overwrite offset beyond 0x38 onto other objects. A positive result is corruption of an object other than the NetIo protocol header object.
  • Set the extension header flag next to the fragment header to different values and observe the effect on parsing of the following extension header. A positive result is a controlled crash or a different overwrite value.
  • Send ESP packets with invalid decrypted content that does not match the extension header type. A positive result would be an exception, which the report says does not occur.

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. 15 min read.

What happened, in plain words

In the month before this write-up, Microsoft released a security update for Windows. One of the things it fixed was a serious flaw in the part of Windows that handles network traffic, the code that lets your computer talk to other computers over the internet and local networks. That code is called the TCP/IP stack, and in Windows it lives in a driver file named tcpip.sys. A driver is a piece of software that sits close to the operating system and controls hardware or core functions; you never open it yourself, but everything network-related passes through it.

The flaw was tracked as CVE-2022-34718. CVE stands for Common Vulnerabilities and Exposures: a public catalogue where each security flaw gets a permanent ID number so people can refer to it unambiguously. The flaw was a remote code execution vulnerability, often shortened to RCE. In plain terms: an attacker who can send the right kind of network packet to a vulnerable machine could make that machine run code of the attacker's choosing, without ever logging in. That is about as bad as a network flaw gets.

The official vulnerability description said the flaw is triggered by sending IPv6 packets to machines that have IPSec enabled. IPv6 is the newer version of the addressing system the internet uses to deliver data between machines; IPSec is a set of rules for encrypting and verifying network traffic, usually set up by an administrator rather than switched on by default.

A security research team called Numen Cyber Labs decided to understand the flaw properly and to rebuild a working proof of concept. A proof of concept, or PoC, is a small demonstration that shows a flaw is real: the minimum amount of work needed to make the bug happen, without building a full attack. They did it the hard way, by comparing the version of tcpip.sys from before the fix with the version from after it, and reasoning backwards from what changed. This article walks through that process in the same order they did: comparing the patches, building a test network, crafting the packets, and looking at what the finished PoC actually does to the machine's memory.

TCP/IP Protocol Remote Code Execution Vulnerability CVE-2022–34718 From the original on medium.com

The image above is the article's title card, naming the flaw as a TCP/IP protocol remote code execution vulnerability.

To follow the analysis you need two public documents that describe the packet formats involved: the specification for IPv6 (RFC 2460) and the specification for IPSec ESP (RFC 2406). An RFC is a numbered document published by the internet's standards bodies; it is the official description of how a protocol works, and it is freely readable. ESP stands for Encapsulating Security Payload and is the part of IPSec that carries the protected data.

Setting up a test network

The team built a lab with two computers, both members of the same Windows domain. A domain is a group of machines managed together, where one central server handles logins and trust between machines. In this lab, each of the two machines checks the integrity of all traffic coming from the other. Integrity checking means the receiver can tell whether a packet was altered in transit, even if it cannot read the packet's contents.

IPSec is not on by default. It is normally used by a VPN (a private tunnel over a public network) or to strengthen the security of other protocols, and an administrator has to configure it deliberately. That matters later, when we talk about who is actually at risk.

Within IPSec ESP you can choose an encryption mode. For this work the team enabled only integrity HASH verification, using SHA1 to compute the hash. A hash is a short fingerprint computed from data: change one byte of the data and the fingerprint changes completely, which is how the receiver detects tampering. SHA1 is one particular hash algorithm. Using only integrity checking, with no encryption of the payload, was the minimum needed to trigger the flaw, and it made the packets easier to read and reason about.

From the original on medium.com

This image shows the lab: two hosts in a domain environment verifying the integrity of each other's traffic.

From the original on medium.com

The image above shows the IPSec configuration, where only integrity HASH verification is enabled and SHA1 is used to calculate the hash.

The lab counts as ready once the two machines can reach each other over ICMPv6 under the configured security policy. ICMPv6 is the IPv6 helper protocol behind things like ping: a small message one machine sends to another to check it is reachable.

To send hand-built network packets and control every single byte while debugging, you need a low-level interface: the normal operating system networking calls are too polite and add their own headers for you. The team used an existing NDIS protocol driver, referring to the code example in the book Windows Network Communication Program Design Version 2 for compiling and installing it. NDIS is the part of Windows that network drivers plug into; writing a driver against it lets you hand raw packets straight to the network card. People who prefer Python can use Scapy instead, a library for building and sending packets from a script.

From the original on medium.com

This image relates to the driver used to send the raw packets.

Finding the flaw by comparing patches

A patch is a small update that changes specific parts of a program. If you have the version of a file from before the patch and the version from after, you can compare them and see exactly which functions the vendor touched. A function is a named block of code that does one job. Security researchers do this constantly: the fix points at the bug.

Comparing the August and September builds of tcpip.sys, the team found two functions that had been patched.

From the original on medium.com

This image shows the comparison of the two builds, highlighting the functions that changed.

The repair applied to the first function tells you something about the bug: there was an error where a memory offset came out larger than expected while the system was reassembling IPv6 fragmented data. Two ideas there need unpacking. Fragmentation is what happens when a packet is too big for a network link: the sender splits it into numbered pieces, and the receiver glues them back together, which is the reassembly. An offset is a distance into a block of memory, used to say which byte you mean; if the offset is bigger than the block, the code writes or reads past the end of it, into memory that belongs to something else. That is the classic shape of a memory corruption bug.

The second patched function was less obvious.

From the original on medium.com

This image shows the second patched function.

From this patch alone the team could only tell that, while receiving IPSec ESP packets, packets whose flag bits do not meet the patch conditions are discarded. A flag bit is a single on/off marker inside a packet's header that tells the receiver something about the packet's contents. Discarded means the machine silently drops the packet instead of processing it.

Building the proof of concept

Step 1: Try plain IPv6 fragmentation first

The first hypothesis was simple: maybe an IPv6 fragmented datagram that satisfies the conditions the patch now checks would be enough to produce the oversized memory offset, with no IPSec involved at all. The function where the reassembly happens is called Ipv6pReassembleDatagram.

To build fragments that get reassembled there, the team started from an earlier public analysis of a Windows denial-of-service flaw, CVE-2021-24086. A denial-of-service flaw is one that crashes or freezes a machine rather than running code on it. That earlier write-up provided a good entry point for producing IPv6 fragments that reach the reassembly function.

Following that reference PoC, the team did get a set of IPv6 fragments reassembled in Ipv6pReassembleDatagram. But fragments carried only in ordinary IPv6 headers did not affect the parameters the patch constrains. In other words, the plain-fragmentation route did not touch the values that the fix was guarding, so it was not the trigger.

Rereading Microsoft's official description together with the second patch led to a conclusion: an IPSec ESP packet is probably needed to control the key parameters of the first patch. That is why the next step was to build IPSec traffic.

Step 2: Build IPSec traffic that satisfies the second patch

To construct valid IPSec packets you must know the encryption algorithm and the secret key the protocol is using. All IPSec encryption happens inside the TCP/IP driver, so there is no obvious place in normal Windows to read the key from.

Microsoft does expose a set of WFP APIs at the user layer. WFP stands for Windows Filtering Platform, the system that lets programs inspect and filter network traffic; an API is a documented set of functions one program offers to another, like a service counter where you ask for specific information in a fixed way. Through WFP you can find some parameters of the security association, such as the SPI. A security association, or SA, is the agreed set of settings for one protected conversation; the SPI, or Security Parameters Index, is the label that identifies which association a packet belongs to. But the secret key material needed for IPSec ESP encryption cannot be obtained directly through those APIs.

By analysing the TCP/IP driver, the team found that the key can be obtained from the driver's MICROSOFT_TCPIP_PROVIDER_Context. In the test environment they read it directly from the BCryptCreateHash parameter in the TCP/IP driver. BCryptCreateHash is the Windows function that sets up a hash calculation; since only integrity checking was enabled, the key material used for hashing was reachable there. Because no encryption of the payload is used in this traffic, no separate encryption key is needed for the payload itself.

The IPSec packets they built satisfy the restrictions of the second patched function. The second flag constrained by that patch is the type of encrypted data carried inside the IPSec ESP packet. When the IPv6 extension header type inside the ESP is less than or equal to 0x2c, the packet is discarded. An extension header is an optional extra header attached to an IPv6 packet that carries additional instructions for the receiver. The affected types are:

  • 0 (IPv6 Hop-by-Hop Option)
  • 0x2b (Routing Header for IPv6)
  • 0x2c (Fragment Header for IPv6)

The numbers are written in hexadecimal, a base-16 way of writing numbers that programmers use because it maps neatly onto bytes; 0x2c is 44 in ordinary decimal. In the test, the Fragment Header for IPv6 (0x2c) was used.

From the original on medium.com

This image shows the extension header types covered by the restriction, with the Fragment Header for IPv6 (0x2c) used in the test.

Step 3: Assemble the final PoC

The IPv6 fragmented data built in step 1 is now treated as the data that needs to be encrypted and verified inside the ESP protocol. The key detail is that the last flag in the ESP tail structure is set to 0x2c, the extension header type carried by the ESP. The packet is sent after it is assembled.

Because the flaw requires sending raw IP packets, the NDIS driver described earlier is used to control and modify each byte of every packet sent. That is the whole reason for the driver: normal networking tools would not let the team set the exact bytes the bug depends on.

What actually goes wrong

Fundamentally, the patch restricts ESP from carrying the IPv6 extension headers listed above inside the IPv6 IPSec protocol. The first patched function, Ipv6pReassembleDatagram, computed a memory offset larger than expected while reassembling IPv6 fragments, and the second patch discards ESP packets whose inner extension header type is 0x2c or lower.

With the current PoC, a byte in the content of the NetIo protocol header object at an arbitrary offset address greater than 0x38 can be overwritten with an arbitrary value, 0x2C in this case. The NetIo protocol header object is an internal data structure the networking code uses to keep track of a packet; overwriting a byte inside it means corrupting the system's own bookkeeping. 0x38 is 56 in decimal, so the overwrite lands past the first 56 bytes of that structure.

That 0x2c is not the first IPv6 extension header type flag carried in the ESP. It is the IPv6 extension header flag next to the fragment header carried in the ESP, and it can be set arbitrarily. In other words, the attacker controls which value gets written, not just where.

By constructing accurate extension headers, the ESP packet can be made to crash while parsing the next extension header. If the decrypted ESP content is invalid and does not correspond to the extension header type, the system does not trigger an exception:

From the original on medium.com

This image illustrates that invalid decrypted ESP content which does not match the extension header type does not cause an exception.

Who is actually affected

The flaw depends on the combination of IPv6 and IPSec. IPv6 is widely deployed today, but IPSec is not usually the default option for common VPNs or for environments that require traffic encryption; an administrator has to configure it.

The PoC also requires an environment where two IP security policies are set in the domain. Identity is authenticated through the domain first, and only then can vulnerable packets be sent to other trusted domain member targets. Encrypted traffic sent without authentication is not processed, and the pre-shared secret key is needed to complete authentication. A pre-shared key is a secret that both sides are configured with in advance, like a password two people agree on before meeting.

The team suggests two possible exploitation paths, both of which still need further analysis of feasibility:

  1. Analyse the detailed structure of the NetIo protocol header object and test whether the data written can turn the data size or other key data locations into other buffer copy errors, constructing an arbitrary read/write primitive. An arbitrary read/write primitive means the attacker can read or change any chosen memory address, which is usually the stepping stone to running code.
  2. Because the modifiable locations are not limited to NetIo protocol header objects, larger offsets can be covered by modifying the length of the ESP packet, so that other objects can be used to construct read/write instructions or code execution.

The fix

Microsoft's patch changes tcpip.sys in two functions. The first corrects the oversized memory offset during IPv6 fragment reassembly. The second discards IPSec ESP packets whose inner IPv6 extension header type is 0x2c or lower, which covers Hop-by-Hop Options, Routing Header and Fragment Header.

Things worth testing next

  • Send IPv6 fragments carried in ordinary IPv6 headers only, without ESP, and observe whether reassembly in Ipv6pReassembleDatagram still produces an oversized offset. A positive result is a crash or memory corruption without any IPSec involvement.
  • Wrap the fragments in ESP with inner extension header types other than 0x2c, such as 0 or 0x2b, on an unpatched host. A positive result is that the packet is processed rather than discarded and reaches the reassembly path.
  • Vary the length of the ESP packet to push the overwrite offset beyond 0x38 onto other objects. A positive result is corruption of an object other than the NetIo protocol header object.
  • Set the extension header flag next to the fragment header to different values and observe the effect on parsing of the following extension header. A positive result is a controlled crash or a different overwrite value.
  • Send ESP packets with invalid decrypted content that does not match the extension header type. A positive result would be an exception, which the report says does not occur.

Glossary

  • API: a documented set of functions one program offers to another, so they can exchange information in a fixed, agreed way.
  • BCryptCreateHash: the Windows function that sets up a hash calculation; in this lab the key material was read from its parameter.
  • CVE: Common Vulnerabilities and Exposures, a public catalogue that gives every security flaw a permanent ID number.
  • Denial-of-service: a flaw that crashes or freezes a machine rather than running code on it.
  • Domain: a group of computers managed together, with one central server handling logins and trust between them.
  • Driver: software that sits close to the operating system and controls hardware or core functions.
  • ESP: Encapsulating Security Payload, the part of IPSec that carries the protected data.
  • Extension header: an optional extra header attached to an IPv6 packet that carries additional instructions for the receiver.
  • Flag bit: a single on/off marker inside a packet header that tells the receiver something about the packet.
  • Fragment reassembly: the process of gluing numbered pieces of a split packet back together at the receiver.
  • Fragmentation: splitting a packet that is too big for a network link into numbered pieces.
  • Function: a named block of code that performs one job.
  • Hash: a short fingerprint computed from data; changing the data changes the fingerprint completely.
  • Hexadecimal: a base-16 way of writing numbers, used by programmers because it maps neatly onto bytes; 0x2c is 44 in decimal.
  • ICMPv6: the IPv6 helper protocol behind reachability checks such as ping.
  • Integrity checking: verifying that a packet was not altered in transit, without necessarily hiding its contents.
  • IPSec: a set of rules for encrypting and verifying network traffic, configured by an administrator rather than on by default.
  • IPv6: the newer version of the internet's addressing system for delivering data between machines.
  • Memory offset: a distance into a block of memory, used to say which byte is meant; an offset larger than the block means reading or writing past its end.
  • NDIS: the part of Windows that network drivers plug into, allowing raw packets to be handed to the network card.
  • NetIo protocol header object: an internal data structure the networking code uses to keep track of a packet.
  • Patch: a small update that changes specific parts of a program.
  • PoC: proof of concept, a minimal demonstration that a flaw is real.
  • Pre-shared key: a secret both sides are configured with in advance, like a password agreed before meeting.
  • RCE: remote code execution, a flaw that lets an attacker run their own code on a machine over the network without logging in.
  • RFC: a numbered document published by the internet's standards bodies that officially describes how a protocol works.
  • SA: security association, the agreed set of settings for one protected conversation.
  • Scapy: a Python library for building and sending network packets from a script.
  • SHA1: one particular hash algorithm.
  • SPI: Security Parameters Index, the label identifying which security association a packet belongs to.
  • TCP/IP stack: the software that implements network communication on a machine; in Windows it lives in tcpip.sys.
  • VPN: a private tunnel over a public network.
  • WFP: Windows Filtering Platform, the system that lets programs inspect and filter network traffic.
  • tcpip.sys: the Windows driver that implements the TCP/IP stack, including IPv6 fragment reassembly and IPSec ESP processing.
  • Ipv6pReassembleDatagram: the function in tcpip.sys that reassembles IPv6 fragments, where the oversized offset occurred.
  • MICROSOFT_TCPIP_PROVIDER_Context: a structure in the TCP/IP driver from which the key could be obtained in the test environment.

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.