Goal Reached Thanks to every supporter — we hit 100%!

Goal: 1000 CNY · Raised: 1000 CNY

100.0%

CVE-2021-42835 PoC — PLEX Plex Media Server 访问控制错误漏洞

Source
Associated Vulnerability
Title:PLEX Plex Media Server 访问控制错误漏洞 (CVE-2021-42835)
Description:PLEX Plex Media Server是瑞士Plex(PLEX)公司的一套媒体播放器及媒体服务器软件。 Plex Media Server 中存在访问控制错误漏洞,该漏洞源于产品更新服务组件中的RPC服务未对用户身份进行有效验证。攻击者可通过该漏洞执行恶意代码。以下产品及版本受到影响:Plex Media Server 1.24.4.5081-e362dc1ee 版本。
Description
Plex media server local privilige escalation poc -  CVE-2021-42835
Readme
# Local Privilege PlEXcalasion -  CVE-2021-42835

Plex Media Server for Windows prior to version 1.25.0.5282, vulnerable to Time Of Check Time Of Use (TOCTOU) that allows low privilege users to gain SYSTEM privileges. 

## Discovered by
Tomer Peled, Netanel Cohen, and Amir Shen a Security Researchers from BugSec.

## Details
Plex for windows uses PlexUpdateService.exe to install new updates. The service is running in the SYSTEM context. When installing an update, the service first verifies file integrity and digital signature, only if the checks were successful the update will be installed.

At this process, After integrity and signature check, There was a design flow that handled the update file improperly. The file was closed and reopened later for installation.

This flaw allows an attacker to swap the update file with a malicious one as soon as the service is finished to verify the integrity and signature, resulting in code execution in the SYSTEM context.
 

This POC use tools developed by James Forshaw with slight modifications. The original can be found here - https://github.com/googleprojectzero/symboliclink-testing-tools

To achieve the above we used a Junction folder that will first point to a folder containing a valid update file and then will swap to a folder containing the malicious file.

We found that the file access order was as follow:
1. Read the update file to check its digital signature
2. Close the update file.
3. Read CACERT.pem
4. verify the signature.
5. Read the update file again
6. Execute the installation

We created a mount point on the junction folder to point to a folder that contains the valid update file.
Set opLock on cacert.pem with a callback function, As soon as it acess we change the mount point to the malicious folder.

In addition, we have created an RPC client that will trigger the update.




## Usage

1. Clone the repository and open PlEXcalasion.sln in Visual Studio.
2. Delete the Delete me.txt file located in TOCTOU\\junction - Its just place holder for git to include the folder , this folder must be empty!
3. Modify Paths:

PlexClient/PlexClient.cpp replace ROOTDIR with your path.
```cpp
const wchar_t* pszString = L"<ROOTDIR>\\PlEXcalaison\\TOCTOU\\junction\\plex.exe"; // Path to the update file. 
```
PlEXcalaison/BaitAndSwitch/BaitAndSwitch.cpp replace ROOTDIR with your path.
```cpp
static LPCWSTR junction = L"<ROOTDIR>\\PlEXcalaison\\TOCTOU\\junction";  // Path to junction folder , MAKE SURE IT IS EMPTY !
static LPCWSTR target1 = L"<ROOTDIR>\\PlEXcalaison\\TOCTOU\\valid"; // Path to folder contains the valid update file.
static LPCWSTR target2 = L"<ROOTDIR>\\PlEXcalaison\\TOCTOU\\malicious"; // Path to folder contains the malicious file - MUST BE THE SAME NAME AS THE UPDATE FILE.
static LPCWSTR cacert = L"C:\\Program Files (x86)\\Plex\\Plex Media Server\\Resources\\cacert.pem"; // Path to cacert.pem - can be found in plex directory.
```

4. Build the solution.
5. Make sure a PlexClient.exe was created and can be found on Rleases dir.
6. Put the desired executeable file you want to execute as system in the malicious folder and rename it to plex.exe (for the poc i used cmd.exe)
7. Execute BiteAndSwitch.exe

## Publications
https://ir-on.io/2021/12/02/local-privilege-plexcalation/

https://forums.plex.tv/t/security-regarding-cve-2021-42835/761510


File Snapshot

[4.0K] /data/pocs/78dd755847f71c1b219f71f34a01861001a8e854 ├── [4.0K] BaitAndSwitch │   ├── [2.4K] BaitAndSwitch.cpp │   ├── [3.5K] BaitAndSwitch_ReadMe.txt │   ├── [4.8K] BaitAndSwitch.vcxproj │   ├── [1.3K] BaitAndSwitch.vcxproj.filters │   ├── [ 292] stdafx.cpp │   ├── [ 307] stdafx.h │   └── [ 306] targetver.h ├── [4.0K] CommonUtils │   ├── [3.5K] CommonUtils.cpp │   ├── [1023] CommonUtils.h │   ├── [4.7K] CommonUtils.vcxproj │   ├── [2.6K] CommonUtils.vcxproj.filters │   ├── [1.9K] DirectoryObject.cpp │   ├── [4.3K] FileOpLock.cpp │   ├── [ 753] FileOpLock.h │   ├── [4.7K] FileSymlink.cpp │   ├── [ 562] FileSymlink.h │   ├── [1.6K] Hardlink.cpp │   ├── [1.9K] NativeSymlink.cpp │   ├── [2.2K] ntimports.h │   ├── [5.0K] RegistrySymlink.cpp │   ├── [ 13K] ReparsePoint.cpp │   ├── [1.2K] ReparsePoint.h │   ├── [1.7K] ScopedHandle.cpp │   ├── [ 473] ScopedHandle.h │   ├── [ 290] stdafx.cpp │   ├── [ 260] stdafx.h │   ├── [ 306] targetver.h │   └── [1.3K] typed_buffer.h ├── [4.0K] CreateMountPoint │   ├── [1.1K] CreateMountPoint.cpp │   ├── [ 386] CreateMountPoint_ReadMe.txt │   ├── [4.7K] CreateMountPoint.vcxproj │   ├── [1.2K] CreateMountPoint.vcxproj.filters │   ├── [ 297] stdafx.cpp │   ├── [ 283] stdafx.h │   └── [ 306] targetver.h ├── [4.0K] DeleteMountPoint │   ├── [1.1K] DeleteMountPoint.cpp │   ├── [ 243] DeleteMountPoint_ReadMe.txt │   ├── [4.7K] DeleteMountPoint.vcxproj │   ├── [1.2K] DeleteMountPoint.vcxproj.filters │   ├── [ 297] stdafx.cpp │   ├── [ 284] stdafx.h │   └── [ 306] targetver.h ├── [ 11K] LICENSE ├── [ 11K] LICENSE.txt ├── [4.5K] PlEXcalasion.sln ├── [3.7M] PlExcalation.mp4 ├── [4.0K] PlexClient │   ├── [2.3K] PlexClient.cpp │   ├── [1.4K] PlexClient.sln │   ├── [7.6K] PlexClient.vcxproj │   ├── [1.4K] PlexClient.vcxproj.filters │   ├── [ 10K] RPlex_c.cpp │   ├── [ 316] RPlex.idl │   └── [10.0K] RPlex_s.cpp ├── [3.3K] README.md ├── [4.0K] SetOpLock │   ├── [1.4K] SetOpLock.cpp │   ├── [1.5K] SetOpLock_ReadMe.txt │   ├── [4.7K] SetOpLock.vcxproj │   ├── [1.3K] SetOpLock.vcxproj.filters │   ├── [ 288] stdafx.cpp │   ├── [ 327] stdafx.h │   └── [ 306] targetver.h └── [4.0K] TOCTOU ├── [4.0K] junction │   └── [ 81] DELETE ME.txt ├── [4.0K] malicious │   └── [283K] plex.exe └── [4.0K] valid └── [ 89M] plex.exe 10 directories, 64 files
Shenlong Bot has cached this for you
Remarks
    1. It is advised to access via the original source first.
    2. If the original source is unavailable, please email f.jinxu#gmail.com for a local snapshot (replace # with @).
    3. Shenlong has snapshotted the POC code for you. To support long-term maintenance, please consider donating. Thank you for your support.