-
Notifications
You must be signed in to change notification settings - Fork 1
/
ruler-2.sh
327 lines (291 loc) · 13 KB
/
ruler-2.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
#!/bin/bash
#========================
#run "sed -i 's/\r$//' start.sh"
#========================
cecho () {
echo -e " | \033[1;32mC\033[0m \033[1;33mS\033[0m \033[1;35mD\033[0m \033[1;36mN\033[0m \E[1;35m阿\033[0m \033[1;34m坤\033[0m |"
}
echo ' .-"""-. '
echo " / .===. \ "
echo " \/ 6 6 \/ "
echo " ( \___/ ) "
echo " _________ooo__\_____/_____________ "
echo " / \ "
cecho
echo " \_______________________ooo________/ "
echo " | | | "
echo " |_ | _| "
echo " | | | "
echo " |__|__| "
echo " /-'Y'-\ "
echo " (__/ \__) "
m=!
echo "=====================Oo欢迎使用安全脚本,祝您使用愉快oO==========================="
echo -e " \033[36mOo安全检测开始oO\033[0m "
#开始
#echo -e "\033[1;32mrunning...\033[0m"
#SBL-System-Linux-01-01
result=`awk -F: '($3 == 0) { print $1 }' /etc/passwd`
if [ $result == root ]
then
echo -e "\033[34m01.\033[0m\033[35mSBL-System-Linux-01-01$m\033[0m \033[1;32m[OK]\033[0m"
else
echo -e "\033[34m01.\033[0m\033[35mSBL-System-Linux-01-01$m\033[0m \033[1;31m[Failed]\033[0m"
fi
#SBL-System-Linux-01-02
result2=`awk -F: '($2 == "") { print $1 }' /etc/shadow`
if [ "$result2" == "" ]
then
echo -e "\033[34m02.\033[0m\033[35mSBL-System-Linux-01-02$m\033[0m \033[1;32m[OK]\033[0m"
else
echo -e "\033[34m02.\033[0m\033[35mSBL-System-Linux-01-02$m\033[0m \033[1;31m[Failed]\033[0m"
fi
#SBL-System-Linux-01-03
result3=`cut -d: -f1 /etc/passwd &>/dev/null && echo $?`
if [ $? == "0" ]
then
echo -e "\033[34m03.\033[0m\033[35mSBL-System-Linux-01-03$m\033[0m \033[1;32m[OK]\033[0m"
else
echo -e "\033[34m03.\033[0m\033[35mSBL-System-Linux-01-03$m\033[0m \033[1;31m[Failed]\033[0m"
fi
#SBL-System-Linux-02-01
#原始值:99999
#sed -i "s/^PASS_MAX_DAYS.*/PASS_MAX_DAYS 90/g" /etc/login.defs
#result4=`cat /etc/login.defs | grep ^PASS_MAX_DAYS | awk -F" " '{print $2}'`
#if [ $result4 == "90" ]
# then
# echo -e "\033[34m04.\033[0m\033[35mSBL-System-Linux-02-01$m\033[0m \033[1;32m[OK]\033[0m"
#else
# echo -e "\033[34m04.\033[0m\033[35mSBL-System-Linux-02-01$m\033[0m \033[1;31m[Failed]\033[0m"
#fi
#SBL-System-Linux-02-02
#原始值:0
#sed -i "s/^PASS_MIN_DAYS.*/PASS_MIN_DAYS 1/g" /etc/login.defs
#result5=`cat /etc/login.defs | grep ^PASS_MIN_DAYS | awk -F" " '{print $2}'`
#if [ $result5 == "1" ]
# then
# echo -e "\033[34m05.\033[0m\033[35mSBL-System-Linux-02-02$m\033[0m \033[1;32m[OK]\033[0m"
#else
# echo -e "\033[34m05.\033[0m\033[35mSBL-System-Linux-02-02$m\033[0m \033[1;31m[Failed]\033[0m"
#fi
#SBL-System-Linux-02-03
#原始值:5
sed -i "s/^PASS_MIN_LEN.*/PASS_MIN_LEN 8/g" /etc/login.defs
result6=`cat /etc/login.defs | grep ^PASS_MIN_LEN | awk -F" " '{print $2}'`
if [ $result6 == "8" ]
then
echo -e "\033[34m06.\033[0m\033[35mSBL-System-Linux-02-02$m\033[0m \033[1;32m[OK]\033[0m"
else
echo -e "\033[34m06.\033[0m\033[35mSBL-System-Linux-02-02$m\033[0m \033[1;31m[Failed]\033[0m"
fi
#SBL-System-Linux-02-04
#原始值:7
#sed -i "s/^PASS_WARN_AGE.*/PASS_WARN_AGE 14/g" /etc/login.defs
#result7=`cat /etc/login.defs | grep ^PASS_WARN_AGE | awk -F" " '{print $2}'`
#if [ $result7 == "14" ]
# then
# echo -e "\033[34m07.\033[0m\033[35mSBL-System-Linux-02-04$m\033[0m \033[1;32m[OK]\033[0m"
#else
# echo -e "\033[34m07.\033[0m\033[35mSBL-System-Linux-02-04$m\033[0m \033[1;31m[Failed]\033[0m"
#fi
#SBL-System-Linux-03-01
#结果为:空正常
result8=`echo $PATH | sed 's|:|\n|g' | grep "\."`
if [ "$result8" == "." ]
then
echo -e "\033[34m08.\033[0m\033[35mSBL-System-Linux-03-01$m\033[0m \033[1;31m[Failed]\033[0m"
echo "$result8"
else
echo -e "\033[34m08.\033[0m\033[35mSBL-System-Linux-03-01$m\033[0m \033[1;32m[OK]\033[0m"
fi
#SBL-System-Linux-03-02
chmod +644 /etc/passwd &&
chmod +000 /etc/shadow &&
chmod +644 /etc/group &&
chmod +644 /etc/services &&
echo -e "\033[34m09.\033[0m\033[35mSBL-System-Linux-03-02$m\033[0m \033[1;32m[OK]\033[0m" ||
echo -e "\033[34m09.\033[0m\033[35mSBL-System-Linux-03-02$m\033[0m \033[1;31m[Failed]\033[0m"
#SBL-System-Linux-03-03
chmod +755 /etc &&
chmod +755 /etc/security &&
chmod +755 /etc/rc.d &&
echo -e "\033[34m10.\033[0m\033[35mSBL-System-Linux-03-03$m\033[0m \033[1;32m[OK]\033[0m" ||
echo -e "\033[34m10.\033[0m\033[35mSBL-System-Linux-03-03$m\033[0m \033[1;31m[Failed]\033[0m"
#SBL-System-Linux-03-04
#结果为:002/022为正常
num1=`cat /etc/profile | grep -i "umask 002" | awk -F" " '{printf $2}' && cat /etc/bashrc | grep -i "umask 022" | awk -F" " '{print $2}'`
num2=`cat /etc/csh.cshrc | grep -i "umask 002" | awk -F" " '{printf $2}' && cat /etc/bashrc | grep -i "umask 022" | awk -F" " '{print $2}'`
num3=`cat /etc/bashrc | grep -i "umask 002" | awk -F" " '{printf $2}' && cat /etc/bashrc | grep -i "umask 022" | awk -F" " '{print $2}'`
number=`echo "$num1$num2$num3"`
if [ "$number" == "002022002022002022" ]
then
echo -e "\033[34m11.\033[0m\033[35mSBL-System-Linux-03-04$m\033[0m \033[1;32m[OK]\033[0m"
else
echo -e "\033[34m11.\033[0m\033[35mSBL-System-Linux-03-04$m\033[0m \033[1;31m[Failed]\033[0m"
fi
#SBL-System-Linux-04-01
#结果为:authpriv.* /var/log/secure
char1=`cat /etc/rsyslog.conf | grep ^authpriv.*`
char2="authpriv.* /var/log/secure"
if [ "$char1" == "$char2" ]
then
echo -e "\033[34m12.\033[0m\033[35mSBL-System-Linux-04-01$m\033[0m \033[1;32m[OK]\033[0m"
else
echo -e "\033[34m12.\033[0m\033[35mSBL-System-Linux-04-01$m\033[0m \033[1;31m[Failed]\033[0m"
fi
#SBL- System- Linux-05-01
#原始值:yes
sed -i "s/^PermitRootLogin.*/PermitRootLogin no/g" /etc/ssh/sshd_config
result9=`cat /etc/ssh/sshd_config | grep PermitRootLogin | head -n 1`
if [ "$result9" == "PermitRootLogin no" ]
then
echo -e "\033[34m13.\033[0m\033[35mSBL-System-Linux-05-01$m\033[0m \033[1;32m[OK]\033[0m"
else
sed -i "s/^#PermitRootLogin.*/PermitRootLogin no/g" /etc/ssh/sshd_config &&
echo -e "\033[34m13.\033[0m\033[35mSBL-System-Linux-05-01$m\033[0m \033[1;32m[OK]\033[0m"
fi
#SBL- System- Linux-05-02
#yum -y remove telnet &>/dev/null &&
#systemctl start sshd &&
#echo -e "\033[34m14.\033[0m\033[35mSBL-System-Linux-05-02$m\033[0m \033[1;32m[OK]\033[0m" ||
#echo -e "\033[34m14.\033[0m\033[35mSBL-System-Linux-05-02$m\033[0m \033[1;31m[Failed]\033[0m"
#SBL- System- Linux-05-03
#原始值:无
#result10=`cat /etc/hosts.allow |grep ^sshd`
#if [ "$result10" == "" ]
# then
# echo "sshd:192.168.:allow" >> /etc/hosts.allow
# echo "sshd:ALL" >> /etc/hosts.deny
#fi
#result10=`cat /etc/hosts.deny |grep ^sshd`
#if [ "$result10" == "sshd:ALL" ]
# then
# echo -e "\033[34m15.\033[0m\033[35mSBL-System-Linux-05-03$m\033[0m \033[1;32m[OK]\033[0m"
#else
# echo -e "\033[34m15.\033[0m\033[35mSBL-System-Linux-05-03$m\033[0m \033[1;31m[Failed]\033[0m"
#fi
#SBL-System-Linux-06-02
systemctl stop snmpd &>/dev/null &&
systemctl disable snmpd &>/dev/null
echo -e "\033[34m17.\033[0m\033[35mSBL-System-Linux-06-02$m\033[0m \033[1;32m[OK]\033[0m"
#SBL-System-Linux-06-03
chkconfig --list &>/dev/null &&
echo -e "\033[34m18.\033[0m\033[35mSBL-System-Linux-06-03$m\033[0m \033[1;32m[OK]\033[0m"
#SBL-System-Linux-06-04
chkconfig --list &>/dev/null &&
echo -e "\033[34m19.\033[0m\033[35mSBL-System-Linux-06-04$m\033[0m \033[1;32m[OK]\033[0m"
#SBL-System-Linux-07-01
result11=`find / -name .rhosts`
result12=`find / -name .netrc`
if [ "$result11" == "" ]
then
if [ "$result12" == "" ]
then
echo -e "\033[34m20.\033[0m\033[35mSBL-System-Linux-07-01$m\033[0m \033[1;32m[OK]\033[0m"
fi
else
echo -e "\033[34m20.\033[0m\033[35mSBL-System-Linux-07-01$m\033[0m \033[1;31m[Failed]\033[0m"
fi
#SBL-System-Linux-08-01
yum -y install bc &>/dev/null &&
ip3=`ip addr | grep eth0 | grep inet | awk -F" " {'print $2'} | awk -F"." {'print $3'}`
ip4=`ip addr | grep eth0 | grep inet | awk -F" " {'print $2'} | awk -F"." {'print $4'} | awk -F"/" {'print $1'}`
sum=`bc <<< $ip4+111`
useradd user1 &&
sed -i "/^root/a user1 ALL=(ALL) ALL" /etc/sudoers && echo "Zhongkedanao$ip3$ip4@$sum" | passwd --stdin user1&>/dev/null
result13=`cat /etc/sudoers |grep ^user1`
if [ "$result13" == "user1 ALL=(ALL) ALL" ]
then
echo -e "\033[34m21.\033[0m\033[35mSBL-System-Linux-08-01$m\033[0m \033[1;32m[OK]\033[0m"
else
echo -e "\033[34m21.\033[0m\033[35mSBL-System-Linux-08-01$m\033[0m \033[1;31m[Failed]\033[0m"
fi
#CentOS-8CT-JX-LINUX-8
sed -i "s/UMASK 077/UMASK 027/g" /etc/login.defs
num4=`cat /etc/login.defs |grep UMASK | awk 'NR == 1' | awk {'print $2'}`
if [ "$num4" == "027" ]
then
echo -e "\033[34m21.\033[0m\033[35mCentOS-8CT-JX-LINUX-08$m\033[0m \033[1;32m[OK]\033[0m"
else
echo -e "\033[34m21.\033[0m\033[35mCentOS-8CT-JX-LINUX-08$m\033[0m \033[1;31m[Failed]\033[0m"
fi
#CentOS-18CT-JX-LINUX-18
mv /etc/issue /etc/issue.bak
mv /etc/issue.net /etc/issue.net.bak
cat /etc/issue.net &>/dev/null || cat /etc/issue.net &>/dev/null ||
if [ "$?" != "0" ]
then
echo -e "\033[34m21.\033[0m\033[35mCentOS-18CT-JX-LINUX-18$m\033[0m \033[1;32m[OK]\033[0m"
else
echo -e "\033[34m21.\033[0m\033[35mCentOS-18CT-JX-LINUX-18$m\033[0m \033[1;31m[Failed]\033[0m"
fi
#ssh/sshd_config
sport=`cat /etc/ssh/sshd_config |grep ^Port |awk -F" " {'print $2'}`
value1=`cat /etc/ssh/sshd_config |grep "^#Port"`
value2=`cat /etc/ssh/sshd_config |grep "^Port"`
if [ "$sport" == "6122" ]
then
echo -e "\033[34m21.\033[0m\033[35mSet-SSH-Port=6122$m\033[0m \033[1;32m[OK]\033[0m"
elif [ "$sport" != "" ]
then
sed -i "s/$value2/Port 6122/g" /etc/ssh/sshd_config
elif [ "$sport" == "" ]
then
sed -i "s/$value1/Port 6122/g" /etc/ssh/sshd_config
else
echo -e "\033[34m21.\033[0m\033[35mSet-SSH-Port=6122$m\033[0m \033[1;31m[Failed]\033[0m"
fi
systemctl restart sshd &>/dev/null &&
systemctl enable sshd &>/dev/null
#userlock
cp /etc/pam.d/sshd /etc/pam.d/sshd.bak &>/dev/null
cp /etc/pam.d/login /etc/pam.d/login.bak &>/dev/null
find / -name "pam_tally2.so" &>/dev/null &&
if [ "$?" == "0" ]
then
sed -i '/^#%PAM-1.0/a auth required pam_tally2.so deny=10 unlock_time=20 even_deny_root root_unlock_time=30' /etc/pam.d/sshd &&
systemctl restart sshd &&
sed -i '/^#%PAM-1.0/a auth required pam_tally2.so deny=10 unlock_time=20 even_deny_root root_unlock_time=30' /etc/pam.d/login &&
echo -e "\033[34m21.\033[0m\033[35mUser-Lock$m\033[0m \033[1;32m[OK]\033[0m"
else
echo -e "\033[34m21.\033[0m\033[35mUser-Lock$m\033[0m \033[1;31m[Failed]\033[0m"
fi
#SBL-System-Linux-06-01
#原始值:systemctl stop firewalld && systemctl disable firewalld
systemctl start firewalld &&
systemctl enable firewalld &>/dev/null &&
echo -e "\033[34m16.\033[0m\033[35mSBL-System-Linux-06-01$m\033[0m \033[1;32m[OK]\033[0m"
### firewalld--TCP
# tcp6-port
netstat -tpln | awk 'NR>2' | grep tcp6 |awk '{print $4}' |awk -F: '{print $4}' >> ./test-tcp6
netstat -tpln | awk 'NR>2' | grep tcp6 |awk '{print $4}' |awk -F: '{print $2}' >> ./test-tcp6
# delete null
sed -i '/^ *$/d' ./test-tcp6
# tcp-port
netstat -tpln | awk 'NR>2' | grep -v tcp6 |awk '{print $4}' |awk -F: '{print $2}' >> ./test-tcp
# delete null
sed -i '/^ *$/d' ./test-tcp
#
for i in $(cat ./test-tcp)
do
firewall-cmd --zone=public --add-port=$i/tcp --permanent &>/dev/null
#echo "$i" >> port.txt
done
for i in $(cat ./test-tcp6)
do
for h in $(cat ./test-tcp )
do
if [ $i == $h ];then
# echo "repeat"
break
else
firewall-cmd --zone=public --add-port=$i/tcp --permanent &>/dev/null
#echo "$i" >> port.txt
fi
done
done
firewall-cmd --reload &>/dev/null && echo -e "\033[34m22.\033[0m\033[35mSBL-System-Linux-08-02$m\033[0m \033[1;32m[OK]\033[0m"
firewall-cmd --zone=public --list-ports >> port.txt
rm -rf ruler-2.sh && rm -rf test-tcp* &&
echo " --------------自动检测完成!--------------- "
echo "==============================期待您的再次使用!!==============================="