您的位置:首页 > 运维架构 > Shell

linux下防止ARP攻击的shell脚本

2018-02-09 22:23 288 查看

防止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."


Windows下的用户可以使用antiArp防火墙,基本上能解决问题,可是喜欢linux的兄弟姐妹们怎么办呢,我今天就遇到这个档子烦心事。

我用的是fedora core 6,我先把几个镜像文件挂上,用关键字arp一搜,就搜到了arptables,和arpwatcher 首先是arpwatcher了,它好像只能监控本机ip/arp地址的改变之类的,好像不能防止arp攻击。 再一看arptables,立马想到了iptables,装上一看,果然,命令行都一模一样。 可是问题来了,保持本机不受arp攻击很简单(用静态arp绑定就可以了),但是人家网关也还是要受到攻击, 俺们又不是网络管理员,网关我只能 “远观而不能亵玩“!

此路不通,俺们改道,arping这个东西映入我的眼帘,回到shell,发现已经安装拉:

“arping - send ARP REQUEST to a neighbour host“arping [ -AbDfhqUV] [ -c count] [ -w deadline] [ -s source] -I interface destination-U Unsolicited ARP mode to update neighbours’ ARP caches. No replies are expected.

关键命令:

arping -U -I 发送包的网卡接口 -s 源ip 目的ip

实例:

假设你的eth0接口对应的ip为192.168.1.1,网关为192.168.1.255你就可以使用

arping -U -I eth0 -s 192.168.1.1 192.168.1.255

好了,今天和大家的分享就到这里吧。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息