Turning a boring file move into a privilege escalation on Mac
A script run by a setuid-root binary moved a user-controlled file into a directory chosen by the user via a symlink, allowing a low-privileged user to place a crafted file into /etc/sudoers.d. The attacker could then gain root privileges by injecting a sudoers rule that grants passwordless sudo.
While poking around Parallels Desktop I found a script which is invoked by a setuid-root binary, which has the following snippet:
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
The script used a user-writable path for a file move without checking that the destination was not a symlink, allowing a low-privileged user to redirect the move into an arbitrary directory.
Impact
A local low-privileged user could escalate to root, as demonstrated by obtaining a root shell.
What the attacker needed
Local low-privileged user; Parallels Desktop installed
The fix
The vulnerability was fixed in version 18.3.2, likely by preventing the script from following symlinks or by using a safe temporary directory.
How it was found
- Create a symlink at ~/Library/Parallels~ pointing to /etc/sudoers.d/.
- Create a symlink at ~/Library/Parallels pointing to /var/log/install.log.
- Inject a sudoers rule into /var/log/install.log using the logger utility with the install.error priority and a carriage return to start a new line.
- Invoke the vulnerable script (which runs as root) to move the symlink into /etc/sudoers.d/.
- Run sudo su to obtain a root shell.
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-root program runs with high privileges, and it called a script that moved a file from the user's home directory to a backup location. Because the user could control both the file and the backup location (via a symbolic link, which is like a shortcut), they could trick the script into placing a file they control into a sensitive system folder. That folder is used by sudo to decide who can run commands as root, so the user could give themselves full admin rights.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.