【发布时间】:2017-06-06 22:00:57
【问题描述】:
我在这里有这个 bash 脚本,我正在尝试修改它以检查是否只有一个 root id,它是否容易受到攻击,目前,这个脚本只检查是否有重复的 uid 并显示共享相同的用户uid。提前致谢! :)
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
【问题讨论】:
-
我建议用
uniq -c替换uniq-c,请看一下:shellcheck.net -
您是否有理由为
cut、grep、awk等基本命令使用完整路径? -
@codeforester 这是给我的一个例子,我是 bash 脚本的初学者,直到你指出我才意识到这一点,感谢您的输入!
标签: linux bash scripting rhel audit