text stringlengths 0 1.99k |
|---|
we set up a local mirror with a backdoored version of the dash [23] |
package, which is the most downloaded package from melpa.org. We were able |
to execute arbitrary code without any constraints. |
-- 3.4.0 - Attack Scenario: Exploiting Client-Side Vulnerabilities to |
Bypass Signature Validation |
We considered other potential attacks against package managers that |
validate signatures yet handle downloaded files in insecure ways that can |
lead to client-side remote code execution—for example, arbitrary |
file-write vulnerabilities. |
In the following section, we will examine a case study of CVE-2024-11681 |
in MacPorts. |
-- 3.4.1.0 - MacPorts RCE When Syncing from Compromised Mirror |
MacPorts [24] is a package manager for MacOS. Like other package managers, |
such as APT [25], users periodically update the list of available |
packages, their versions, checksums, and so on. They do this by either |
running port sync or, preferably, port selfupdate. Under the hood, the |
client then uses rsync to download a ports.tar.gz archive and its |
corresponding signature file, ports.tar.gz.rmd160. The MacPorts client |
then verifies the signatures or discards the archive if verification |
fails. |
If the signature is valid, the ports.tar.gz file is extracted into the |
same directory that rsync used as its target, creating a directory |
structure like the following: |
total 34776 |
drwxr-xr-x 3 root root 4096 ... 13:37 . |
drwxr-xr-x 3 root root 4096 ... x 13:37 .. |
drwxr-xr-x 4 500 505 4096 ... x 13:37 ports |
-rw-r--r-- 1 root root 35593472 ... x 13:37 ports.tar.gz |
-rw-r--r-- 1 root root 512 ... x 13:37 ports.tar.gz.rmd160 |
The ports directory is essentially an up-to-date version of the |
macports/macports-ports [26] GitHub repository. Each Port contains a |
Portfile [27] within this directory structure. These files are written in |
Tcl [28] and inform the MacPorts client about the name of the Port, |
dependencies, how to build the Port, and more. |
Once the archive is extracted, the MacPorts client attempts to fetch an |
index of all the Ports from the same Rsync server (which is also signed) |
or if it's not served or is outdated, creates its own index using the |
portindex [29] binary. This helper finds all the Portfile files within |
ports and evaluates them. |
When evaluated, a Portfile can instruct the client to execute arbitrary |
system commands, for example: |
set x [exec "bash" "-c" "id > /tmp/poc"] |
We can verify that this works if we create a file called |
ports/foo/bar/Portfile containing the above snippet, then run the |
portindex binary in the ports directory: |
uid=0(root) gid=0(wheel) groups=0(wheel), snip |
The question now becomes, how can an attacker place a controlled Portfile |
on the client's machine, when the archive is signed? We will answer this |
question in the next section. |
-- 3.4.1.1 - Creating Arbitrary Portfiles on Clients Machine from a |
Compromised Mirror |
We previously mentioned that the client uses Rsync to fetch the |
ports.tar.gz file from its configured mirror(s). The important detail here |
is that, the target directory of rsync and the target in which portindex |
are run, are the same. In theory, a malicious server could serve a valid, |
signed archive and additional Portfiles. |
The client blocks this attack by running a second, tightly scoped rsync |
command that fetches only the package index and its signature: |
/usr/bin/rsync \ |
-rtzvl \ |
--delete-after \ |
--include=/PortIndex.rmd160 \ |
--include=/PortIndex \ |
--exclude=* \ |
rsync://localhost:12000/macports/PortIndex_linux_5_i386/ |
The important flags here are: |
* --include=PortIndex.rmd160 |
* --include=PortIndex |
* --exclude=* |
This instructs the Rsync client to only fetch PortIndex and |
PortIndex.rmd160 and reject everything else. |
The problem here is that in some Rsync implementations and versions |
(described in more detail below) these filters are only enforced on the |
server-side. We compiled rsync.samba.org's server version with a single |
change that ignores all filters sent by the client: |
diff --git a/exclude.c b/exclude.c |
index 87edbcf7..05028469 100644 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.