5

After upgrading to MacOS Sierra (10.12), my sudo command seems to be acting differently. See the following test case:

# Run in terminal pane #1: (should prompt for password)
sudo -v

# Run in terminal pane #2: (should NOT prompt for password)
sudo -v

The above works as expected on earlier versions of OS X. However, on Sierra, the second command prompts for the password again. It does not prompt for the password within the same terminal pane. This seems to only happen for the root user; the following works as expected on all OS versions including Sierra:

# Run in terminal pane #1: (prompts for password)
sudo -v -u "$USER"

# Run in terminal pane #2: (does not prompt for password)
sudo -v -u "$USER"

Looking at /ect/sudoers, the timestamp_timeout value is not set to 0. I've briefly looked over the changelog for 1.7 to 1.8 but could not come up with anything significant other than there being a mention of a policy plugin for Sierra when running sudo -V.

Can anybody help me figure out what has changed? I have a script that relies on the sudo timeout value for a keepalive and on Sierra it is prompting for the password constantly since it seems to no longer use a timestamp for the root user.

4

2 回答 2

11

经过大量搜索并将sudo旧操作系统版本上的配置与 Sierra ( sudo su; sudo -V) 的配置进行比较后,似乎 Sierratty_tickets现在默认启用,导致上述问题。据我所知,这是一个未记录的更改。要修复,需要/etc/sudoers通过运行将以下内容添加到文件中sudo visudo

Defaults !tty_tickets
于 2016-09-13T16:11:29.260 回答
0

TLDR;馊主意。这种旧行为虽然是 sudo 的一个选项,但我从未遇到过任何其他 UNIX-y 操作系统都将其用作默认行为。原因是它很容易被利用,而当被利用时,恶意代码会完全控制你的系统。

原始的很长的咆哮帖子,正确地指出是 blahdiblah:

大声笑,这很有趣。我是通过谷歌搜索来到这里的,因为我不记得如何将旧行为更改为这个新的、正确的行为(被其他所有 UNIX-y 操作系统使用)。甚至没有注意到我的新 Sierra Mac 现在表现正常。

我早些时候在 Mac 论坛上写过关于这种先前行为的文章,这是一个巨大的安全漏洞。我什至提供了一个三行概念验证脚本,它会简单地(作为普通用户)等待sudo事件出现在任何地方,然后立即获得对系统的 root 访问权限。我被粉丝们嘘了出来,然后被禁止说谎。不过,苹果似乎在听。干得好,这一次,库比蒂诺。糟糕,糟糕的想法是试图恢复旧的行为。

作为参考,这里是三班轮。它不会做任何恶意的事情,只是在获得 sudo 后将一个虚拟文件添加到文件系统的根目录。在脚本中运行它(或者只是将它粘贴到没有 sudo 的地方),然后在另一个终端应用程序/窗口或使用 sudo 的应用程序(例如 TrueCrypt/VeraCrypt 或类似)中执行 sudo,然后观察它的工作。

tail -f -n 0 /var/log/system.log | grep -m 1 -E 'sudo\[[0-9]+\]:\s+'$USER
echo "Gonna play around with root privs ..."
sudo touch /kilroy-was-here
于 2017-01-11T06:48:53.487 回答