Key*_*one 7 permissions find files
我一直在尝试使用“one liner”来查找 setuid 可执行文件。
我第一次尝试的线路是:
find / -perm /u+s -type f
Run Code Online (Sandbox Code Playgroud)
然后我找到了一条相似但给出不同结果的行:
find / -perm /6000 -type f
Run Code Online (Sandbox Code Playgroud)
据我所知,这些看起来是一样的,但第一个显示的结果没有第二个那么多(大多数缺少奇怪组的结果)。为什么,有什么不同?
slm*_*slm 10
大多数人不知道,但 Unix 权限实际上不仅仅是用户、组和其他 (rwx)。这三个三元组是允许用户、组和其他用户访问文件和目录的典型权限。然而,在用户位之前还有一组位。这些位被称为“特殊模式”。
它更像是一种速记符号,您在处理诸如chmod
.
$ chmod 644
Run Code Online (Sandbox Code Playgroud)
实际上相当于:
$ chmod 0644
Run Code Online (Sandbox Code Playgroud)
这是位列表:
摘录维基百科文章,标题为:chmod
Flag Octal value Purpose
---- ----------- -------
S_ISUID 04000 Set user ID on execution
S_ISGID 02000 Set group ID on execution
S_ISVTX 01000 Sticky bit
S_IRUSR, S_IREAD 00400 Read by owner
S_IWUSR, S_IWRITE 00200 Write by owner
S_IXUSR, S_IEXEC 00100 Execute/search by owner
S_IRGRP 00040 Read by group
S_IWGRP 00020 Write by group
S_IXGRP 00010 Execute/search by group
S_IROTH 00004 Read by others
S_IWOTH 00002 Write by others
S_IXOTH 00001 Execute/search by others
Run Code Online (Sandbox Code Playgroud)
因此,在您要查找的第一个命令中u+s
,结果是 bit 04000
。当您使用数字符号时,您要求的是位04000
AND 02000
。这将为您提供设置了用户或组 setuid 位的文件。
我强烈建议任何想要更好地了解 Unix 权限的人阅读有关chmod
. 它非常简单地分解它,当您忘记时,它是一个很好的参考。