OpenSSL is a popular open source cryptography library. Applications that secure communication over computer networks use OpenSSL to implement SSL (Secure Socket Layer) and TLS (Transport Layer Security). OpenSSL provides different utility functions, such as generating public and private keys to initiate secure communications.
The OpenSSL project recently announced the release of OpenSSL 3.0.7
. This release was made available on 1st November 2022 as a security fix for two high-severity vulnerabilities, CVE-2022-3602 and CVE-2022-3786.
1. CVE-2022-3602 (X.509 Email Address 4-byte Buffer Overflow): This vulnerability occurs because OpenSSL processes Punycode incorrectly when checking X.509 certificates. Punycode is a unique encoding system for representing Unicode characters in multiple languages using ASCII character subset. It is used to encode Domain names that contain non-ASCII characters. The specific vulnerable function in OpenSSL is the ossl_punycode_decode
. This vulnerable function may trigger a buffer overflow when OpenSSL processes a certificate chain when decoding Punycode strings. This vulnerability was reported on 17th October 2022 by SandboxEscaper. The OpenSSL project initially rated CVE-2022-3602 as a “critical” vulnerability, but it was later downgraded to “high” because it does not reliably initiate Remote Code Execution (RCE).
2. CVE-2022-3786 (X.509 Email Address Variable Length Buffer Overflow): This vulnerability triggers a buffer overflow in the vulnerable ossl_a2ulable
function. When the vulnerable function interacts with a Punycode character accompanied by a dot character (.), the ossl_a2ulable
function appends the dot character to the buffer output. This action happens even when the action overflows the size of the buffer. An attacker will trigger a buffer overflow by using any number of dot characters, leading to the stack corruption. This vulnerability was found by Viktor Dukhovni on 18th October 2022 while researching CVE-2022-3602.
Both vulnerabilities are buffer overflow vulnerabilities that OpenSSL triggers in the name constraint checking function of the X.509 certificate verification. A certificate chain signature verification must occur for an attacker to exploit these vulnerabilities. These vulnerabilities are exploited when:
- A certificate authority (CA) signs a malicious certificate. Here, an attacker will create a CA certificate that contains the
nameConstraints
field with a malicious Punycode string containing at least 512 bytes excluding “xn--”. Alternatively, an attacker can create a leaf certificate containing theotherName
field of an X.509 Subject Alternative Name (SAN). This field specifies an SmtpUTF8Mailbox string. - An application verifies a malicious certificate despite failure to build a trusted issuer path.
CVE-2022-3602 and CVE-2022-3786 both lead to Denial of Service (DoS). An attacker will crash an application using OpenSSL by sending a certificate containing a malicious Punycode-encoded email to the application for parsing.
The affected versions of OpenSSL are 3.0.0
through 3.0.6
, while the earlier versions, OpenSSL 0.9.x
, 1.0.x
, and 1.1.x
are not affected by the mentioned vulnerabilities. There are no available working exploits at the time of writing this blog post.
The fix for CVE-2022-3602 in the punycode decoder was implemented by simply changing “>
” to “>=
” in the source code, as shown below:
n = n + i / (written_out + 1); i %= (written_out + 1); if (written_out >= max_out) return 0; memmove(pDecoded + i + 1, pDecoded + i
This shows how a one-byte error can trigger a high severity vulnerability.
To ensure airtight security, organizations must prioritize inventorying and scanning all available systems for vulnerable software versions, in this case, OpenSSL. In this blog post, we detect the vulnerable versions of OpenSSL on an endpoint with the Wazuh Vulnerability Detector module and the Security Configuration Assessment (SCA) module.
Detection with Wazuh
To demonstrate Wazuh capabilities for detecting the OpenSSL 3.0.0 – 3.0.6 vulnerabilities, we set up the following infrastructure:
1. A pre-built ready-to-use Wazuh OVA 4.3.10. Follow this guide to download the virtual machine.
2. Ubuntu 22.04 and Windows 11 endpoints with OpenSSL 3.0.1 to 3.0.6 installed. You can install a Wazuh agent and enroll it to a Wazuh server by following the deploying Wazuh agents guide.
Vulnerability detector
The Wazuh Vulnerability Detector module can detect vulnerable versions of the OpenSSL package. It can discover vulnerabilities affecting applications and the operating system of monitored endpoints. The Vulnerability Detector module first downloads and stores the data of all vulnerabilities from multiple publicly available CVE repositories. Then, the Wazuh server builds a global vulnerability database from the gathered data. Finally, the Wazuh global vulnerability database is cross-correlated with the endpoint inventory data to detect vulnerabilities.
Take the following steps to configure the Wazuh Vulnerability Detector module:
Wazuh server
1. Edit the /var/ossec/etc/ossec.conf
file and enable the Vulnerability Detector module:
<ossec_config> … <vulnerability-detector> <enabled>yes</enabled> … </vulnerability-detector> … </ossec_config>
2. Edit the /var/ossec/etc/ossec.conf
configuration file and enable the operating system provider of the monitored endpoint. In this section, we will use an Ubuntu endpoint for the Vulnerability Detector module. We then enable Canonical
, the publisher of Ubuntu.
<ossec_config> … <vulnerability-detector> … <!-- Ubuntu OS vulnerabilities --> <provider name="canonical"> <enabled>yes</enabled> <os>trusty</os> <os>xenial</os> <os>bionic</os> <os>focal</os> <os>jammy</os> <update_interval>1h</update_interval> </provider> … </vulnerability-detector> … </ossec_config>
3. Restart the Wazuh manager to apply the changes:
# systemctl restart wazuh-manager
4. View the Wazuh Vulnerability Detector events on the Wazuh dashboard by navigating to Modules > Vulnerabilities > Select agent, and select the Ubuntu endpoint.
After completing the Wazuh vulnerability scan, we wait for a few minutes and will see the CVE-2022-3786 and CVE-2022-3602 vulnerabilities as part of the inventory of the vulnerable monitored endpoint on the Wazuh dashboard:
Security Configuration Assessment
The Wazuh SCA module runs checks that test system hardening, detect vulnerable software, and validate configuration policies. In this section, we utilize SCA to detect the vulnerable versions of OpenSSL on Windows.
Note
Run the below commands using Administrator privileges.
Windows endpoint
1. Create a directory to hold local SCA policy files:
mkdir "C:\Program Files (x86)"\local_sca_policies\
Custom SCA policies inside the Wazuh default ruleset folders are not kept across updates. This is why the C:\Program Files (x86)\local_sca_policies\
directory is created outside the Wazuh agent installation folder.
2. Create a new policy file C:\Program Files (x86)\local_sca_policies\openssl3x_check.yml
and add the following content:
policy: id: "openssl3x_check" file: "openssl3x_check.yml" name: "OpenSSL 3.0.x vulnerability check on Windows" description: "Detecting vulnerable versions of OpenSSL." references: - https://www.openssl.org/news/secadv/20221101.txt/ requirements: title: "Check that Windows is installed" description: "Requirements for running the SCA scan against machines with OpenSSL on them." condition: all rules: - 'r:HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion -> ProductName -> r:^Windows' checks: - id: 10001 title: "Ensure OpenSSL is not between 3.0.0 to 3.0.6." description: "The OpenSSL 3.0.0 to 3.0.6 is vulnerable to CVE-2022-3602 & CVE-2022-3786 leading to potential denial of service" rationale: "New vulnerabilities have been discovered in OpenSSL. It is important to update to the latest version of OpenSSL to prevent discovered vulnerabilities in previous versions from being exploited." remediation: "Update OpenSSL to a version greater than or equal to 3.0.7" condition: none rules: - "c:powershell Get-command openssl -> r:3.0.0|3.0.1|3.0.2|3.0.3|3.0.4|3.0.5|3.0.6"
Note
The local custom SCA policy file can also be distributed to other endpoints that you want to check for the OpenSSL vulnerability on by using a remote deployment tool like Ansible, or the Windows GPO.
3. Edit C:\Program Files (x86)\ossec-agent\ossec.conf
to contain the SCA block:
<sca> <policies> <policy>C:\Program Files (x86)\local_sca_policies\openssl3x_check.yml</policy> </policies> </sca>
4. Restart the Wazuh agent to apply the changes:
NET STOP WazuhSvc NET START WazuhSvc
Testing the configuration
We can see the SCA scan results for an endpoint with the infected version of OpenSSL:
Mitigation
It is recommended by OpenSSL to upgrade any vulnerable installation of OpenSSL to the OpenSSL project released OpenSSL-3.0.7 fix.
Red Hat Enterprise users can update to the Red Hat patched version openssl-3.0.1-43.el9_0.
Ubuntu 22.04 and 22.10 users can update to the Canonical patched version 3.0.2-0ubuntu1.7 and 3.0.5-2ubuntu2, respectively.
Conclusion
This blog post demonstrates how Wazuh detects OpenSSL libraries with the CVE-2022-3602 and CVE-2022-3786 vulnerabilities. The Wazuh Vulnerability Detector can be used by organizations to detect existing vulnerabilities across different operating systems on a large scale. The Wazuh Security Configuration Assessment (SCA) module can also be used to check for vulnerable OpenSSL versions on multiple endpoints.
Do you have any questions? Join our community on Slack.