This week we dive into the details of a number of local privilege escalation vulnerablities discovered by Qualys in the needrestart package, covering topics from confused deputies to the inner workings of the /proc filesystem and responsible disclosure as well.
/proc/self/exe
to first identify the interpreter as say python/proc/self/cmdline
to determine the primary file being run
by the interpreter and from that looks at import
statements to determine
which files are likely being used/proc/pid/environ
and executes the Python interpreter with this same value
to get it to resolve the imports to files on disk__init__.so
files from that path, the attacker controlled shared object
is then executed by Python running as root via needrestartRUBYLIB
env var) may also be affected and subsequently confirmed this to be the casePYTHONPATH
used by the interpreter, is about the interpreter binary itself
/proc/pid/exe
entry - matches this against a regex like
/usr/bin/python - back in 2022 Jakub Wilk discovered a vuln where the regex
was not anchored, so if a process was running via a attacker controlled
interpreter (/home/amurray/usr/bin/python
) this would match and
needrestart would execute that interpreter directly as root - CVE-2022-30688/proc/pid/exe
twice - once early on when collecting info on all processes, and then a
second time to determine if it is say a Python application - but when
needrestart goes and executes this interpreter to do the PYTHONPATH lookups
etc, it uses the original value that it collected at the start of its run/proc/self/exe
to trick needrestart -
which will then go and execute its original malicious interpreter binaryopen
with a string that ends in a
pipe (|
) and it will instead execute that string as a shell commandopen
on any files that it finds along
the way in its analysis - and since these filenames are controlled by the
unprivileged attacker, can create a file which ends in a pipe character
(e.g. /home/amurray/bin/pwned|
) and Perl will then just execute that
script directlyeval()
on contents from
these files as well - directly executing whatever strings found as Perl codeuse
directives/proc/pid/exe
path to match
against when looking for interpreted processes to remove the TOCTOU race/proc
filesystem - this is a virtual filesystem managed by the kernel, representing
information about processes in userspace