Nucleus: Dissecting The Nucleus TCP/IP Stack
Nucleus: Dissecting The Nucleus TCP/IP Stack
NUCLEUS: 13
Dissecting the Nucleus TCP/IP stack
By Forescout Research Labs & Medigate Labs
Medigate Labs
Uriel Malin
Tal Zohar
Yuval Halaban
RESEARCH REPORT | NUCLEUS:13
Table of Contents
1. Executive Summary.......................................................................................................3
2. Main Findings.................................................................................................................5
2.1. What is Nucleus NET?................................................................................................5
4. Impact...........................................................................................................................10
5. Mitigation Recommendations...................................................................................14
6. Technical Dive-In: Exploiting CVE-2021-31886........................................................15
6.1. Root cause analysis..................................................................................................16
7. Conclusions..................................................................................................................27
1. Executive Summary
• In the fifth study of Project Memoria – • The new vulnerabilities allow for Remote
NUCLEUS:13 – Forescout Research Labs and Code Execution or Denial of Service, with
Medigate Labs identified a set of 13 new three of the thirteen new vulnerabilities
vulnerabilities affecting the Nucleus TCP/IP being critical and having CVSS scores of
stack. either 9.8 or 8.8.
• Nucleus is currently owned by Siemens. • Forescout Research Labs and Medigate
Originally released in 1993, Nucleus has Labs exploited one of the Remote Code
been deployed in many industries that Execution vulnerabilities in their labs and
have safety and security requirements, demonstrated that a successful attack could
such as medical devices, automotive and potentially disrupt medical care and other
industrial systems. critical processes.
• Upon identifying new vulnerabilities, • Two of the recommended mitigations
Forescout Research Labs and Medigate Labs for NUCLEUS:13 include using network
collaborated with Siemens, CISA, CERT/CC segmentation to limit the network
and other agencies to confirm the findings exposure of critical vulnerable devices
and notify vendors. and patching devices as vendors release
• According to the Siemens website, Nucleus their patches. Some vulnerabilities can
is deployed in three billion devices. also be mitigated by blocking or disabling
Anesthesia machines, ventilators and support for unused protocols, such as FTP.
patient monitors are among the medical
devices possibly impacted by NUCLEUS:13.
INFORMATIONAL
2. Main Findings
2.1. What is Nucleus NET? 2.2. Why analyze Nucleus NET?
Nucleus NET is the TCP/IP stack of the Nucleus We chose to analyze Nucleus NET because of
Real-time Operating System (RTOS). The stack its known uses in safety-critical applications,
and the RTOS were originally developed by as described above. Nucleus NET was the
Accelerated Technology, Inc. (ATI) in 1993, target of previous analyses in Project Memoria,
then acquired by Mentor Graphics in 2002 and during both NUMBER:JACK and NAME:WRECK.
finally by Siemens in 2017. Since its original Siemens also published two CVEs affecting the
release 28 years ago, Nucleus has been IPv6 components of the stack in 2021, which
deployed in many industries that have safety are similar to some issues seen on AMNESIA:33.
and security requirements, such as medical Table 1 summarizes the previously known
devices, automotive and industrial systems. vulnerabilities affecting Nucleus NET.
Nucleus is currently distributed as:
Since we had already analyzed Nucleus NET
• ReadyStart: Containing source code, a for specific vulnerabilities in NUMBER:JACK
suite of tools for development and analysis, and NAME:WRECK (TCP ISN generation and
middleware, board support packages (BSPs) DNS client, respectively), we investigated other
and examples components of the stack that we had access to.
• SafetyCert: A certified version of the
kernel with runtime libraries, connectivity
middleware, networking and data storage.
The certification package includes source
code and documentation with traceability
and hyperlinks for easier safety reviews
CVE IDs Description/Comment
DHCP client vulnerability allows attackers to change the IP address of a device to an invalid
CVE-2019-13939 value. Besides Nucleus, it also affects several devices in the APOGEE, TALON and Desigo lines
of building automation products
CVE-2020-15795
CVE-2020-27009
CVE-2020-27736
Set of DNS client vulnerabilities
CVE-2020-27737
Part of Project Memoria’s NAME:WRECK
CVE-2020-27738
CVE-2021-25677
CVE-2021-27393
Predictable TCP ISN vulnerability
CVE-2020-28388
Part of Project Memoria’s NUMBER:JACK
CVE-2021-25663
IPv6 vulnerabilities, similar to AMNESIA:33
CVE-2021-25664
Siemens has released patches for all the in 2021 (after the NAME:WRECK disclosure)
vulnerabilities. Approximately half had already that listed critical vulnerable devices, such
been patched in existing versions of the stack as Siemens gas turbines, BD Alaris infusion
but never issued CVE IDs. pumps and GE healthcare devices.
As we have seen in NAME:WRECK with CVE- NUCLEUS:13 is the same, and in Section 6,
2016-20009 (which we independently found we discuss exploitation using one of the CVEs
on IPnet and had never been publicly reported that had been previously patched (CVE-2021-
with a CVE ID), vulnerabilities in TCP/IP stacks 31886) but still impacted devices with current
that have been silently patched may still affect firmware.
several devices. In the case of CVE-2016-20009
(whose ID indicates original discovery year of
2016), there were several advisories released
3. Attack Scenarios
Leveraging NUCLEUS:13
NUCLEUS:13 includes remote code execution Research Labs has shown that other types
and denial-of-service vulnerabilities that can of IoT devices, including building automation
be exploited by attackers to achieve different controllers, figure prominently among those
goals based on their motivations, such as to most impacted by TCP/IP stack vulnerabilities
gain a foothold into a network or wreak havoc. in healthcare organizations. The same holds
In this section, we discuss two examples of true for NUCLEUS:13, which impacts medical
attack scenarios that affect different industries devices, building automation devices and
but leverage the same FTP-based exploitation other types of OT and IoT devices (discussed in
(detailed in Section 6). Section 4).
A video showing both attacks as implemented Building automation devices are used in
in our lab can be found here. hospitals to control functions such as physical
3.1. Scenario 1: hacking the hospital access control, fire alarm systems, lighting
Although connected medical devices are and HVAC (heating, ventilation and air
currently (and justifiably) the focus of conditioning). These functions are not directly
much cybersecurity discussion, Forescout connected to patients, but they are critical to
delivering patient care.
In this scenario, a motion sensor, a light bulb Since the exploited vulnerability allows for
and a model fan are connected to a building code execution (discussed in Section 6), this
automation controller. When someone attack could be extended to allow the attacker
enters a patient’s room, the fan and lights to change temperature setpoints, control logic
switch on automatically, and they switch off and other variables in the controller. He could
automatically when the person leaves the also use the compromised device to issue
room. An attacker can crash the controller by malicious commands to other devices in the
sending a crafted FTP packet that exploits CVE- hospital. The main difference is that those
2021-31886 (or any other DoS in NUCLEUS:13). attacks would be highly targeted to a specific
When the attack is successful, the fan environment (i.e., a particular hospital with a
and lights stop working, thus creating an particular set of controllers and logic), whereas
environment where patient care is hindered. the denial of service works against several
targets, making it an easily commoditized asset
for cyber criminals).
In this scenario, a presence sensor and a the controller by sending the same FTP packet
train model are connected to an automation that exploits CVE-2021-31886 described above
controller placed at a station. When the (or any other DoS in NUCLEUS:13). When the
sensor detects that the train is at the station, attack is successful, the train will not stop at
it controls the train to stop for a certain period the station, and thus can collide with another
of time, after which the train automatically train, people or other objects on the track.
continues its journey. An attacker can crash
4. Impact
In this section, we estimate the impact of that most of those three billion devices are
NUCLEUS:13 based on the evidence collected actually device components such as MediaTek
during our research, using three main sources: IoT chipsets and baseband processors used
• The official Nucleus website, which states in smartphones and other wireless devices.
that the RTOS is deployed in more than We also found technical documentation
three billion devices. A review of customer detailing the use of Nucleus for medical
success stories reveals its use in scenarios devices, such as the GE S/5 Avance
such as healthcare (ZOLL defibrillators and Anesthesia Machine (shown in Figure 3) and
ZONARE ultrasound machines), IT (BDT the Nihon Kohden Bedside Monitor (shown
AG storage systems) and critical systems in Figure 4).
(Garmin avionics navigation). Yet, we believe
Figure 3 – Documentation of a GE S/5 Avance Anesthesia Machine showing the use of Nucleus RTOS
Figure 4 – Documentation of a Nihon Kohden patient monitor detailing an error message caused by Nucleus
Figure 5 – Exposed devices running Nucleus FTP Figure 6 – Exposed devices running Nucleus RTOS (“Operating System:
(“220 Nucleus FTP”) Nucleus PLUS”)
• Forescout Device Cloud. Forescout Device instance. We found close to 5,500 devices
Cloud is a repository of information for from 16 vendors in place at 127 customers.
about 13+ million devices monitored by Thirteen of these customers had more than
Forescout appliances. We queried it for 100 vulnerable devices, with healthcare
similar banners to Shodan, as well as other being the most impacted sector
information, based on DHCP signatures, for (see Figure 7).
Figure 8 – Devices running Nucleus in each vertical (source: Forescout Device Cloud)
As we have done with our previous research, to vendors impacted by NUCLEUS:13 on our
we will maintain a list of advisories related GitHub page.
5. Mitigation Recommendations
Complete protection against NUCLEUS:13 • Enforce segmentation controls and
requires patching devices running the proper network hygiene to mitigate
vulnerable versions of Nucleus. Siemens the risk from vulnerable devices. Restrict
has released its official patches, and device external communication paths and isolate
vendors using this software should provide or contain vulnerable devices in zones as a
their own updates to customers. Below, we mitigating control if they cannot be patched
discuss mitigation strategies for network or until they can be patched.
operators. • Monitor progressive patches released
Given that patching the embedded devices by affected device vendors and devise a
is notoriously difficult (due to their mission- remediation plan for your vulnerable asset
critical nature), we recommend the following inventory, balancing business risk and
mitigation strategy: business continuity requirements.
• Discover and inventory devices running • Monitor all network traffic for malicious
Nucleus. Forescout Research Labs has packets that try to exploit known
released an open-source script that uses vulnerabilities or possible zero-days. You
active fingerprinting to detect devices should block anomalous and malformed
running Nucleus. The script is updated traffic, or at least alert its presence to
constantly with new signatures to follow the network operators.
latest development of our research. Table 4 provides recommended mitigations for
each vulnerability.
CVE Affected Component Mitigation Recommendation
2021-31885
2021-31886
FTP / TFTP server Disable FTP/TFTP if not needed, or whitelist connections.
2021-31887
2021-31888
2021-31881 Use switch-based DHCP control mechanisms: protocol-aware network switches may
2021-31882 be configured to block DHCP responses from rogue servers (“DHCP snooping”)1.
DHCP client
2021-31883 Alternatively, firewalls can be configured in a similar fashion. As a last resort, use static IP
2021-31884 addresses.
2021-31344
2021-31345
Monitor traffic for malformed packets and block them. Having a vulnerable device behind
2021-31346 TCP / UDP / IP / ICMP
a properly configured firewall should be sufficient.
2021-31889
2021-31890
1 See https://kb.isc.org/docs/aa-00573
TECHNICAL DIVE-IN
6. Technical Dive-In:
Exploiting CVE-2021-31886
There are three vulnerabilities in NUCLEUS:13 constraints. Note that the exploitation does
that allow for Remote Code Execution: CVE- not require any authentication on the target,
2021-31886, CVE-2021-31887 and CVE-2021- as the vulnerability is triggered for any input of
31888. All three vulnerabilities affect the the “USER” command that has a specific length.
default FTP server application shipped with the The vulnerability is detailed in Section 6.1, and
Nucleus TCP/IP stack. In this section, we will the exploitation details are outlined in Sections
focus on CVE-2021-31886: unchecked input 6.2 and 6.3.
size of the USER command.
Important note on exploitability: Some of the
At a high level, to trigger CVE-2021-31886, technical details of the exploitation are specific
attackers perform authentication attempts to the hardware/firmware being exploited,
on the affected FTP server, sending the FTP including the presence of specific components
“USER” command with a username that is of the affected TCP/IP stack and the absence
larger than the internal buffer designated to of exploit mitigations. Some of the details
hold the input of this command (note that the discussed below may be specific to the chosen
actual size of this buffer may vary). Sending targets (QEMU image based on Nucleus Ready
a large enough username results in a stack- Start for NXP i.MX28 evaluation software, and
based buffer overflow, allowing performance WAGO 750-852 PLC with firmware version
of controlled writes into the memory of “01.07.21 (14)”, respectively).
the affected device, hijacking the execution
flow and executing attackers’ code with few
TECHNICAL DIVE-IN
TECHNICAL DIVE-IN
The server variable is a pointer to a variable “USER”, one space character, 31 characters
that holds the FTP_SERVER structure (shown of username and the two “\r\n” characters.
in Figure 10). The server->replyBuff field However, if we place a null-terminator in an
holds the contents of the input buffer (in arbitrary place within server->replyBuff such
this case, the entire “USER” command). In that strlen() returns a value less than 38, we
our case, the contents of server->replyBuff can still copy a longer string into server->user,
are expected to be of the following format: provided that we place the “\r” character at a
“USER\x20username\x0d\x0a\x00”, where desired offset.
the command “USER” is followed by a space
In this way, we can overflow server->user, the
character (0x20), the “\r\n” characters and a
remaining fields of the FTP_SERVER structure
null terminator (0x00) that signifies the end of
as well as some local variables and the
the input string.
metadata of a stack frame, where FTP_SERVER
The username is then copied from is declared (server happens to be a pointer to
server->replyBuff into server->user (lines a local variable declared in the Control_Task()
21-24 in Figure 9). This code will copy a function). In essence, this is a stack-based
sequence of characters (up to 250) until the buffer overflow vulnerability.
first occurrence of the ‘\r’ character (0x0d or
6.2. Exploiting a QEMU image
13 in ASCII). It will finally add a null-terminator
In this Section, we describe the exploitation
to server->user (line 26 of Figure 9). Note, that
details, based on a QEMU image built for
server->user is, in fact, only 32-bytes long (see
Nucleus Ready Start for NXP i.MX28 evaluation
Figure 10).
software. We also managed to exploit this
At line 7 of Figure 9, the code checks whether vulnerability on a WAGO 750-852 PLC, which is
the input string server->replyBuff is not explained in Section 6.3.
larger than 38 characters, using the strlen()2
function. The expected contents of this buffer
are as follows: four characters for the string
2 strlen() returns the length of a byte sequence until the first 0x00 byte is encountered.
TECHNICAL DIVE-IN
The exploitation strategy involved the Figure 11 shows a pseudocode excerpt from
following steps: the Control_Task() function, which is an
1. Patch the address of the input buffer (e.g., RTOS task that is responsible for handling FTP
the buffer that stores the “USER” command), sessions. This function contains important local
so that it points to a different memory variables: FTP_SERVER server that contains a
location: This allows the attacker to have field user, which we intend to overflow; and
longer shellcode (we can upload only CHAR *buffer, which is a pointer to the buffer
218 bytes of shellcode at a time). This also that contains the raw user input (it will be later
helps to avoid overwriting the shellcode copied into server->replyBuff).
(e.g., by buffer deallocation and other
FTP commands).
2. Prepare the shellcode and upload it to a
desired location within the memory.
3. Redirect the execution flow to the shellcode.
TECHNICAL DIVE-IN
At this point, we can construct such input shellcode in some unused memory region
that will overflow the server->user field, where more space is available; (2) since
overwriting the fields of server past the Control_Task() is an RTOS task3, it runs in an
server->user field, as well as the local infinite loop and will not return as a traditional
variables in Control_Task() past server. C function; therefore, overwriting the return
We could also overwrite the return address address will at best cause a Denial-of-Service
of Control_Task() at this point and hijack under certain conditions but will not allow us
the execution flow. However, we incur two to hijack the execution flow in a useful way.
problems: (1) we still need to store our
Our first goal is to find an executable region as writable in our case). Figure 12 shows an
of memory to store the shellcode. For this excerpt from this segment. It contains several
purpose, we have chosen the address static variables which are not used in the
0x000b22bc located in the .bss segment (this context of the FTP server and therefore is a
memory segment happens to be marked good location for our shellcode.
3 Have a look at this blog post from CircuitsToday.com for a short overview of RTOS concepts.
TECHNICAL DIVE-IN
Since we cannot easily overwrite the return callback will be triggered when a particular LLC
address of Control_Task(), we must resort frame is received. Therefore, if we overwrite
to other means for redirecting the execution. the span_process_packet pointer with the
We have found several function pointers address of our shellcode and send the LLC
declared in the .bss memory segment. One frame4 that meets the right conditions, the
of them is called span_process_packet and it shellcode will be executed.
is set to zero by default. Figure 13 shows that To achieve this, we establish our first FTP
span_process_packet is a callback pointer, session with the target device and send a
and if the pointer contains a non-zero address malformed USER command with the
(it is supposed to be a function address), this following bytes:
The payload contains the following bytes: • The address of the shellcode (0x000b22c4,
• The “USER” command followed by a space big endian), the address of the span_
character (0x20) process_packet pointer (0x00b14f8, big
• Several dummy bytes that overflow the field endian)
server->user. Note that we have also placed When the field server->user is overwritten, we
a null-terminator (0x00) in the middle of will write the two addresses into the first eight
the input, so that the input length checks bytes of the server->FTP_Events field (see
(shown on Figure 9) will be circumvented. Figure 10; the addresses are marked in red
and green):
4 A Logical-Link Control (LLC) frame with the bytes 0x0026 or 0x0007 set in place of the ETHERTYPE/LENGTH field (bytes 13 and 14)
of the Ethernet header
TECHNICAL DIVE-IN
These addresses will, essentially, be written At this time, the pointers node->cs_previous
into the fields of the ev_created variable and node->cs_next are the same as server-
enclosed into server->FTP_events. >FTP_Events->ev_created->cs_previous and
server->FTP_Events->ev_created->cs_next,
and they point to the desired shellcode address
and the address of span_process_packet
After these addresses are written, we close pointer, respectively. After the code on line 10 is
the FTP session by sending a TCP RST packet. executed, we overwrite the value of the span_
When the session is closed, Control_Task() will process_packet pointer with our shellcode
eventually call the NU_Remove_From_List() address, which means that now this callback
function (shown in Figure 14). This function will is initialized, and whenever it is invoked, the
remove the current FTP event node from the shellcode will be executed.
FTP event list (lines 9-10).
Next, we establish a new FTP session and of 52 bytes from the end of server->user, we
attempt to patch the buffer pointer and to simply construct an FTP user command that
write our shellcode at the desired location. To contains the new address of buffer at the
patch the address of buffer, we use the same required offset.
technique as before. As buffer lies at the offset
TECHNICAL DIVE-IN
Note that after the USER command is handled buffer points to the address that we now
and the execution returns to Control_Task(), control:
Note that this time, we are supplying the It is important that, at this time, we do not
address 0x000b22bc, which is different from close the current FTP session. Otherwise,
the shellcode address 0x00b22c4 that we set Control_Task() will allocate a new input buffer
during the previous step. This is because we pointer, and all the work we have done so far
are patching the raw input buffer. Apart from will be lost. Therefore, to supply the shellcode,
the user-supplied contents, it will include the we immediately follow with another USER
entire FTP command that starts with “USER\ command that will be written into the memory
x20”. Therefore, we will structure our input as starting at address 0x000b22bc. This time, it
“USER\x20\x00\x00\x00[shellcode]” and skip the contains the following shellcode:
first eight bytes to jump directly at the first
byte of the shellcode.
TECHNICAL DIVE-IN
Finally, we send an LLC frame that meets the executed. In this case, our shellcode simply
requirements for triggering the span_process_ prints a line to the serial console of
packet callback, and the shellcode gets the QEMU VM.
6.3. Exploiting a WAGO 750-852 because of the size limitations that constrain
The exploitation of CVE-2021-31886 in the stage 0. To do so, we needed to make
WAGO 750-852 PLC is similar to the QEMU stage 0 patch another function pointer ppe_
image exploitation. That is, we overflow the process_packet to point at a location which
server structure to have our shellcode residing we dynamically allocated. Whenever stage
at a stable location pointed to by the buffer 0 gets triggered again, it will copy shellcode
variable and calling it afterwards through fragments which we sent within the LLC frame
a patched span_process_packet function to be reassembled at the location pointed at by
pointer. ppe_process_packet. This pointer is another
After having a first payload running through callback (similar to span_process_packet)
span_process_packet (called “stage 0”), we which is called at the function EightZeroTwo, as
aimed at loading a second payload (“stage 1”) follows:
TECHNICAL DIVE-IN
The stage 0 shellcode is illustrated in Once the entire stage 1 shellcode is copied and
Figure 15. It allocates the memory for is in good order (ensured by the checksum),
stage 1 shellcode on lines 34-39. Whenever we patch the ppe_process_packet pointer to
stage 0 gets executed, it copies the fragments point at the beginning of stage 1 shellcode
of stage 1 shellcode in the right order and into (lines 53-64).
a designated memory location (lines 66-72).
TECHNICAL DIVE-IN
TECHNICAL DIVE-IN
When this is done, we trigger the ppe_process_ of a particular page used in the embedded
packet callback by sending a crafted Point-to- webserver. The effect of this change is shown
Point Protocol over Ethernet (PPOE) frame. in Figure 16 (normal operation) and Figure 17
The stage 1 shellcode accesses the filesystem (after exploiting CVE-2021-31886).
of the WAGO PLC, changing the HTML code
7. Conclusions
In this report, we discussed NUCLEUS:13, a set by financial gains more than ever. This is
of 13 vulnerabilities affecting the Nucleus TCP/ especially true for operational technology and
IP stack, currently owned by Siemens and used the Internet of Things. The expanded adoption
in billions of devices. The vulnerabilities include of these types of technology by every type of
three RCEs, which we managed to exploit in organization, and their deep integration into
our labs as discussed in Section 3. We saw critical business operations, will only increase
evidence of the stack running in industrial their value for attackers over the long term.
controllers, building automation equipment,
With this context in mind, Forescout Research
and medical devices.
Labs and Medigate Labs look forward to
We strongly believe that the threat landscape analyzing additional software and devices,
for every type of connected device is changing driving opportunities for better industry
fast, with an ever-increasing number of severe collaboration and continuing to help secure
vulnerabilities and attackers being motivated the Enterprise of Things.