Bash:如何检查是否只有一个根ID且所有用户UID都是唯一的? [英] Bash: how to check if there is only one root id and all user UIDs are unique?

查看:226
本文介绍了Bash:如何检查是否只有一个根ID且所有用户UID都是唯一的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里有一个bash脚本,我正尝试修改它以检查是否只有一个root id,是否容易受到攻击,当前,此脚本仅检查是否存在重复的uid,并显示共享相同ID的用户uid.提前致谢! :)

i have this bash script here that i'm trying to modify to check if there is only one root id, is it vulnerable and currently, this script only checks if there is a duplicate uid and display the users that shares the same uid. Thanks in advance! :)

Bash脚本:

#!/bin/bash
/bin/cat /etc/passwd| /bin/cut -f3 -d":" | /bin/sort -n | /usr/bin/uniq-c | while 
read x ; do
  [ -z "${x}" ] && break
  set -$x
  if [ $1 -gt1 ]; then
       users=`/bin/gawk -F: '($3 == n) { print $1 }' n=$2 /etc/passwd| /usr/bin/xargs`
       echo "Duplicate UID ($2): ${users}"
  fi
done

预期输出:

Audit criteria: There is only one root id

Vulnerability: Yes

Details: See below


root:!:0:0::/:/usr/bin/bash

jdoe:*:0:1:John Doe:/home/jdoe:/usr/bin/bash

推荐答案

您可以使用awk找出答案:

if ! awk -F: '$3==0{c++}END{exit !(c<2)}' /etc/passwd ; then
    echo "More than one user with uid 0"
fi

这篇关于Bash:如何检查是否只有一个根ID且所有用户UID都是唯一的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆