zsh-users
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: Andrew Parker <andrew.j.c.parker@gmail.com>
Cc: zsh-users@zsh.org
Subject: Re: Thoughts on protecting against PATH interception via user owned profiles
Date: Sun, 15 Dec 2019 07:14:17 +0000	[thread overview]
Message-ID: <20191215071417.ivb76lzapj43ag3z@tarpaulin.shahaf.local2> (raw)
In-Reply-To: <CAG78ipVksGrRjOdV0H=qofrtSNHfeh_OHg2GD9AjjnbF42JoMw@mail.gmail.com>

Andrew Parker wrote on Sun, Dec 15, 2019 at 14:27:45 +0800:
> I'm curious to hear the community's thoughts on the threat of PATH
> interception in shells. Specifically, it's very easy for a malicious
> process, running as regularly user, to interfere with your profiles and
> there's no fool-proof way to protect against this. For example, a malicious
> binary can easily change a profile to insert something into your PATH. Once
> that's done a privilege escalation is extremely feasible due to the vast
> number of tools that rely on your path and which don't specify full paths
> to binaries they in turn shell out to.

So you're saying is that an attacker that can run arbitrary code as your user
*now* can use this to modify script files (such as ~/.zshenv) to be able to run
arbitrary code as you *later*.

First of all, this is not what's normally meant by a "privilege escalation"
attack.  That generally means "Alice can run code as Bob".

As to your attacker, you could uninstall zsh entirely and he'd still have any
number of ways to run code as you — for example, by editing
~/.config/autostart/, or ~/.xinitrc, or ~/.vimrc, or ~/.gitconfig¹, etc., or by
running crontab(1) or at(1).

The short answer here is that untrusted applications should not be given write
access to files that will be executed by trusted programs.  Traditionally,
untrusted applications would be run under a dedicated unprivileged uid, and
their output sanitized if needed.  Nowadays there are tools such as Qubes
(q.v.).

> My question is whether zsh (and other shells) would ever be interested in
> implementing a solution to this. My suggestion would be something like the
> following (although there may be better alternatives):
> 
> * zsh uses a config file in e.g. /etc directory which much be owned and
> only writable by root
> * The config can be used enable "protected profiles"
> * Once protected profiles are enabled, only profiles which are owned and
> only writable by root can be sourced on startup
> 

I think you've basically reinvented Perl's taint mode ("perl -T").

Anyway, even if you wanted to implement a taint mode in zsh, treating dotfiles
as tainted is simply not enough.  There's any number of ways to mount
a "delayed code execution" attack _against zsh_ without editing the dotfiles.

Cheers,

Daniel

¹ «git <TAB><Esc>which __git_config_option-or-value | egrep -c '_absolute_command_names|_cmdstring'»
  prints 33.

  reply	other threads:[~2019-12-15  7:15 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-15  6:27 Andrew Parker
2019-12-15  7:14 ` Daniel Shahaf [this message]
2019-12-15  7:57   ` Andrew Parker
2019-12-15  8:49     ` Daniel Shahaf
2019-12-15 17:42     ` Lewis Butler
2019-12-15 18:57     ` Grant Taylor
2019-12-15 19:47     ` Bart Schaefer
2019-12-17 13:34       ` Andrew Parker
2019-12-15  8:41 ` Roman Perepelitsa
2019-12-15  8:49   ` Andrew Parker
2019-12-15 14:31   ` Andrew Parker
2019-12-15 14:43     ` Roman Perepelitsa
2019-12-17 13:35       ` Andrew Parker
2019-12-16  4:10   ` Daniel Shahaf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191215071417.ivb76lzapj43ag3z@tarpaulin.shahaf.local2 \
    --to=d.s@daniel.shahaf.name \
    --cc=andrew.j.c.parker@gmail.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).