Crashing Industrial Control Systems at Pwn2Own Miami 2022
Two denial-of-service vulnerabilities were found in OPC UA servers: a stack exhaustion in the .NET server via a recursive TranslateBrowsePathsToNodeId request, and a use-after-free race condition in the C++ demo server. An attacker could crash the servers, disrupting industrial operations.
Published on jfrog.com
Earlier this year, the JFrog Security research team competed in the Pwn2Own Miami 2022 hacking competition which focuses on Industrial Control Systems (ICS) security. We were proud to take part in this competition and join other researchers in the effort to make mission-critical industrial environments safe and secure.
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
OPC UA (Open Platform Communications United Architecture) is a protocol that lets industrial devices and endpoint clients send and receive data in a secure and reliable way. Its main advantage is a unified API: a client can reach data collected by all sorts of industrial devices through one standard interface instead of implementing a vendor-specific API for each device. Because the API is standardised, any device on either side of the connection, client or server, can be replaced transparently by a different OPC UA compliant device, even from another manufacturer, and communications persist without major changes.

The protocol is widely used by major ICS vendors such as Siemens, Bosch, Rockwell Automation and ABB. The JFrog Security Research team stresses that these vendors and products are only used as OPC UA examples and that it did not test whether they are susceptible to the DoS vulnerabilities described here. For instance, the Siemens S7 series automation controllers use OPC UA:

Denial-of-service bugs in industrial control systems matter because they can disrupt critical operations. On controllers used for motion control, a DoS can interrupt a factory's production line or cause physical damage through misalignments between moving parts.
The team competed in Pwn2Own Miami 2022, an ICS-focused contest, and won in two categories: Denial of Service on the OPC UA C++ server, and Denial of Service on the OPC UA .NET server (CVE-2022-29866).

Setup
Two targets were used, both reference implementations rather than vendor products:
- The OPC UA .NET Standard server, an implementation of an OPC UA server in C# provided by the OPC Foundation. According to GitHub, it is used by 286 other repositories, including Microsoft's Industrial-IoT repository, which discovers industrial assets on-site and automatically registers them in the cloud.
- Unified Automation's OPC UA C++ demo server, an implementation in C++ provided by Unified Automation as a reference for an OPC UA server implementation. The code discussed comes from the "C++ based OPC UA Client/Server SDK + Pub/Sub Bundle", which contains the demo server as an example.
The targets at Pwn2Own ran on the latest Windows 10 64-bit with every mitigation technique enabled (ASLR, NX and so on), because ZDI wanted the environment as close to reality as possible. The contest allows only 3 re-tries.
Finding it
OPC UA .NET Standard stack exhaustion (CVE-2022-29866)
The server could be crashed with a stack exhaustion bug leading to denial of service. There is a recursion in the code that handles the TranslateBrowsePathsToNodeId request. The recursion can make the server crash with a Stack Overflow exception once the maximum recursion limit is exceeded, and that exception cannot be caught by a try..catch block. All versions before 1.4.368.58 are affected.
The recursion lies in MasterNodeManager.cs::TranslateBrowsePath():
private void TranslateBrowsePath(
OperationContext context,
INodeManager nodeManager,
object sourceHandle,
RelativePath relativePath,
BrowsePathTargetCollection targets,
int index)
{
...
// check for end of list.
if (index < 0 || index >= relativePath.Elements.Count)
{
return;
}
...
// process next hops.
for (int ii = 0; ii < targetIds.Count; ii++)
{
...
// recursively follow hops.
TranslateBrowsePath(
context,
nodeManager,
sourceHandle,
relativePath,
targets,
index + 1);
}
}
This function handles the TranslateBrowsePathsToNodeIds request specified in the OPC UA reference, Part 4, section 5.8.4:

The function is first called with the startingNode and is subsequently called recursively according to the elements in relativePath, where each element's format is:

For example, given a browsePath with startingNode = "NodeA" and relativePath defined as:
TargetName = "NodeB"
IsInverse = False
referenceTypeId = HasComponent |
TargetName = "NodeC"
referenceTypeId = HasComponent |
The server will resolve the browsePath as:

and return NodeC's nodeId. The bug is that there is no limit on the number of recursive calls, so a long enough relativePath makes the code throw a StackOverflowException when it reaches the environment's maximum recursion limit. As noted, that exception cannot be caught with try..catch. From MSDN: "Starting with the .NET Framework 2.0, you can't catch a StackOverflowException object with a try/catch block, and the corresponding process is terminated by default".
Unified Automation C++ demo server use-after-free
In the C++ demo server there is a use-after-free that can cause denial of service and possibly remote code execution. It is caused by a lack of synchronisation primitives when calling two specific methods that the demo server exports to the user.
OPC UA lets the server export methods that a client can call, in a similar fashion to RPC, by sending the Call message. Exported methods can be called asynchronously. Demo_DynamicNodes_CreateDynamicNode and Demo_DynamicNodes_DeleteDynamicNode are methods exported by the server for the client to call, and the race condition between them produces the UaF.
Exploitation
Step 1: build a long relativePath that still points to an existing node
Two obstacles stood in the way of building a long relativePath:
- The path must eventually point to an existing node.
- The TCP-based OPC protocol does not allow a packet larger than 64KB.
For the first obstacle the team used a method similar to path/directory traversal, the equivalent of ../Directory/../Directory/../Directory. When the server translates a relativePath, it starts with the startingNode and walks through the relativePath elements, which guide the server between nodes. Each element also has a flag called isInverse that tells the code whether to traverse to one of the node's parents (True) instead of one of the node's children (False).
To make sure an existing node is used, the team picked a node in namespace 0. A namespace defines a set of types; namespace 0 is a built-in namespace containing all of the standard types of the server. The team used one of the standard types of namespace 0, RelativePath. The malicious request includes a single browsePath with a startingNode named "RelativePath" and a relativePath that looks like this:

"HasEncoding" and "EncodingOf" are actually the same referenceTypeId, but they got different names because of the IsInverse field. Sending this request results in the following recursion, which lets the attacker send a large packet while always pointing to an existing node:

Step 2: avoid the TCP size limit with the HTTP-based protocol
For the second obstacle the team used the HTTP-based OPC protocol instead of the raw TCP-based one. The HTTP-based protocol has a larger maximum size limit, allowing a maximum packet size of 4MB, much more accommodating than the 64KB limit of the TCP-based protocol.
To successfully crash the OPC server in the team's environment, at least 7000 elements were needed in the relative path. The exploit uses 65534 elements (one less than the default config's max array size) to make sure the payload crashes as many configurations as possible.
Step 3: crash the server
The exploit crashes both the ConsoleReferenceServer and the ReferenceServer (a GUI version of the server). After sending the exploit, the ConsoleReferenceServer crashes with a StackOverflowException:

The ReferenceServer crashes without printing anything.
Step 4: race the two exported methods on the C++ demo server
Consider the following code from the two exported functions:
UaStatus NodeManagerDemo::Demo_DynamicNodes_CreateDynamicNode(const ServiceContext& serviceContext)
{
UaStatus ret;
if ( m_pDynamicNode != NULL ) // m_pDynamicNode is a property of the node manager
{
// The node is already created
return OpcUa_BadInvalidState;
}
...
m_pDynamicNode = new OpcUa::FolderType(
UaNodeId(UaGuid::create(), getNameSpaceIndex()),
"New Dynamic Node",
getNameSpaceIndex(),
this);
ret = addNodeAndReference(pDynamicNodes->getUaReferenceLists(), m_pDynamicNode, OpcUaId_Organizes);
if ( ret.isNotGood() )
{
// Adding the node failed
// Release the node since the NodeManager did not take over ownership
m_pDynamicNode->releaseReference();
m_pDynamicNode = NULL;
return ret;
}
else
{
UaVariant defaultValue;
OpcUa::DataItemType* pVariable = NULL;
defaultValue.setUInt32(0);
pVariable = new OpcUa::DataItemType(
UaNodeId("Demo.DynamicNodes.Variable1", getNameSpaceIndex()),
"Variable1",
getNameSpaceIndex(),
defaultValue,
OpcUa_AccessLevels_CurrentReadOrWrite,
this);
ret = addNodeAndReference(m_pDynamicNode, pVariable, OpcUaId_HasComponent);
....
}
return ret;
}
UaStatus NodeManagerDemo::Demo_DynamicNodes_DeleteDynamicNode(const ServiceContext& serviceContext)
{
UaStatus ret;
if ( m_pDynamicNode == NULL )
{
// The node is not created yet
return OpcUa_BadInvalidState;
}
...
ret = deleteUaNode(m_pDynamicNode, OpcUa_True, OpcUa_True, OpcUa_True);
// Release our reference to the node
m_pDynamicNode->releaseReference();
m_pDynamicNode = NULL;
return ret;
}
Neither function uses a mutex to ensure that the object pointed to by m_pDynamicNode is not changed in the middle of the function's execution. When releaseReference() is called and the refcount reaches 0, the object destructor is called:
int __thiscall ReferenceCounter::releaseReference(ReferenceCounter *this)
{
int currentCount;
ReferenceCounter *thisa
thisa = this;
currentCount = ua_atomic_decrement(&this->m_refCount);
if ( !currentCount && thisa )
(thisa->~ReferenceCounter)(thisa, 1);
return currentCount;
}
That free, combined with the fact that Demo_DynamicNodes_CreateDynamicNode and Demo_DynamicNodes_DeleteDynamicNode can be called in parallel, causes the UaF. An attacker may simultaneously and repeatedly call both methods using OPC UA's call message. These invocations can happen in the middle of the execution of addNodeAndReference. While Demo.DynamicNodes.Variable1 is being added, another thread runs Demo_DynamicNodes_DeleteDynamicNode and executes releaseReference, which calls the destructor. The FolderType object is then used after it was freed, causing a crash due to a virtual function call with a garbage pointer, for example inside NodeManagerUaNode::addUaReference in the bold line:
UaStatus *__thiscall NodeManagerUaNode::addUaReference(NodeManagerUaNode *this, UaStatus *result, UaReferenceLists *pSourceNode, UaReferenceLists *pTargetNode, const UaNodeId *referenceTypeId)
{
…
pNewReference = 0;
…
pNewReference = some_reference // NewReference get assigned
if ( pNewReference )
{
…
pSourceNode->addTargetNode(pSourceNode, pNewReference);
…
}
…
return result
Here pSourceNode is m_pDynamicNode. This either crashes on a dereference of an illegal address (for example vptr will be 0) or can be used for remote code execution if the attacker can allocate the freed object and direct its vptr to a fake vtable.
The lack of a locking primitive can be exploited in further ways, such as calling Demo_DynamicNodes_DeleteDynamicNode simultaneously from two threads. Depending on timing, both threads may pass the NULL check of m_pDynamicNode, causing a similar UaF, or the slower thread may crash on a NULL pointer dereference when calling releaseReference() with m_pDynamicNode as NULL.
Step 5: trigger the race
The race condition is triggered easily by spawning two threads, one calling Demo.DynamicNodes.CreateDynamicNode and the other Demo.DynamicNodes.DeleteDynamicNode. This method reliably crashes the server.
Step 6: attempt RCE from the UaF
Within the boundaries of Pwn2Own the team could not exploit the UaF for remote code execution, due to time and stability constraints. The intended strategy was:
- Spawn another thread that tries to make an allocation of the same size as
m_pDynamicNode, to grab the freed object from the allocator. - Spray a fake vtable in the heap. The vtable would contain a stack pivot gadget giving more control over the eventual ROP chain. The C++ server allows writing an arbitrary size array of strings with the input, and each of those strings can serve as the fake vtable with the gadgets.
- Pop a shell using the ROP chain.
The userspace frontend heap allocator in Windows 10 is called segment heap; for this allocation size it uses a heap allocator called LFH (Low Fragmentation Heap).
This makes exploitation difficult because free chunks are randomised on every malloc operation, compared with Glibc's default ptmalloc2, which would return the last freed block. If the freed object is not rewritten before the vtable call, the process crashes, which prevents simply allocating the right object over and over until it succeeds. The team's statistics for grabbing the freed object were too low for Pwn2Own, even with heap shaping methods.
Root cause
In the .NET server, TranslateBrowsePath() recurses once per element of relativePath with no depth limit. The request format lets a client supply an arbitrarily long element list, and the only practical ceiling is the transport's maximum packet size. Because a StackOverflowException cannot be caught by try..catch and terminates the process by default, the recursion depth is effectively a remote kill switch. The traversal trick with isInverse and a namespace 0 node such as RelativePath defeats the requirement that the path resolve to an existing node, and the HTTP-based OPC transport raises the packet ceiling from 64KB to 4MB, which is enough room for the element count needed.
In the C++ demo server, Demo_DynamicNodes_CreateDynamicNode and Demo_DynamicNodes_DeleteDynamicNode read and write the shared m_pDynamicNode pointer and call releaseReference() without a mutex. Since exported methods can be called asynchronously, one thread can free the FolderType object through releaseReference() while another is still using it inside addNodeAndReference, producing a virtual call through a dangling pointer. The same missing lock allows two delete calls to both pass the NULL check.
Impact
Both bugs are denial of service. On the .NET server, a single crafted TranslateBrowsePathsToNodeIds request over the HTTP-based OPC protocol crashes the ConsoleReferenceServer and the ReferenceServer. On the C++ demo server, two threads repeatedly calling the create and delete methods reliably crash the server. The C++ UaF can also potentially lead to remote code execution, but the team did not achieve a stable RCE exploit within the contest. The report frames the wider risk in industrial terms: disrupting a controller used for motion control can interrupt a production line or cause physical damage through misaligned moving parts. The vendor products named as OPC UA users were not tested for susceptibility.
Fix
All versions before 1.4.368.58 are affected; the report does not describe the code change itself. The report does not describe the code change itself. For the C++ demo server, the report identifies the missing synchronisation: the two exported methods need a locking primitive so that the object pointed to by m_pDynamicNode cannot be freed or replaced in the middle of another call, and so that two concurrent deletes cannot both pass the NULL check.
Variants to test
- Other recursive request handlers in OPC UA stacks. Look for handlers that walk a client-supplied list, such as browse paths, and recurse per element. A positive result is a request with a long element list that terminates the server process with a stack overflow rather than returning a service error.
- Other transports with larger packet limits. If the TCP-based OPC protocol caps packets at 64KB, try the HTTP-based OPC protocol, which allows up to 4MB. A positive result is a payload that exceeds the TCP limit and still reaches the vulnerable handler.
- Traversal-style paths that always resolve. Use
isInverseto alternate between a node and its parent, as withHasEncodingandEncodingOf, so a long path still ends on an existing node. A positive result is a longrelativePaththat the server accepts and resolves instead of rejecting as invalid. - Exported methods that mutate shared state. Enumerate the methods a server exports through the
Callmessage and look for pairs that create and delete the same object. A positive result is a crash when one thread calls create while another calls delete. - Double-delete races. Call the delete method from two threads at once. A positive result is a use-after-free or a NULL pointer dereference in
releaseReference()when both threads pass the NULL check. - Heap grooming against LFH. On Windows 10, try to reclaim a freed object of the same size before the virtual call. A positive result is control of the
vptrand a crash at an address you chose rather than at 0.
What happened, in plain words
A team of security researchers from JFrog took part in a hacking contest called Pwn2Own Miami 2022. This contest is unusual because it focuses on industrial control systems: the computers and software that run factories, power plants and machines. Contestants try to make these systems misbehave, and the organisers watch and score the attempts.
The team found two ways to crash industrial software that speaks a language called OPC UA. One crash affects a server written in C# (a programming language from Microsoft), the other affects a server written in C++. Both crashes are denial-of-service bugs: the attacker does not steal data, they simply make the program stop working. In a factory, a program that stops working can halt a production line or, on a machine with moving parts, cause physical damage.
The team won in two categories at the contest: Denial of Service on the OPC UA C++ server, and Denial of Service on the OPC UA .NET server, which was given the identifier CVE-2022-29866. A CVE is a public catalogue number for a known security flaw, so people can look it up and track fixes.

What OPC UA is, and why it matters
OPC UA stands for Open Platform Communications United Architecture. It is a set of rules, a protocol, that lets industrial devices and the programs that talk to them exchange data in a secure and reliable way. Think of it as a common language: instead of every manufacturer inventing its own words, everyone agrees on the same vocabulary.
The biggest advantage is what the report calls a unified API. An API is an interface: a fixed list of requests a program can make and answers it will get back, like a restaurant menu you can order from without knowing what happens in the kitchen. With OPC UA, one client program can ask for data from all sorts of industrial devices through the same menu, instead of learning a different menu for each brand.
Because the menu is standardised, any device on either side of the connection, the client or the server, can be swapped for a different OPC UA compliant device, even one from another manufacturer, and the conversation carries on without major changes. The report illustrates this with a diagram:

The protocol is widely used by major industrial vendors such as Siemens, Bosch, Rockwell Automation and ABB. The researchers are careful to say that these vendors and products are only used as examples of OPC UA users, and that they did not test whether those products are susceptible to the bugs described here. For instance, the Siemens S7 series automation controllers use OPC UA:

Why does a denial-of-service bug in an industrial control system matter? On controllers used for motion control, a DoS can interrupt a factory's production line, or cause physical damage through misalignments between moving parts.
The two targets
The team worked on two pieces of software, both reference implementations rather than products sold by a vendor. A reference implementation is a working example published so that others can learn from it or build on it.
- The OPC UA .NET Standard server, an implementation of an OPC UA server in C# provided by the OPC Foundation. According to GitHub, it is used by 286 other repositories, including Microsoft's Industrial-IoT repository, which discovers industrial assets on-site and automatically registers them in the cloud. A repository is a shared code project; being used by 286 others means the code is widely reused, so a bug in it travels far.
- Unified Automation's OPC UA C++ demo server, an implementation in C++ provided by Unified Automation as a reference for an OPC UA server implementation. The code discussed comes from the "C++ based OPC UA Client/Server SDK + Pub/Sub Bundle", which contains the demo server as an example. An SDK is a software development kit: a box of ready-made parts that programmers use to build their own programs.
At Pwn2Own the targets ran on the latest Windows 10 64-bit with every mitigation technique enabled, such as ASLR and NX, because the organisers, ZDI, wanted the environment as close to reality as possible. Mitigations are defences built into the operating system that make attacks harder; ASLR shuffles where things sit in memory, and NX marks certain memory as not executable. The contest also allows only 3 re-tries, so an exploit has to work reliably, not just once in a while.
Finding the first bug: the .NET server runs out of stack
The first bug is a stack exhaustion. To understand it, picture a stack of sticky notes. Every time a function calls another function, the program puts a new note on the stack to remember where to return. If functions keep calling each other without stopping, the pile grows until it hits the ceiling of the desk. In computing, that ceiling is the maximum recursion limit, and hitting it throws a StackOverflowException, which crashes the process.
Recursion means a function that calls itself. The .NET server has a recursion in the code that handles the TranslateBrowsePathsToNodeId request. A request is a message a client sends to a server asking it to do something. This particular request asks the server to translate a browse path, which is a route through the server's tree of nodes. A node is a named item in that tree, such as a folder or a value.
The recursion can make the server crash with a Stack Overflow exception once the maximum recursion limit is exceeded, and that exception cannot be caught by a try..catch block. A try..catch block is the usual way a program handles an error: it tries something and catches the failure so it can carry on. A stack overflow is special: the program has no room left to run the catching code, so the whole process is terminated. All versions before 1.4.368.58 are affected.
The recursion lies in MasterNodeManager.cs::TranslateBrowsePath(). The .cs tells you this is a C# source file, and the name after :: is the function inside it:
private void TranslateBrowsePath(
OperationContext context,
INodeManager nodeManager,
object sourceHandle,
RelativePath relativePath,
BrowsePathTargetCollection targets,
int index)
{
...
// check for end of list.
if (index < 0 || index >= relativePath.Elements.Count)
{
return;
}
...
// process next hops.
for (int ii = 0; ii < targetIds.Count; ii++)
{
...
// recursively follow hops.
TranslateBrowsePath(
context,
nodeManager,
sourceHandle,
relativePath,
targets,
index + 1);
}
}
Line by line:
private void TranslateBrowsePath(starts the definition of a function that returns nothing (void) and can only be used inside its own class (private).- The parameters are the pieces of information the function needs:
context(details about the current operation),nodeManager(the component that owns the nodes),sourceHandle(a handle to the starting point),relativePath(the route to follow),targets(where results are collected) andindex(how far along the route we are). if (index < 0 || index >= relativePath.Elements.Count)checks whether we have walked past the end of the route.relativePath.Elements.Countis the number of steps in the route.return;stops the function when the route is finished. This is the only exit condition.for (int ii = 0; ii < targetIds.Count; ii++)loops over every place the current step can lead to.TranslateBrowsePath(inside the loop calls the very same function again, passingindex + 1, so it moves one step further along the route. This is the recursion.- The closing braces end the loop and the function.
The important detail is that nothing counts how deep the recursion has gone. Each step along the route adds another call to the pile, and a long enough route pushes the pile past the ceiling.
This function handles the TranslateBrowsePathsToNodeIds request specified in the OPC UA reference, Part 4, section 5.8.4:

The function is first called with the startingNode, the node where the route begins, and is then called recursively according to the elements in relativePath. Each element's format is:

For example, given a browsePath with startingNode = "NodeA" and relativePath defined as:
TargetName = "NodeB"
IsInverse = False
referenceTypeId = HasComponent |
TargetName = "NodeC"
referenceTypeId = HasComponent |
This is a route with two steps. The first step says: from the current node, go to a child named NodeB, following a relationship of type HasComponent. IsInverse = False means go downwards to a child rather than upwards to a parent. The second step says: from there, go to a child named NodeC, again following HasComponent.
The server will resolve the browsePath as:

and return NodeC's nodeId. A nodeId is the unique identifier of a node, like a house number. The bug is that there is no limit on the number of recursive calls, so a long enough relativePath makes the code throw a StackOverflowException when it reaches the environment's maximum recursion limit. As noted, that exception cannot be caught with try..catch. From MSDN, Microsoft's developer documentation: "Starting with the .NET Framework 2.0, you can't catch a StackOverflowException object with a try/catch block, and the corresponding process is terminated by default".
The second bug: the C++ server uses memory after freeing it
The second bug is a use-after-free, often shortened to UaF. To picture it, imagine borrowing a library book, returning it, and then reading from it anyway. The library may have lent it to someone else, or thrown it away; whatever you read is no longer yours. In a program, a use-after-free happens when code frees a block of memory and then keeps using it. The result can be a crash, and sometimes an attacker can arrange for the freed block to be replaced with data they control, which can lead to remote code execution: making the server run the attacker's commands.
In the C++ demo server there is a use-after-free that can cause denial of service and possibly remote code execution. It is caused by a lack of synchronisation primitives when calling two specific methods that the demo server exports to the user. A synchronisation primitive is a lock: a way to make sure two parts of a program do not touch the same thing at the same time, like a bathroom key that only one person can hold.
OPC UA lets the server export methods that a client can call, in a similar fashion to RPC, by sending the Call message. RPC means remote procedure call: asking a program on another machine to run one of its functions as if it were local. Exported methods can be called asynchronously, meaning several calls can be in progress at once rather than one after another. Demo_DynamicNodes_CreateDynamicNode and Demo_DynamicNodes_DeleteDynamicNode are methods exported by the server for the client to call, and the race condition between them produces the UaF. A race condition is what happens when two actions run at the same time and the outcome depends on which one gets there first.
Step 1: build a long relativePath that still points to an existing node
To trigger the stack overflow, the attacker needs a very long route. Two obstacles stood in the way:
- The path must eventually point to an existing node.
- The TCP-based OPC protocol does not allow a packet larger than 64KB. A packet is a chunk of data sent over a network, and 64KB is roughly 64,000 bytes, not much room for a long route.
For the first obstacle the team used a method similar to path/directory traversal, the equivalent of ../Directory/../Directory/../Directory. On a computer, .. means the folder above the current one, so this trick walks up and down repeatedly while always landing somewhere real. When the server translates a relativePath, it starts with the startingNode and walks through the relativePath elements, which guide the server between nodes. Each element also has a flag called isInverse that tells the code whether to traverse to one of the node's parents (True) instead of one of the node's children (False).
To make sure an existing node is used, the team picked a node in namespace 0. A namespace defines a set of types; namespace 0 is a built-in namespace containing all of the standard types of the server, so its contents are guaranteed to be present. The team used one of the standard types of namespace 0, RelativePath. The malicious request includes a single browsePath with a startingNode named "RelativePath" and a relativePath that looks like this:

"HasEncoding" and "EncodingOf" are actually the same referenceTypeId, but they got different names because of the IsInverse field. Sending this request results in the following recursion, which lets the attacker send a large packet while always pointing to an existing node:

Step 2: avoid the TCP size limit with the HTTP-based protocol
For the second obstacle the team used the HTTP-based OPC protocol instead of the raw TCP-based one. HTTP is the protocol your browser uses to load web pages. The HTTP-based protocol has a larger maximum size limit, allowing a maximum packet size of 4MB, much more accommodating than the 64KB limit of the TCP-based protocol. That is roughly sixty-four times more room.
To successfully crash the OPC server in the team's environment, at least 7000 elements were needed in the relative path. The exploit uses 65534 elements (one less than the default config's max array size) to make sure the payload crashes as many configurations as possible. A payload is the malicious content of the request, and an array is an ordered list of items; staying one below the default maximum is meant to crash as many configurations as possible.
Step 3: crash the server
The exploit crashes both the ConsoleReferenceServer and the ReferenceServer (a GUI version of the server). GUI means graphical user interface: the version with windows and buttons, as opposed to the text-only console version. After sending the exploit, the ConsoleReferenceServer crashes with a StackOverflowException:

The ReferenceServer crashes without printing anything.
Step 4: race the two exported methods on the C++ demo server
Now for the second bug. Consider the following code from the two exported functions:
UaStatus NodeManagerDemo::Demo_DynamicNodes_CreateDynamicNode(const ServiceContext& serviceContext)
{
UaStatus ret;
if ( m_pDynamicNode != NULL ) // m_pDynamicNode is a property of the node manager
{
// The node is already created
return OpcUa_BadInvalidState;
}
...
m_pDynamicNode = new OpcUa::FolderType(
UaNodeId(UaGuid::create(), getNameSpaceIndex()),
"New Dynamic Node",
getNameSpaceIndex(),
this);
ret = addNodeAndReference(pDynamicNodes->getUaReferenceLists(), m_pDynamicNode, OpcUaId_Organizes);
if ( ret.isNotGood() )
{
// Adding the node failed
// Release the node since the NodeManager did not take over ownership
m_pDynamicNode->releaseReference();
m_pDynamicNode = NULL;
return ret;
}
else
{
UaVariant defaultValue;
OpcUa::DataItemType* pVariable = NULL;
defaultValue.setUInt32(0);
pVariable = new OpcUa::DataItemType(
UaNodeId("Demo.DynamicNodes.Variable1", getNameSpaceIndex()),
"Variable1",
getNameSpaceIndex(),
defaultValue,
OpcUa_AccessLevels_CurrentReadOrWrite,
this);
ret = addNodeAndReference(m_pDynamicNode, pVariable, OpcUaId_HasComponent);
....
}
return ret;
}
Line by line:
UaStatus NodeManagerDemo::Demo_DynamicNodes_CreateDynamicNode(...)defines the create function.UaStatusis the function's return value, a status code saying whether it worked.UaStatus ret;declares a variable to hold that status.if ( m_pDynamicNode != NULL )checks whether a node already exists.m_pDynamicNodeis a pointer, a variable that holds the address of an object in memory, andNULLmeans it points at nothing.return OpcUa_BadInvalidState;refuses the request if a node is already there.m_pDynamicNode = new OpcUa::FolderType(...)creates a new folder object and stores its address inm_pDynamicNode.newis the C++ instruction that reserves memory for an object.ret = addNodeAndReference(...)attaches the new folder to the server's tree.if ( ret.isNotGood() )handles failure: if attaching failed, the code callsm_pDynamicNode->releaseReference();to give up its claim on the object, then setsm_pDynamicNode = NULL;so nothing points at it any more.- In the
elsebranch, the code creates a second object, a data item namedDemo.DynamicNodes.Variable1, and attaches it to the folder withaddNodeAndReference(m_pDynamicNode, pVariable, OpcUaId_HasComponent);. return ret;reports the final status.
UaStatus NodeManagerDemo::Demo_DynamicNodes_DeleteDynamicNode(const ServiceContext& serviceContext)
{
UaStatus ret;
if ( m_pDynamicNode == NULL )
{
// The node is not created yet
return OpcUa_BadInvalidState;
}
...
ret = deleteUaNode(m_pDynamicNode, OpcUa_True, OpcUa_True, OpcUa_True);
// Release our reference to the node
m_pDynamicNode->releaseReference();
m_pDynamicNode = NULL;
return ret;
}
Line by line:
- The function signature is the same shape as the create function, but this one deletes.
if ( m_pDynamicNode == NULL )checks whether there is nothing to delete, and returns an error if so.ret = deleteUaNode(m_pDynamicNode, ...)removes the node from the server's tree.m_pDynamicNode->releaseReference();gives up the code's claim on the object. When the last claim is given up, the object's memory is freed.m_pDynamicNode = NULL;clears the pointer so it no longer refers to the freed object.
Neither function uses a mutex to ensure that the object pointed to by m_pDynamicNode is not changed in the middle of the function's execution. A mutex is the lock described earlier: without it, one function can be halfway through its work when the other function changes the shared pointer underneath it. When releaseReference() is called and the refcount reaches 0, the object destructor is called. A refcount is a counter of how many owners an object has; when it drops to zero, nobody needs the object, so the destructor, the cleanup code that runs when an object dies, frees it:
int __thiscall ReferenceCounter::releaseReference(ReferenceCounter *this)
{
int currentCount;
ReferenceCounter *thisa
thisa = this;
currentCount = ua_atomic_decrement(&this->m_refCount);
if ( !currentCount && thisa )
(thisa->~ReferenceCounter)(thisa, 1);
return currentCount;
}
Line by line:
int __thiscall ReferenceCounter::releaseReference(...)defines a function that returns an integer, the new count.int currentCount;andReferenceCounter *thisadeclare local variables.thisa = this;copies the pointer to the object into a local variable.currentCount = ua_atomic_decrement(&this->m_refCount);decreases the reference count by one. The word atomic means the decrease happens as a single indivisible step, so two threads cannot both read the old value and both write the same new one.if ( !currentCount && thisa )checks whether the count has reached zero and the pointer is valid.(thisa->~ReferenceCounter)(thisa, 1);calls the destructor, which frees the object.return currentCount;hands the new count back to the caller.
That free, combined with the fact that Demo_DynamicNodes_CreateDynamicNode and Demo_DynamicNodes_DeleteDynamicNode can be called in parallel, causes the UaF. An attacker may simultaneously and repeatedly call both methods using OPC UA's call message. These invocations can happen in the middle of the execution of addNodeAndReference. While Demo.DynamicNodes.Variable1 is being added, another thread runs Demo_DynamicNodes_DeleteDynamicNode and executes releaseReference, which calls the destructor. A thread is one line of execution inside a program; a program can run several at once. The FolderType object is then used after it was freed, causing a crash due to a virtual function call with a garbage pointer, for example inside NodeManagerUaNode::addUaReference in the bold line:
UaStatus *__thiscall NodeManagerUaNode::addUaReference(NodeManagerUaNode *this, UaStatus *result, UaReferenceLists *pSourceNode, UaReferenceLists *pTargetNode, const UaNodeId *referenceTypeId)
{
…
pNewReference = 0;
…
pNewReference = some_reference // NewReference get assigned
if ( pNewReference )
{
…
pSourceNode->addTargetNode(pSourceNode, pNewReference);
…
}
…
return result
Line by line:
- The function signature takes a source node, a target node and a reference type, and returns a status pointer.
pNewReference = 0;starts with an empty reference.pNewReference = some_referenceassigns a real reference.if ( pNewReference )checks that the reference is not empty.pSourceNode->addTargetNode(pSourceNode, pNewReference);uses the source node to add the target. This is the dangerous line: ifpSourceNodehas already been freed, the program is reading from memory it no longer owns.return resulthands back the status.
Here pSourceNode is m_pDynamicNode. This either crashes on a dereference of an illegal address (for example vptr will be 0) or can be used for remote code execution if the attacker can allocate the freed object and direct its vptr to a fake vtable. A vptr is a hidden pointer inside an object that tells the program which functions belong to it, and a vtable is the table those pointers point into. If an attacker can control the vptr, they can make the program call a function of their choosing.
The lack of a locking primitive can be exploited in further ways, such as calling Demo_DynamicNodes_DeleteDynamicNode simultaneously from two threads. Depending on timing, both threads may pass the NULL check of m_pDynamicNode, causing a similar UaF, or the slower thread may crash on a NULL pointer dereference when calling releaseReference() with m_pDynamicNode as NULL. A NULL pointer dereference means the program tries to use address zero, which is never valid, so it crashes.
Step 5: trigger the race
The race condition is triggered easily by spawning two threads, one calling Demo.DynamicNodes.CreateDynamicNode and the other Demo.DynamicNodes.DeleteDynamicNode. Spawning means starting a new thread. This method reliably crashes the server.
Step 6: attempt RCE from the UaF
Within the boundaries of Pwn2Own the team could not exploit the UaF for remote code execution, due to time and stability constraints. The intended strategy was:
- Spawn another thread that tries to make an allocation of the same size as
m_pDynamicNode, to grab the freed object from the allocator. An allocator is the part of the program that hands out memory when something asks for it. - Spray a fake vtable in the heap. The vtable would contain a stack pivot gadget giving more control over the eventual ROP chain. Spraying means filling memory with many copies of the same data so that one of them lands where it is needed. A gadget is a small existing piece of code that does something useful to an attacker, a stack pivot redirects execution to a place the attacker controls, and a ROP chain is a sequence of such gadgets stitched together to perform an action. The C++ server allows writing an arbitrary size array of strings with the input, and each of those strings can serve as the fake vtable with the gadgets.
- Pop a shell using the ROP chain. Popping a shell means getting a command prompt on the victim machine.
The userspace frontend heap allocator in Windows 10 is called segment heap; for this allocation size it uses a heap allocator called LFH (Low Fragmentation Heap). The heap is the pool of memory a program uses for objects it creates while running.
This makes exploitation difficult because free chunks are randomised on every malloc operation, compared with Glibc's default ptmalloc2, which would return the last freed block. malloc is the C function that asks the allocator for memory, and Glibc is the standard C library on Linux. If the freed object is not rewritten before the vtable call, the process crashes, which prevents simply allocating the right object over and over until it succeeds. The team's statistics for grabbing the freed object were too low for Pwn2Own, even with heap shaping methods. Heap shaping means arranging earlier allocations so that the next one lands in a favourable spot.
Root cause
In the .NET server, TranslateBrowsePath() recurses once per element of relativePath with no depth limit. The request format lets a client supply an arbitrarily long element list, and the only practical ceiling is the transport's maximum packet size. Because a StackOverflowException cannot be caught by try..catch and terminates the process by default, the recursion depth is effectively a remote kill switch. The traversal trick with isInverse and a namespace 0 node such as RelativePath defeats the requirement that the path resolve to an existing node, and the HTTP-based OPC transport raises the packet ceiling from 64KB to 4MB, which is enough room for the element count needed.
In the C++ demo server, Demo_DynamicNodes_CreateDynamicNode and Demo_DynamicNodes_DeleteDynamicNode read and write the shared m_pDynamicNode pointer and call releaseReference() without a mutex. Since exported methods can be called asynchronously, one thread can free the FolderType object through releaseReference() while another is still using it inside addNodeAndReference, producing a virtual call through a dangling pointer. A dangling pointer is a pointer to memory that has already been freed. The same missing lock allows two delete calls to both pass the NULL check.
Impact
Both bugs are denial of service. On the .NET server, a single crafted TranslateBrowsePathsToNodeIds request over the HTTP-based OPC protocol crashes the ConsoleReferenceServer and the ReferenceServer. On the C++ demo server, two threads repeatedly calling the create and delete methods reliably crash the server. The C++ UaF can also potentially lead to remote code execution, but the team did not achieve a stable RCE exploit within the contest. The report frames the wider risk in industrial terms: disrupting a controller used for motion control can interrupt a production line or cause physical damage through misaligned moving parts. The vendor products named as OPC UA users were not tested for susceptibility.
Fix
The .NET issue was fixed in version 1.4.368.58; all earlier versions are affected. The report does not describe the code change itself. For the C++ demo server, the report identifies the missing synchronisation: the two exported methods need a locking primitive so that the object pointed to by m_pDynamicNode cannot be freed or replaced in the middle of another call, and so that two concurrent deletes cannot both pass the NULL check. The report does not state whether Unified Automation shipped a fix.
Variants to test
- Other recursive request handlers in OPC UA stacks. Look for handlers that walk a client-supplied list, such as browse paths, and recurse per element. A positive result is a request with a long element list that terminates the server process with a stack overflow rather than returning a service error.
- Other transports with larger packet limits. If the TCP-based OPC protocol caps packets at 64KB, try the HTTP-based OPC protocol, which allows up to 4MB. A positive result is a payload that exceeds the TCP limit and still reaches the vulnerable handler.
- Traversal-style paths that always resolve. Use
isInverseto alternate between a node and its parent, as withHasEncodingandEncodingOf, so a long path still ends on an existing node. A positive result is a longrelativePaththat the server accepts and resolves instead of rejecting as invalid. - Exported methods that mutate shared state. Enumerate the methods a server exports through the
Callmessage and look for pairs that create and delete the same object. A positive result is a crash when one thread calls create while another calls delete. - Double-delete races. Call the delete method from two threads at once. A positive result is a use-after-free or a NULL pointer dereference in
releaseReference()when both threads pass the NULL check. - Heap grooming against LFH. On Windows 10, try to reclaim a freed object of the same size before the virtual call. A positive result is control of the
vptrand a crash at an address you chose rather than at 0.
Glossary
- API: a fixed list of requests a program can make to another program, and the answers it gets back.
- ASLR: a defence that randomises where things sit in memory, so an attacker cannot rely on fixed addresses.
- Array: an ordered list of items stored together.
- Asynchronous: able to run several calls at the same time rather than one after another.
- Atomic: an operation that happens as a single indivisible step, so two threads cannot interfere with it.
- C#: a programming language from Microsoft, used for the .NET server.
- C++: a programming language often used for performance-critical software, used for the demo server.
- CVE: a public catalogue number for a known security flaw.
- Dangling pointer: a pointer to memory that has already been freed.
- Denial of service (DoS): an attack that makes a service stop working for legitimate users.
- Destructor: the cleanup code that runs when an object is destroyed.
- Exploit: the concrete input or program that triggers a vulnerability.
- Gadget: a small existing piece of code that an attacker reuses to build an attack.
- GUI: graphical user interface, the version of a program with windows and buttons.
- Heap: the pool of memory a program uses for objects it creates while running.
- Heap shaping: arranging earlier memory allocations so that a later one lands in a favourable spot.
- HTTP: the protocol browsers use to load web pages, also usable for carrying larger request bodies.
- ICS: industrial control systems, the computers and software that run factories and plants.
- LFH (Low Fragmentation Heap): a Windows heap allocator used for small allocations.
- malloc: the C function that asks the allocator for memory.
- Mitigation: a defence built into an operating system or program that makes attacks harder.
- Mutex: a lock that ensures only one part of a program touches a shared thing at a time.
- Namespace: a named set of types; namespace 0 is the built-in set of standard types.
- Node: a named item in the server's tree, such as a folder or a value.
- nodeId: the unique identifier of a node.
- NX: a defence that marks certain memory as not executable.
- OPC UA: Open Platform Communications United Architecture, a standard protocol for industrial data exchange.
- Packet: a chunk of data sent over a network.
- Payload: the malicious content of a request.
- Pointer: a variable that holds the address of an object in memory.
- Protocol: an agreed set of rules for exchanging data.
- Race condition: a situation where two actions run at the same time and the outcome depends on which finishes first.
- Recursion: a function that calls itself.
- Refcount: a counter of how many owners an object has; at zero, the object is freed.
- Remote code execution (RCE): making a remote machine run the attacker's commands.
- Repository: a shared code project, for example on GitHub.
- Request: a message a client sends to a server asking it to do something.
- ROP chain: a sequence of small existing code pieces stitched together to perform an action.
- RPC: remote procedure call, asking a program on another machine to run one of its functions.
- SDK: software development kit, a box of ready-made parts for building programs.
- Segment heap: the userspace frontend heap allocator in Windows 10.
- Stack: the area of memory where a program keeps track of function calls.
- Stack overflow: running out of stack space, usually because of too much recursion, which terminates the process.
- Stack pivot: a technique that redirects execution to a place the attacker controls.
- Synchronisation primitive: a lock that coordinates access to shared state.
- Thread: one line of execution inside a program; a program can run several at once.
- Transport: the underlying way messages travel, such as TCP or HTTP.
- try..catch: the usual way a program handles an error by trying something and catching the failure.
- Unified API: one standard interface that reaches many different devices.
- Use-after-free (UaF): using memory after it has been freed.
- vptr: a hidden pointer inside an object that tells the program which functions belong to it.
- vtable: the table of function pointers that a vptr points into.