当出现系统被暴力破解时一般遵循以下处理步骤。
- 确认攻击者
- 封堵攻击者
- 入侵痕迹排查
- 加固系统
一:确认攻击者
查看高频攻击IP
[root@localhost ~]#grep -i "Failed password" /var/log/secure | awk '{print $11}' | sort | uniq -c | sort -nr | head -n 10
259 10.44.32.41
114 admin
19 10.28.98.88
...
"259 10.44.32.41"表示该IP有259次登录失败记录
或者使用如下命令
[root@localhost ~]#grep -i "failed password" /var/log/secure|grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" | uniq -c | sort -nr
1246 10.32.78.3
22 10.98.2.9
3 10.78.3.20
查看成功登录的IP
[root@localhost ~]#grep -i "accepted " /var/log/secure | awk '{print $11}' | sort | uniq -c | sort -nr | more
12 10.3.33.1
7 10.11.2.98
查看成功登录的日期、用户名、IP
[root@localhost ~]#grep -i "accepted " /var/log/secure | awk '{print $1,$2,$3,$9,$11}'
Jul 2 15:36:41 zhangsan 10.23.35.97
Jul 3 11:24:18 root 10.57.36.5
查看爆破用户名字典
[root@localhost ~]#grep -i "Failed password" /var/log/secure | perl -e 'while($_=<>){ /for(.*?) from/; print "$1\n";}' | uniq -c | sort -nr | more
48 root
36 admin
29 guest
二:封堵攻击者
在确认攻击者的IP后应第一时间进行阻断
防火墙封堵
iptables
[root@localhost ~]#iptables -I INPUT -s <攻击IP> -j DROP
##禁止攻击IP访问本机
[root@localhost ~]#iptables -I OUTPUT -d <攻击IP> -j DROP
##禁止本机访问攻击IP
[root@localhost ~]#service iptables save
##持久化,防止重启后失效
[root@localhost ~]#iptables -L
##查看iptables规则
[root@localhost ~]#systemctl status iptables.service
##查看iptables运行状态
也可对攻击IP的整个网段进行封堵,如下所示
[root@localhost ~]#iptables -I INPUT -s 10.25.61.0/24 -j DROP
##禁止"10.25.61.0/24"网段IP访问本机
[root@localhost ~]#iptables -I OUTPUT -d 10.25.61.0/24 -j DROP
##禁止本机访问"10.25.61.0/24"网段
firewalld
[root@localhost Desktop]# firewall-cmd --list-all
##查看当前firewall信息
[root@ocalhost Desktop]#firewall-cmd --zone=public --ad