
Exploit für CVE-2022-29464, einen nicht authentifizierten beliebigen Datei-Upload in WSO2-Servern, der eine Remote-Codeausführung durch bösartige JSP-Uploads ermöglicht.
WSO2 RCE (CVE-2022-29464) Exploit und Writeup.
CVE-2022-29464 ist ein schwerwiegender Fehler in WSO2. Der Fehler ist ein nicht autorisierter, uneingeschränkter Datei-Upload, der es nicht autorisierten Benutzern ermöglicht, bösartige JSP-Dateien auf WSO2-Server hochzuladen und Remote Code Execution (RCE) zu erlangen.
Die anfällige Upload-Route ist /fileupload, die vom Servlet FileUploadServlet verarbeitet wird. Und sie ist eine ungeschützte Route durch IAM, wie wir in der Konfigurationsdatei indentity.xml sehen können:```xml
Die Funktion 'handleSecurity()' ist für den Schutz der verschiedenen von WSO2 bereitgestellten Routen verantwortlich und bietet einen Mechanismus zur Durchführung von Sicherheitsprüfungen auf die empfangenen HTTP-Anfragen. 'handleSecurity()' ruft 'CarbonUILoginUtil.handleLoginPageRequest(),' auf, und basierend auf dessen Rückgabewert wird entschieden, ob der Zugriff auf die angeforderte URI gewährt 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 ist:```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;
}
mit `CarbonUILoginUtil.handleLoginPageRequest()`, die `CarbonUILoginUtil.RETURN_TRUE` zurückgibt, wird `handleSecurity()` `true` zurückgeben, und der Zugriff auf `/fileupload` wird dann ohne Authentifizierung gewährt.
Der `FileUploadServlet`-Servlet und über [`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) lädt über eine Reihe von Methodenaufrufen letztendlich aus der Konfigurationsdatei `carbon.xml` mehrere Upload-Dateiformate/-aktionen zusammen mit dem Objekt, das jedes Format behandelt.```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 FileUploadExecutorManager Klassenkonstruktor lautet wie folgt:```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 die Konfigurationsladung erfolgt:```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 Konfigurationen der Datei-Upload-Formate befinden sich im FileUploadConfig-Namespace 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>