脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|shell|

服务器之家 - 脚本之家 - shell - 防止ARP攻击的shell代码

防止ARP攻击的shell代码

2022-12-15 11:21shell编程教程 shell

防止ARP攻击,使用命令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."



解决linux下ARP攻击的方法

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

延伸 · 阅读

精彩推荐