linux下检查arp攻击以及arp防御的shell脚本

arp是有机器伪装成了网关的mac,所以浏览受害机器的arp缓存肯定可以发现一台或者多台机器与网关有相同的mac地址。如果真的有这种情况,就可以判断是arp攻击。具体:

[root@server ~]# arp -a
? (103.231.15.222) at 00:00:5E:00:01:05 [ether] on eth0
? (23.154.118.254) at 0A:9D:C3:CC:81:C9 [ether] on eth0
[root@server ~]# cat /proc/net/arp
IP address HW type Flags HW address Mask Device
103.231.15.222 0x1 0x2 00:00:5E:00:01:05 * eth0
23.154.118.254 0x1 0x2 0A:9D:C3:CC:81:C9 * eth0

[root@server ~]# netstat -rn (获取网关地址)
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0 23.154.118.254 0.0.0.0         UG    100    0        0 eth0
23.154.118.0    0.0.0.0         255.255.255.128 U     100    0        0 eth0

[root@server ~]# arping 23.154.118.254  (或者 arping -I eth0 23.154.118.254)
ARPING 23.154.118.254 from 43.254.218.29 eth0
Unicast reply from 23.154.118.254 [0C:C4:7A:B6:23:80] 1.949ms
Unicast reply from 23.154.118.254 [0C:C4:7A:B6:23:80] 0.814ms
Unicast reply from 23.154.118.254 [0A:9D:C3:CC:81:C9] 483.863ms (欺骗攻击的,响应时间比较长)

看,我们受到的响应中有网关正确的响应(第一行),也有其他主机的arp欺骗响应(第三行后面都是~)

三:解决:arp绑定
1.首先,清空arp缓存。
#arp -d 网关ip

2.找到网关真实mac地址。
#arping 网关ip

3.绑定mac地址
#arp -s 网关ip 网关真实mac

如果是暂时性arp欺骗攻击至此即可,如果网络中常有此问题,继续以下:
4、如下命令建立 /ect/ip-mac 文件
echo \’网关IP地址 网关MAC地址\’ >/ect/ip-mac
通过下面的命令查看文件是否写的正确
more /ect/ip-mac

5、arp -f /ect/ip-mac 加载静态绑定arp记录。

6、如果想开机自动绑定

echo \’arp -f /ect/ip-mac\’ >> /etc/rc.d/rc.local

防止ARP攻击的shell脚本,使用命令route、grep、ifconfig等,需要的朋友可以参考下就不废话了,直接上代码了。

#!/bin/bash
declare gw=`route -n | grep -e \'^0.0.0.0\'`
declare gwname=`echo $gw | grep -oe \'\\w*$\'`
declare gwip=`echo $gw | grep -oe \'[0-9]\\{2,3\\}\\.[0-9]\\{1,3\\}\\.[0-9]\\{1,3\\}\\.[0-9]\\{1,3\\}\'`
declare gwmac=`arp -n | grep -e $gwip | grep -oe \'[0-9A-F]\\{2\\}:[0-9A-F]\\{2\\}:[0-9A-F]\\{2\\}:[0-9A-F]\\{2\\}:[0-9A-F]\\{2\\}:[0-9A-F]\\{2\\}\'`
echo \"switch $gwname arp: $gwip - $gwmac to static\"
arp -s $gwip $gwmac
echo \"done, off arp reuqest ..\"
ifconfig $gwname -arp
echo \"all done.\"

© 版权声明
THE END
文章版权归作者所有,未经允许请勿转载。本站资源均来自互联网,仅供研究学习,禁止违法使用和商用,产生法律纠纷本站概不负责!如果侵犯了您的权益请与我们联系!
点赞4731赞赏 分享
feizhuAdmin的头像-飞猪资源网钻石会员
评论 抢沙发

请登录后发表评论

    暂无评论内容

©文章声明