如何识别二进制文件是否设置了用户 ID?

如何识别二进制文件是否设置了用户 ID?

在Linux中,如何识别二进制文件是否为set-user-ID?

我可以用吗ls -l

答案1

执行ls -l你会得到类似的东西:

-rwSr--r--   1 user user    8111573 Sep 26  2012 net-snmp.tar

其中S(也可以是s) 表示该文件设置了 SUID 位

S当您没有设置执行标志时设置

s当您设置了执行标志时设置

答案2

使用 手动查看文件ls -l filename,或者通过您可以使用的脚本查看文件

[ -u filename ] && echo SUID-bit is set

也可以看看man bash

   -u file
          True  if  file  exists  and its set-user-id bit is set.

也可以看看info ls

 The file mode bits listed are similar to symbolic mode
 specifications (*note Symbolic Modes::).  But ‘ls’ combines
 multiple bits into the third character of each set of permissions
 as follows:

 ‘s’
      If the set-user-ID or set-group-ID bit and the corresponding
      executable bit are both set.

 ‘S’
      If the set-user-ID or set-group-ID bit is set but the
      corresponding executable bit is not set.

相关内容