Part 1: dispatching to root
A setuid-root binary in SAP HANA Express Edition had a race condition between creating a UNIX socket and changing its ownership/permissions, allowing a member of the sapsys group to make /etc/passwd and /etc/shadow world-writable and gain root. Separately, misconfigured NFS shares without the nosuid option and with world-writable directories allowed a setuid-root shell to be placed on the share, enabling root access on all systems that mounted it.
anvilventures.com
Published on anvilventures.com
This is a story in two parts. First, sometime mid-2019 Anvil was asked by one of its customers to come in and help out with evaluating the security posture of their implementation of some SAP applications.
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 a time-of-check-to-time-of-use race condition in the setuid binary's file permission change, combined with NFS mounts lacking nosuid and allowing world-writable directories.
Impact
The race condition allowed a sapsys group member to escalate to root on a single HANA instance, and the NFS misconfiguration allowed that root access to be extended to all UNIX systems mounting the same shares.
What the attacker needed
Access as a member of the sapsys group; NFS share mounted without nosuid; world-writable directory on the NFS share
The fix
SAP released a patch for the race condition (CVE-2019-0357), and the NFS shares should be rebuilt from known safe media and mounted with the nosuid option and without world-writable directories.
How it was found
- Log in as a user in the sapsys group on the SAP HANA Express system.
- Run the setuid binary hdbmdcdispatcher with the -m 0777 option to set world-writable permissions.
- Repeatedly delete the socket file and create a symbolic link to /etc/shadow or /etc/passwd before the binary changes permissions.
- After the permissions are changed, add a new root-equivalent user to /etc/passwd and /etc/shadow.
- Switch to the new user to obtain a root shell.
- On the NFS share, compile a setuid-root shell, copy it to a world-writable directory, and set the setuid bit.
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.
A setuid program runs with the privileges of its owner (here root) even when started by a normal user. The program created a socket file and then changed its permissions, but an attacker could swap that file for a symbolic link to a sensitive system file in the short window between those steps, causing the program to change the permissions of the sensitive file instead. Separately, a network file share was configured so that files kept their setuid property and anyone could write to it, letting attackers place a root-owned program that any user on any connected machine could run to become…
What is Race condition?
Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.