近期,快要邻近春节,安全方面更加重要。
首先要对操作系统的用户做安全监控,防止操作系统账号被爆破泄露,我们也要监控起来。
(1)Zabbix记录每分钟日志登录失败的次数
(2)Zabbix记录登录失败用户的信息,方便查看
首先,我们整个集群日志,通过rsyslog服务,把上千台的日志同步到一台上,所以我们只需要监控这个rsyslog的服务端就可以了。
看效果图(这样一来,十分方便查看记录)




(1) 登录失败次数
日志格式
1
|
2021-12-29T15:04:16.264895+08:00 127.0.0.1 [sshd] notice: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=172.17.9.200 user=deployer
|
编写代码的脚本
1
2
3
4
5
6
7
8
9
10
11
|
#!/bin/bash
LOG_PATH="/var/log/secure"
mon=$(date +%B)
h=$(date +%d)
ms=$(date +%H:%M)
#表示字符开头为0就替换为空
h=${h/#0/""}
k="T" #我这边有T,有的是空格,根据时间环境使用
count=`grep "$h$k$ms" /var/log/secure | grep -v sudo | grep -c "authentication failure" `
echo $count
|
修改zabbix客户端配置
1
2
|
#====================检查 账号登录失败次数======================
UserParameter=check_failed,sh /usr/local/zabbix-v503/scripts/check_failed.sh
|
重启zabbix客户端
zabbix界面配置
检查配置

触发器

(2)失败日志记录
编写脚本
1
2
3
4
5
6
7
8
9
10
11
12
|
[root@logserver01 zabbix-v503]# cat scripts/check_failedlog.sh
#!/bin/bash
LOG_PATH="/var/log/secure"
mon=$(date +%B)
h=$(date +%d)
#获取前一分钟的爆破日志记录的时间 时:分
ms=$(date -d "1 minute ago" +"%H:%M")
#表示字符开头为0就替换为空
h=${h/#0/""}
k="T"
grep "$h$k$ms" /var/log/secure | grep -v sudo | grep "authentication failure" >> /usr/local/zabbix-v503/scripts/fail.log
|
开启定时任务(每分钟检查一次)
1
2
|
#-------check_fail_user_log-----------------
* * * * * sh /usr/local/zabbix-v503/scripts/check_failedlog.sh
|
如果有登录失败的,会单独过滤出来

zabbix界面配置
1
|
log[/usr/local/zabbix-v503/scripts/fail.log,"sshd",skip,]
|

已经完成相关的项目类容,很容易监控。

根据触发器,可以设置值,如果每分钟爆破登录失败10次,就报警,有爆破的嫌疑