如何从源代码构建“su”?

如何从源代码构建“su”?

尝试在 Ubuntu 20.04 上构建自定义“su”,但从原始源开始进行测试(不做任何更改)。运行

apt-get source login

我得到了 shadow-4.8.1 目录。运行

./configure
make

然后尝试运行

src/su testuser

它不起作用!身份验证失败错误。运行原始操作系统二进制文件:

/usr/bin/su testuser

而且运行良好!什么鬼?

我认为构建过程中缺少一些模块/参数。

转到 shadow 包的 buildlog。

https://launchpad.net/ubuntu/+source/shadow/1:4.11.1+dfsg1-2ubuntu1/+build/23780688

并查看下一个 ./configure 字符串

./configure --build=x86_64-linux-gnu --prefix=/usr --includedir=\${prefix}/include --mandir=\${prefix}/share/man --infodir=\${prefix}/share/info --sysconfdir=/etc --localstatedir=/var --disable-silent-rules --libdir=\${prefix}/lib/x86_64-linux-gnu --runstatedir=/run --disable-maintainer-mode --disable-dependency-tracking --disable-shared --without-libcrack --mandir=/usr/share/man --with-libpam --enable-shadowgrp --enable-man --disable-account-tools-setuid --with-group-name-max-length=32 --without-acl --without-attr --without-su --without-tcb 

看那边:

--without-su

尝试这个 ./configure 字符串,它确实生成了所有不带“su”的二进制文件。尝试将其替换为

--with-su

新的二进制文件也不起作用。身份验证失败。:(

关于此有两个问题。

  1. 在哪里可以找到原始“su”的构建日志?
  2. 为什么新构建的“su”看不到 /etc/shadow|passwd 中存在的真实操作系统用户?

答案1

一切都顺利汇编进程。但是,su您编译的 属于您的用户,并且没有设置 set uid 位,这意味着它以您的用户身份执行。

您的用户不是有能力切换到其他用户 ID。这是为 root 保留的。

如果你运行ls -l /usr/bin/su,你会看到它由 root 拥有并且设置了 suid 位:

$ ls -l /usr/bin/su
-rwsr-xr-x 1 root root 55480 Apr  1 21:16 /usr/bin/su

您可以通过运行chown root:root /path/to/your/su使其由 root 拥有并chmod 4755 /path/to/your/su使其成为 setuid 来解决此问题。

相关内容