-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathA:sudo-su.sh
76 lines (65 loc) · 1.91 KB
/
A:sudo-su.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
echo
echo -e "\e[1;95m-------------------------[sudo/su audit in progress]-------------------------"
installed=$(dpkg-query -W -f='${Status}' sudo 2>/dev/null | grep -c "ok installed")
if [ $installed -eq 0 ];
then
status="\e[91m[ BAD ]"
#exit
else
status="\e[92m[ GOOD ]"
fi
echo -e "\e[39m[*] Checking sudo installation\t\t\t\t\t\t\t\t$status"
groupwheel=$(getent group wheel 2>/dev/null | grep -c "wheel")
if [ $groupwheel -eq 0 ];
then
status="\e[91m[ BAD ]"
#exit
else
status="\e[92m[ GOOD ]"
fi
echo -e "\e[39m[*] Checking if wheel group exists\t\t\t\t\t\t\t$status"
userexists=$(getent passwd $1 2>/dev/null | grep -c $1)
if [ $userexists -eq 0 ];
then
status="\e[91m[ BAD ]"
echo -e "\e[39m[*] Checking if user exists\t\t\t\t\t\t\t\t$status\e[39m"
else
status="\e[92m[ GOOD ]"
echo -e "\e[39m[*] Checking if user exists\t\t\t\t\t\t\t\t$status\e[39m"
userwheel=$(groups $1|grep -c "\bwheel\b")
if [ $userwheel -eq 0 ];
then
status="\e[91m[ BAD ]"
#exit
else
status="\e[92m[ GOOD ]"
fi
echo -e "\e[39m[*] Checking if $1 is in group wheel\t\t\t\t\t\t\t$status"
fi
suwheel=$(grep -cP '^auth\s+required\s+pam_wheel\.so\s+group=wheel\s+debug$' /etc/pam.d/su)
if [ $suwheel -eq 0 ];
then
status="\e[91m[ BAD ]"
#exit
else
status="\e[92m[ GOOD ]"
fi
echo -e "\e[39m[*] Checking if su usage is restricted to wheel group only\t\t\t\t$status"
if [ ! -f /etc/sudoers ];
then
status="\e[91m[ BAD ]"
echo -e "\e[39m[*] Checking if sudo usage is restricted to wheel group only\t\t\t\t$status\e[39m"
exit
fi
sudowheel=$(grep -cP '^%wheel\s+ALL=\(ALL:ALL\)\s+ALL$' /etc/sudoers)
if [ $sudowheel -eq 0 ];
then
status="\e[91m[ BAD ]"
#exit
else
status="\e[92m[ GOOD ]"
fi
echo -e "\e[39m[*] Checking if sudo usage is restricted to wheel group only\t\t\t\t$status"
echo -e "\033[0m"
echo [SUCCESS] sudo su audit ran by $USER on $(date -u) | tee -a /bin/lib/sh/MK3S/data/MK3S.log