/usr/bin/passwd 和 CAP_CHOWN 功能

发布于 2024-12-11 03:59:33 字数 302 浏览 2 评论 0原文

我正在试验 Linux 功能,我注意到,要使 passwd 程序在没有 Set-UID root 的情况下工作,它需要具有 CAP_CHOWN 功能(除了一些其他的)。从逻辑上讲,为什么需要 CAP_CHOWN 呢?

顺便说一句,如果我删除该功能,passwd 会给我一个“令牌操作错误”。

编辑:我使用的是没有 SELinux 的 Ubuntu 11.04。我正在尝试让 passwd 在不成为 Set-UID root 的情况下工作。

I was experimenting with Linux Capabilities, and I noticed that for the passwd program to work without being Set-UID root, it needs to have the CAP_CHOWN capability (in addition to some others). Logically, why would it need to have CAP_CHOWN at all?

Incidentally, passwd gives me a "token manipulation error" if I remove the capability.

Edit: I'm using Ubuntu 11.04 without SELinux. I'm trying to get passwd to work without being Set-UID root.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不离久伴 2024-12-18 03:59:33

passwd 本身不需要 cap_chown。只需要更改与 userID 关联的 /etc/shadow 文件。
/etc/shadow 文件已设置为任何人都无法读取。

/etc/shadow 只能由 root 访问。因此,当 /etc/passwd 完成其身份验证模块并准备写入新的(编码的)密码时,它将创建一个令牌。它由 Linux-PAM 服务访问,该服务会将其 chown 到 root 并将其写入 /etc/shadow。

编辑:

passwd 使用文件 /etc/.pwd.lock 、 /etc/shadow 、 /etc/nshadow 。
由于passwd从/etc目录中读取和写入,因此需要w权限。请注意,/etc/shadow 永远不会由 passwd 写入。 passwd 实际上写入 /etc/nshadow 并将 /etc/nshadow 重命名为 /etc/shadow。

open('/etc/nshadow',O_WRONLY|O_CREAT)=fd1
open('/etc/shadow', O_RDONLY)=fd2
fchown(fd1, uid=root, gid=shadow)
chmod /etc/shadow to : rw by owner and r by group
read(fd2)
write(fd1)
rename("/etc/nshadow", "/etc/shadow")

此外,我使用这个C程序确认了/etc/nshadow的存在。供参考,

#include<stdio.h>
#include<unistd.h>
int main()
{
while(1)
if (access("/etc/nshadow",F_OK)!=-1){
    printf("Exists\n");
    break;
    }
return 0;
}

The cap_chown is not required for the passwd itself. It is only needed to change the /etc/shadow file associated with the userID.
The /etc/shadow file is set so that it cannot be read by just anyone.

/etc/shadow is only accessible to root. So when /etc/passwd finishes it's authentication module and is ready to write a new (encoded) password, it will create a token. Which is accessed by the Linux-PAM service, which will chown it to root and write it into /etc/shadow.

Edit:

passwd uses the files /etc/.pwd.lock, /etc/shadow , /etc/nshadow.
Since passwd reads and writes from /etc directory, w permissions are requried by it. Note that, /etc/shadow is never written by passwd. passwd actually writes to /etc/nshadow and renames /etc/nshadow to /etc/shadow.

open('/etc/nshadow',O_WRONLY|O_CREAT)=fd1
open('/etc/shadow', O_RDONLY)=fd2
fchown(fd1, uid=root, gid=shadow)
chmod /etc/shadow to : rw by owner and r by group
read(fd2)
write(fd1)
rename("/etc/nshadow", "/etc/shadow")

Furthermore, I confirmed the existence of /etc/nshadow using this C program. FYI,

#include<stdio.h>
#include<unistd.h>
int main()
{
while(1)
if (access("/etc/nshadow",F_OK)!=-1){
    printf("Exists\n");
    break;
    }
return 0;
}
白云不回头 2024-12-18 03:59:33

setuid 就是最初所需要的。

SELinux安全增强)的添加要求程序上下文是正确以及文件权限检查。

如果系统的 SE 功能被禁用,passwd 将正常工作,无需任何 CAP_...。我在某处读到可以通过向 /selinux/disable 写入“1”来禁用 SE。大概写“0”会重新启用它。

请参阅NSA 的描述Fedora 的

setuid is all that originally was needed.

The additions of SELinux (Security Enhanced) requires the program context to be correct as well as file permission checks.

If the system's SE feature is disabled, passwd will work fine without any CAP_.... Somewhere I read that SE can be disabled by writing a "1" to /selinux/disable. Presumably writing "0" reenables it.

See NSA's description or Fedora's.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文