Vulnerabilities > CVE-2019-0232 - OS Command Injection vulnerability in Apache Tomcat

047910
CVSS 8.1 - HIGH
Attack vector
NETWORK
Attack complexity
HIGH
Privileges required
NONE
Confidentiality impact
HIGH
Integrity impact
HIGH
Availability impact
HIGH
network
high complexity
apache
CWE-78
nessus
exploit available
metasploit

Summary

When running on Windows with enableCmdLineArguments enabled, the CGI Servlet in Apache Tomcat 9.0.0.M1 to 9.0.17, 8.5.0 to 8.5.39 and 7.0.0 to 7.0.93 is vulnerable to Remote Code Execution due to a bug in the way the JRE passes command line arguments to Windows. The CGI Servlet is disabled by default. The CGI option enableCmdLineArguments is disable by default in Tomcat 9.0.x (and will be disabled by default in all versions in response to this vulnerability). For a detailed explanation of the JRE behaviour, see Markus Wulftange's blog (https://codewhitesec.blogspot.com/2016/02/java-and-command-line-injections-in-windows.html) and this archived MSDN blog (https://web.archive.org/web/20161228144344/https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/).

Vulnerable Configurations

Part Description Count
Application
Apache
186
OS
Microsoft
1

Common Attack Pattern Enumeration and Classification (CAPEC)

  • Command Line Execution through SQL Injection
    An attacker uses standard SQL injection methods to inject data into the command line for execution. This could be done directly through misuse of directives such as MSSQL_xp_cmdshell or indirectly through injection of data into the database that would be interpreted as shell commands. Sometime later, an unscrupulous backend application (or could be part of the functionality of the same application) fetches the injected data stored in the database and uses this data as command line arguments without performing proper validation. The malicious data escapes that data plane by spawning new commands to be executed on the host.
  • Command Delimiters
    An attack of this type exploits a programs' vulnerabilities that allows an attacker's commands to be concatenated onto a legitimate command with the intent of targeting other resources such as the file system or database. The system that uses a filter or a blacklist input validation, as opposed to whitelist validation is vulnerable to an attacker who predicts delimiters (or combinations of delimiters) not present in the filter or blacklist. As with other injection attacks, the attacker uses the command delimiter payload as an entry point to tunnel through the application and activate additional attacks through SQL queries, shell commands, network scanning, and so on.
  • Exploiting Multiple Input Interpretation Layers
    An attacker supplies the target software with input data that contains sequences of special characters designed to bypass input validation logic. This exploit relies on the target making multiples passes over the input data and processing a "layer" of special characters with each pass. In this manner, the attacker can disguise input that would otherwise be rejected as invalid by concealing it with layers of special/escape characters that are stripped off by subsequent processing steps. The goal is to first discover cases where the input validation layer executes before one or more parsing layers. That is, user input may go through the following logic in an application: In such cases, the attacker will need to provide input that will pass through the input validator, but after passing through parser2, will be converted into something that the input validator was supposed to stop.
  • Argument Injection
    An attacker changes the behavior or state of a targeted application through injecting data or command syntax through the targets use of non-validated and non-filtered arguments of exposed services or methods.
  • OS Command Injection
    In this type of an attack, an adversary injects operating system commands into existing application functions. An application that uses untrusted input to build command strings is vulnerable. An adversary can leverage OS command injection in an application to elevate privileges, execute arbitrary commands and compromise the underlying operating system.

Exploit-Db

idEDB-ID:47073
last seen2019-07-03
modified2019-07-03
published2019-07-03
reporterExploit-DB
sourcehttps://www.exploit-db.com/download/47073
titleApache Tomcat - CGIServlet enableCmdLineArguments Remote Code Execution (Metasploit)

Metasploit

descriptionThis module exploits a vulnerability in Apache Tomcat's CGIServlet component. When the enableCmdLineArguments setting is set to true, a remote user can abuse this to execute system commands, and gain remote code execution.
idMSF:EXPLOIT/WINDOWS/HTTP/TOMCAT_CGI_CMDLINEARGS
last seen2020-06-14
modified2019-08-02
published2019-06-18
references
reporterRapid7
sourcehttps://github.com/rapid7/metasploit-framework/blob/master//modules/exploits/windows/http/tomcat_cgi_cmdlineargs.rb
titleApache Tomcat CGIServlet enableCmdLineArguments Vulnerability

Nessus

  • NASL familyWeb Servers
    NASL idTOMCAT_7_0_94.NASL
    descriptionThe version of Tomcat installed on the remote Windows host is prior to 7.0.94. It is, therefore, affected by a remote code execution vulnerability due to a bug in the way the JRE passes command line arguments to Windows. An unauthenticated, remote attacker can exploit this to execute arbitrary commands. Additionally, it is affected by a cross-site (XSS) scripting vulnerability as the SSI printenv command echoes user provided data without proper escaping. Note that Nessus has not tested for this issue but has instead relied only on the application
    last seen2020-03-18
    modified2019-04-16
    plugin id124064
    published2019-04-16
    reporterThis script is Copyright (C) 2019-2020 and is owned by Tenable, Inc. or an Affiliate thereof.
    sourcehttps://www.tenable.com/plugins/nessus/124064
    titleApache Tomcat 7.0.0 < 7.0.94 Remote Code Execution Vulnerability (Windows)
    code
    #
    # (C) Tenable Network Security, Inc.
    #
    
    include('compat.inc');
    
    if (description)
    {
      script_id(124064);
      script_version("1.11");
      script_set_attribute(attribute:"plugin_modification_date", value:"2020/03/11");
    
      script_cve_id("CVE-2019-0221", "CVE-2019-0232");
      script_bugtraq_id(107906);
    
      script_name(english:"Apache Tomcat 7.0.0 < 7.0.94 Remote Code Execution Vulnerability (Windows)");
    
      script_set_attribute(attribute:"synopsis", value:
    "The remote Windows Apache Tomcat server is affected by a remote code execution vulnerability");
      script_set_attribute(attribute:"description", value:
    "The version of Tomcat installed on the remote Windows host is prior to 7.0.94. It is, therefore, affected by a remote
    code execution vulnerability due to a bug in the way the JRE passes command line arguments to Windows. An 
    unauthenticated, remote attacker can exploit this to execute arbitrary commands. 
    Additionally, it is affected by a cross-site (XSS) scripting vulnerability as the SSI printenv command echoes user
    provided data without proper escaping.
    
    Note that Nessus has not tested for this issue but has instead relied
    only on the application's self-reported version number.");
      script_set_attribute(attribute:"see_also", value:"https://github.com/apache/tomcat/commit/7f0221b");
      # https://tomcat.apache.org/security-7.html#Fixed_in_Apache_Tomcat_7.0.94
      script_set_attribute(attribute:"see_also", value:"http://www.nessus.org/u?afa7a4e1");
      script_set_attribute(attribute:"solution", value:
    "Upgrade to Apache Tomcat version 7.0.94 or later.");
      script_set_cvss_base_vector("CVSS2#AV:N/AC:M/Au:N/C:C/I:C/A:C");
      script_set_cvss_temporal_vector("CVSS2#E:F/RL:OF/RC:C");
      script_set_cvss3_base_vector("CVSS:3.0/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H");
      script_set_cvss3_temporal_vector("CVSS:3.0/E:F/RL:O/RC:C");
      script_set_attribute(attribute:"cvss_score_source", value:"CVE-2019-0232");
      script_set_attribute(attribute:"exploitability_ease", value:"Exploits are available");
      script_set_attribute(attribute:"exploit_available", value:"true");
      script_set_attribute(attribute:"metasploit_name", value:'Apache Tomcat CGIServlet enableCmdLineArguments Vulnerability');
      script_set_attribute(attribute:"exploit_framework_metasploit", value:"true");
    
      script_set_attribute(attribute:"vuln_publication_date", value:"2019/03/03");
      script_set_attribute(attribute:"patch_publication_date", value:"2019/04/13");
      script_set_attribute(attribute:"plugin_publication_date", value:"2019/04/16");
    
      script_set_attribute(attribute:"plugin_type", value:"combined");
      script_set_attribute(attribute:"cpe", value:"cpe:/a:apache:tomcat");
      script_set_attribute(attribute:"agent", value:"all");
      script_end_attributes();
    
      script_category(ACT_GATHER_INFO);
      script_family(english:"Web Servers");
    
      script_copyright(english:"This script is Copyright (C) 2019-2020 and is owned by Tenable, Inc. or an Affiliate thereof.");
    
      script_dependencies("tomcat_error_version.nasl", "os_fingerprint.nasl", "tomcat_win_installed.nbin", "apache_tomcat_nix_installed.nbin");
      script_require_keys("installed_sw/Apache Tomcat", "Host/OS");
    
    
      exit(0);
    }
    
    include('tomcat_version.inc');
    
    # Vuln only on Windows
    os = get_kb_item_or_exit('Host/OS');
    if ('Windows' >!< os) audit(AUDIT_OS_NOT, 'Windows', os);
    
    conf = get_kb_item('Host/OS/Confidence');
    if ((conf <= 70) && (report_paranoia < 2 )) 
    {
      exit(1, 'Can\'t determine the host\'s OS with sufficient confidence and \'show potential false alarms\' is not enabled.');
    }
    tomcat_check_version(fixed: '7.0.94', min:'7.0.0', severity:SECURITY_HOLE, granularity_regex: "^7(\.0)?$", xss:TRUE);
    
    
  • NASL familyWeb Servers
    NASL idTOMCAT_9_0_18.NASL
    descriptionThe version of Tomcat installed on the remote Windows host is prior to 9.0.19. It is, therefore, affected by a remote code execution vulnerability due to a bug in the way the JRE passes command line arguments to Windows. An unauthenticated, remote attacker can exploit this to execute arbitrary commands. Additionally, it is affected by a cross-site (XSS) scripting vulnerability as the SSI printenv command echoes user provided data without proper escaping. Note that Nessus has not tested for this issue but has instead relied only on the application
    last seen2020-03-18
    modified2019-04-15
    plugin id124058
    published2019-04-15
    reporterThis script is Copyright (C) 2019-2020 and is owned by Tenable, Inc. or an Affiliate thereof.
    sourcehttps://www.tenable.com/plugins/nessus/124058
    titleApache Tomcat 9.0.0.M1 < 9.0.19 Remote Code Execution Vulnerability (Windows)
  • NASL familyWeb Servers
    NASL idTOMCAT_8_5_40.NASL
    descriptionThe version of Tomcat installed on the remote Windows host is prior to 8.5.40. It is, therefore, affected by a remote code execution vulnerability due to a bug in the way the JRE passes command line arguments to Windows. An unauthenticated, remote attacker can exploit this to execute arbitrary commands. Additionally, it is affected by a cross-site (XSS) scripting vulnerability as the SSI printenv command echoes user provided data without proper escaping. Note that Nessus has not tested for this issue but has instead relied only on the application
    last seen2020-03-18
    modified2019-04-16
    plugin id124063
    published2019-04-16
    reporterThis script is Copyright (C) 2019-2020 and is owned by Tenable, Inc. or an Affiliate thereof.
    sourcehttps://www.tenable.com/plugins/nessus/124063
    titleApache Tomcat 8.5.0 < 8.5.40 Remote Code Execution Vulnerability (Windows)
  • NASL familyRed Hat Local Security Checks
    NASL idREDHAT-RHSA-2019-3929.NASL
    descriptionUpdated Red Hat JBoss Web Server 5.2.0 packages are now available for Red Hat Enterprise Linux 6, Red Hat Enterprise Linux 7, and Red Hat Enterprise Linux 8. Red Hat Product Security has rated this update as having a security impact of Important. A Common Vulnerability Scoring System (CVSS) base score, which gives a detailed severity rating, is available for each vulnerability from the CVE link(s) in the References section. Red Hat JBoss Web Server is a fully integrated and certified set of components for hosting Java web applications. It is comprised of the Apache Tomcat Servlet container, JBoss HTTP Connector (mod_cluster), the PicketLink Vault extension for Apache Tomcat, and the Tomcat Native library. This release of Red Hat JBoss Web Server 5.2 serves as a replacement for Red Hat JBoss Web Server 5.1, and includes bug fixes, enhancements, and component upgrades, which are documented in the Release Notes, linked to in the References. Security Fix(es) : * openssl: Side-channel vulnerability on SMT/Hyper-Threading architectures (PortSmash) (CVE-2018-5407) * openssl: 0-byte record padding oracle (CVE-2019-1559) * tomcat: HTTP/2 connection window exhaustion on write, incomplete fix of CVE-2019-0199 (CVE-2019-10072) * tomcat: XSS in SSI printenv (CVE-2019-0221) * tomcat: Apache Tomcat HTTP/2 DoS (CVE-2019-0199) For more details about the security issue(s), including the impact, a CVSS score, acknowledgments, and other related information, refer to the CVE page(s) listed in the References section.
    last seen2020-03-18
    modified2019-11-22
    plugin id131214
    published2019-11-22
    reporterThis script is Copyright (C) 2019-2020 and is owned by Tenable, Inc. or an Affiliate thereof.
    sourcehttps://www.tenable.com/plugins/nessus/131214
    titleRHEL 6 / 7 / 8 : JBoss Web Server (RHSA-2019:3929)
  • NASL familyAmazon Linux Local Security Checks
    NASL idALA_ALAS-2019-1208.NASL
    descriptionWhen the default servlet in Apache Tomcat returned a redirect to a directory (e.g. redirecting to
    last seen2020-06-01
    modified2020-06-02
    plugin id125294
    published2019-05-21
    reporterThis script is Copyright (C) 2019 and is owned by Tenable, Inc. or an Affiliate thereof.
    sourcehttps://www.tenable.com/plugins/nessus/125294
    titleAmazon Linux AMI : tomcat8 (ALAS-2019-1208)

Packetstorm

data sourcehttps://packetstormsecurity.com/files/download/153506/tomcat_cgi_cmdlineargs.rb.txt
idPACKETSTORM:153506
last seen2019-07-03
published2019-07-02
reportersinn3r
sourcehttps://packetstormsecurity.com/files/153506/Apache-Tomcat-CGIServlet-enableCmdLineArguments-Remote-Code-Execution.html
titleApache Tomcat CGIServlet enableCmdLineArguments Remote Code Execution

Redhat

advisories
rhsa
idRHSA-2019:1712

The Hacker News

idTHN:A1FA44D6DEC0509E076C54E227E6E6A1
last seen2019-04-16
modified2019-04-16
published2019-04-15
reporterThe Hacker News
sourcehttps://thehackernews.com/2019/04/apache-tomcat-security-flaw.html
titleApache Tomcat Patches Important Remote Code Execution Flaw

References