Skip to content
RCE Write-up Advanced

CVE-2021-31181: Microsoft SharePoint WebPart Interpretation Conflict Remote Code Execution Vulnerability

SharePoint's EditingPageParser failed to trim the namespace attribute in Register directives, allowing an attacker to bypass the SafeControl list and instantiate a dangerous XmlDataSource control. This let an authenticated user read web.config, obtain the machineKey validation key, and forge a VIEWSTATE to achieve remote code execution.

zerodayinitiative.com

Published on zerodayinitiative.com

In May of 2021, Microsoft released a patch to correct CVE-2021-31181 – a remote code execution bug in the supported versions of Microsoft SharePoint Server. This bug was reported to the ZDI program by an anonymous researcher and is also known as ZDI-21-573.

The author, on zerodayinitiative.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the namespace attribute in a Register directive was not trimmed during the safe-list verification, so a type with a trailing space failed to resolve and was not blocked, while later processing trimmed it and resolved the dangerous type.

Impact

An authenticated user with ManageLists permissions could execute arbitrary code on the server in the context of the SharePoint service account.

What the attacker needed

Authenticated SharePoint user; SPBasePermissions.ManageLists on a site; ability to create a site (default for authenticated users)

The fix

Microsoft patched the vulnerability in May 2021.

How it was found

  1. Authenticate to SharePoint as a regular user and create a site to obtain ManageLists permissions.
  2. Retrieve the site's webId via /_api/web/id and the title of an existing SPList.
  3. Send a RenderWebPartForEdit request containing a Register directive with a trailing space in the namespace and an XmlDataSource control to read web.config.
  4. Extract the validationKey and validation algorithm from the machineKey section of web.config.
  5. Obtain the __VIEWSTATEGENERATOR value from a page such as success.aspx.
  6. Forge a VIEWSTATE using ysoserial with the stolen key and send it to the server to execute an OS command.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

SharePoint lets users build pages from server controls, and some controls are blocked because they are dangerous. The check that blocks them looked at the control name without removing an extra space, so it did not recognise the dangerous control and let it through. The attacker then used that control to read a secret file and run commands on the server.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.