Subscribe to the Salt blog to learn about the latest developments in API Security

Blog Post

Salt Labs

OpenSSL Vulnerability Analysis — Denial of Service and Remote Code Execution

Salt Labs
Nov 3, 2022

In today’s post, we provide insights regarding two new vulnerabilities that have been uncovered in the OpenSSL library — CVE-2022-3602 and CVE-2022-3786. These vulnerabilities affect OpenSSL versions 3.0.0 — 3.0.6 but have been patched in the recent version 3.0.7.

Both have been rated HIGH severity. However, of the two, CVE-2022-3602 is considered more critical. Though still critical, CVE-2022-3786, Denial of Service, is less urgent. We have yet to see any active attack or exploit in the wild; however, we expect some could occur over the next few weeks.

To find out if you’re using vulnerable software, GitHub has a list of affected and unaffected software on its site here. In this blog post, we will take a deeper look at CVE-2022-3602 and the urgent risks it presents to organizations.

CVE-2022-3602 — OpenSSL Remote Code Execution (RCE)

The vulnerability can affect servers that require client authentication and may lead to critical remote code execution. If your server requests client authentication with X.509 certificate verification, or has a flow that validates such a certificate, an attacker can craft a malicious field (email address) in a certificate to exploit a classic buffer overflow. This buffer overflow could result in a crash (causing a denial of service) and, in some cases, may lead to remote code execution on your server.

The CVE-2022-3602 was originally assessed by the OpenSSL project as CRITICAL because of its potential to lead to remote code execution but was changed to HIGH after researching the stack layout with the conclusion that a remote code is less likely to happen.

To understand this, let's take a look at the vulnerable piece of code, in the function ossl_punycode_decode:

As part of parsing and converting a punycode string to unicode, the memmove function copies bytes from left to right by one byte (dword to be more accurate — unsigned int). To make sure memmove doesn't move/copy bytes outside of pDecoded, the code must check that the last byte memmove writes “to” is not bigger than the size of pDecoded in the stack, which is max_out.

To be more specific, the following condition must be checked by the code:

i + 1 + (written_out - i) < maxout

Since i-i is 0, we have a simpler condition:  written_out + 1 < maxout

However, the check in line 183 omits the "+1", leadining to a potential overflow by one dword (sizeof unsigned int). This is 4 bytes dangerous buffer overflow.

OpenSSL published the following fix here, changing (written_out > max_out) to (written_out >= max_out), which also solves the issue.

However, to understand the impact of those 4 bytes, we need to understand exactly what is located in the stack near pDecoded. For example, if there is a pointer in that place, the attacker could cause the server which uses OpenSSL to run a malicious code instead of the original flow. While not easy, this type of attack is theoretically possible.

The answer varies between different uses of OpenSSL, in combination with different compilers.

In the common scenario, as the OpenSSL security team wrote, the stack layout was such that the 4 bytes overwrote an adjacent buffer that was yet to be used. Therefore, remote code execution was less likely to happen.

By looking a bit deeper, ossl_punycode_decode is invoked from ossl_a2ulabel. In ossl_a2ulabel, pDecoded is a LABEL_BUF_SIZE (512) sized array of unsigned int. The total size on the stack is 512*4 = 2048.

In ossl_a2ulablel, there seems to be a seed variable after pDecoded in the stack, which means that the attacker can control its value.

However, this happens before the variable is initialized and therefore has no effect on the program (the value of the attacker will be overwritten anyway). In other scenarios, the compiler may ignore the seed variable because of optimization, which means that the stack cookie will be overwritten, which will cause the program to crash.

Even if the attacker finds a specific implementation/use of OpenSSL with a significant variable in the stack near pDecoded, they would  still need to bypass several stack overflow protections which exist on any platform and software by default.

Having exploited similar vulnerabilities, we know that it is not trivial to exploit it, and it may take some time to see a working exploit with remote code execution. Nevertheless, this CVE may motivate attackers to search for additional vulnerabilities in the OpenSSL library. It’s always important to ensure your server is protected against those attacks, especially if there is no available patch like in zero day vulnerabilities.

To learn more about how Salt can help defend your organization from API risks, you can connect with a rep or schedule a personalized demo.

Tags

Salt Security Blog

Sign up for the Salt Newsletter for the latest resources and blog posts.

November 5, 2024

Eric Schwake
Head of Product Marketing

Industry

API Security: The Non-Negotiable for Modern Transportation

Airlines and transportation companies heavily rely on APIs to handle sensitive data, from customer information to payment details and flight schedules. While crucial for efficient operations, these APIs are also prime cyberattack targets.

Read more

October 31, 2024

Alexandria Nicosia
Social Media Manager

Industry

Securing APIs in Retail: Safeguarding Customer Data

In the fast-paced retail industry, where customer trust and data protection are critical, API security must be a top priority to ensure both reliability and a seamless customer experience, confidence, and trust in digital services.

Read more

October 30, 2024

Eric Schwake
Head of Product Marketing

Customer

Salt Security and Dazz: A Powerful Partnership for API Security

Integrating Salt Security and Dazz provides a robust solution for organizations aiming to enhance their API and application security.

Read more

Download this guide for advice on evaluating key capabilities in API Security

Get the guide
Back