
Exploit und technische Dokumentation für CVE-2022-29464, einen nicht authentifizierten beliebigen Datei-Upload, der zu Remote-Codeausführung in WSO2-Servern über bösartigen JSP-Upload führt.
WSO2 RCE (CVE-2022-29464) Exploit und Writeup.
CVE-2022-29464 ist eine kritische Schwachstelle in WSO2, die von Orange Tsai entdeckt wurde. Die Schwachstelle ist ein nicht authentifizierter, uneingeschränkter, beliebiger Datei-Upload, der es nicht authentifizierten Angreifern ermöglicht, über das Hochladen bösartiger JSP-Dateien RCE auf WSO2-Servern zu erlangen.
Die verwundbare Upload-Route ist /fileupload, die vom FileUploadServlet Servlet verarbeitet wird. Sie ist eine durch IAM ungeschützte Route, wie wir in der indentity.xml-Konfigurationsdatei sehen können:```xml
Und auch nicht durch die Standard-Login-Maßnahme geschützt, ist `handleSecurity()` die Funktion, die für die Absicherung der verschiedenen von WSO2 bereitgestellten Routen verantwortlich ist und einen Mechanismus zur Durchführung von Sicherheitsüberprüfungen an den empfangenen HTTP-Anfragen bietet. `handleSecurity()` ruft `CarbonUILoginUtil.handleLoginPageRequest()` auf, und basierend auf dessen Rückgabewert wird entschieden, ob der Zugriff auf die angeforderte URI erlaubt oder verweigert wird:```java
public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response)
throws IOException {
[snipped]
if ((val = CarbonUILoginUtil.handleLoginPageRequest(requestedURI, request, response,
authenticated, context, indexPageURL)) != CarbonUILoginUtil.CONTINUE) {
if (val == CarbonUILoginUtil.RETURN_TRUE) {
return true;
} else {
return false;
}
}
[snipped]
}
CarbonUILoginUtil.handleLoginPageRequest() gibt CarbonUILoginUtil.RETURN_TRUE zurück, wenn die Route /fileupload lautet:```java
protected static int handleLoginPageRequest(String requestedURI, HttpServletRequest request,
HttpServletResponse response, boolean authenticated, String context, String indexPageURL)
throws IOException {
boolean isTryIt = requestedURI.indexOf("admin/jsp/WSRequestXSSproxy_ajaxprocessor.jsp") > -1;
boolean isFileDownload = requestedURI.endsWith("/filedownload");
if ((requestedURI.indexOf("login.jsp") > -1
|| requestedURI.indexOf("login_ajaxprocessor.jsp") > -1
|| requestedURI.indexOf("admin/layout/template.jsp") > -1
|| isFileDownload
|| requestedURI.endsWith("/fileupload")
|| requestedURI.indexOf("/fileupload/") > -1
|| requestedURI.indexOf("login_action.jsp") > -1
|| isTryIt
|| requestedURI.indexOf("tryit/JAXRSRequestXSSproxy_ajaxprocessor.jsp") > -1)
&& !requestedURI.contains(";")) {
if ((requestedURI.indexOf("login.jsp") > -1
|| requestedURI.indexOf("login_ajaxprocessor.jsp") > -1 || requestedURI
.indexOf("login_action.jsp") > -1) && authenticated) {
[snipped]
} else if ((isTryIt || isFileDownload) && !authenticated) {
[snipped]
} else if (requestedURI.indexOf("login_action.jsp") > -1 && !authenticated) {
[snipped]
} else {
if (log.isDebugEnabled()) {
log.debug("Skipping security checks for " + requestedURI);
}
return RETURN_TRUE;
}
}
return CONTINUE;
}
Wenn `CarbonUILoginUtil.handleLoginPageRequest()` `CarbonUILoginUtil.RETURN_TRUE` zurückgibt, gibt `handleSecurity()` `true` zurück, und der Zugriff auf `/fileupload` wird dann ohne Authentifizierung gewährt.
Das `FileUploadServlet`-Servlet lädt beim [`init()`](https://github.com/wso2/carbon-kernel/blob/d47232dfb2b26c0ef18a74e2ef4aa503caa59697/core/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/transports/FileUploadServlet.java#L71) und durch eine Reihe von Methodenaufrufen letztendlich aus der Konfigurationsdatei `carbon.xml` mehrere Upload-Dateiformate/-Aktionen zusammen mit dem Objekt, das jedes Format verarbeitet.```java
public void init(ServletConfig servletConfig) throws ServletException {
this.servletConfig = servletConfig;
try {
fileUploadExecutorManager = new FileUploadExecutorManager(bundleContext, configContext, webContext);
//Registering FileUploadExecutor Manager as an OSGi service
bundleContext.registerService(FileUploadExecutorManager.class.getName(), fileUploadExecutorManager, null);
} catch (CarbonException e) {
log.error("Exception occurred while trying to initialize FileUploadServlet", e);
throw new ServletException(e);
}
}
der Konstruktor der FileUploadExecutorManager Klasse sieht wie folgt aus:```java
public FileUploadExecutorManager(BundleContext bundleContext,
ConfigurationContext configCtx,
String webContext) throws CarbonException {
this.bundleContext = bundleContext;
this.configContext = configCtx;
this.webContext = webContext;
this.loadExecutorMap();
}
der Konstruktor ruft die private Methode [`loadExecutorMap()`](https://github.com/wso2/carbon-kernel/blob/d47232dfb2b26c0ef18a74e2ef4aa503caa59697/core/org.wso2.carbon.ui/src/main/java/org/wso2/carbon/ui/transports/fileupload/FileUploadExecutorManager.java#L131) auf, in der das Laden der Konfiguration durchgeführt wird:```java
private void loadExecutorMap() throws CarbonException {
[snipped]
try {
documentElement = XMLUtils.toOM(serverConfiguration.getDocumentElement());
} catch (Exception e) {
String msg = "Unable to read Server Configuration.";
log.error(msg);
throw new CarbonException(msg, e);
}
[snipped]
OMElement fileUploadConfigElement =
documentElement.getFirstChildWithName(
new QName(ServerConstants.CARBON_SERVER_XML_NAMESPACE, "FileUploadConfig"));
for (Iterator iterator = fileUploadConfigElement.getChildElements(); iterator.hasNext();) {
OMElement mapppingElement = (OMElement) iterator.next();
if (mapppingElement.getLocalName().equalsIgnoreCase("Mapping")) {
OMElement actionsElement =
mapppingElement.getFirstChildWithName(
new QName(ServerConstants.CARBON_SERVER_XML_NAMESPACE, "Actions"));
String confPath = System.getProperty(CarbonBaseConstants.CARBON_CONFIG_DIR_PATH);
[snipped]
Die Konfiguration der Datei-Upload-Formate befindet sich im Namespace FileUploadConfig in der XML-Konfigurationsdatei; dies ist die Standardkonfiguration:```xml
100
<Mapping>
<Actions>
<Action>keystore</Action>
<Action>certificate</Action>
<Action>*</Action>
</Actions>
<Class>org.wso2.carbon.ui.transports.fileupload.AnyFileUploadExecutor</Class>
</Mapping>