病毒信息网 www.Virus-Info.asia

夜火 & 轨迹's Blog

免费网络资源-计算机技术-网络安全-Linux-Android—15897.com(要我发就齐) 夜火&轨迹共用的Blog

导航

用批处理文件抵御ARP攻击

  ARP欺骗通过伪造IP地址和MAC地址实现,能够在网络中产生大量的ARP通信量使网络阻塞,攻击者只要持续不断的发出伪造的ARP响应包就能更改目标主机ARP缓存中的IP-MAC条目,造成网络中断或中间人攻击。 笔者将介绍四种利用自制批处理文件来防御ARP攻击的方法。

  一、把下面语句编成BAT处理文件

      @echo off
  ::读取本机Mac地址
  if exist ipconfig.txt del ipconfig.txt
  ipconfig /all >ipconfig.txt
  if exist phyaddr.txt del phyaddr.txt
  find "Physical Address" ipconfig.txt >phyaddr.txt
  for /f "skip=2 tokens=12" %%M in (phyaddr.txt) do set Mac=%%M ::读取本机ip地址
  if exist IPAddr.txt del IPaddr.txt
  find "IP Address" ipconfig.txt >IPAddr.txt
  for /f "skip=2 tokens=15" %%I in (IPAddr.txt) do set IP=%%I  ::绑定本机IP地址和MAC地址
  arp -s %IP% %Mac%   ::读取网关地址
  if exist GateIP.txt del GateIP.txt
  find "Default Gateway" ipconfig.txt >GateIP.txt
  for /f "skip=2 tokens=13" %%G in (GateIP.txt) do set GateIP=%%G  ::读取网关Mac地址
  if exist GateMac.txt del GateMac.txt
  arp -a %GateIP% >GateMac.txt
  for /f "skip=3 tokens=2" %%H in (GateMac.txt) do set GateMac=%%H  ::绑定网关Mac和IP
  arp -s %GateIP% %GateMac%
  arp -s 网关IP 网关MAC
  exit
 


  这个批处理要查询本机的ARP 缓存表,看里面是不是有网关的IP和MAC,有则能成功绑定,但是没有的话就绑不定了!!!不过可以改进一下,达到双绑的目的,比如加上arp -s 网关IP 网关MAC一行就可以了。

  二、绑定本机IP和MAC

      @echo off
  for /f "delims=: tokens=2" %%a in (ipconfig /all^|find "Physical Address") do set local_mac=%%a
  for /f "delims=: tokens=2" %%a in (ipconfig /all^|find "IP Address") do set local_ip=%%a
  for /f "delims=: tokens=2" %%a in (ipconfig /all^|find "Default Gateway") do set gate_ip=%%a
  fo* /* %%* in (getmac /nh /s %local_ip%) do set gate_mac=%%a
  arp -s %local_ip% %local_mac%
  arp -s %gate_ip% %gate_mac% (这个地方有问题,改进中……)


  经测试,此批处理不能绑定网关IP和MAC,只能绑定本机IP和MAC

  三、测试中,目前所知也能绑定本机IP和MAC

      @ECHO OFF
  SETLOCAL ENABLEDELAYEDEXPANSION
  for /f "tokens=2 delims=[]=" %%i in (nbtstat -a %COMPUTERNAME%) do call set local=!local!%%i
  for /f "tokens=3" %%i in (netstat -r^|find " 0.0.0.0") do set gm=%%i
  for /f "tokens=1,2" %%i in (arp -a %gm%^|find /i /v "inter") do set gate=%%i %%j
  arp -s %gate%
  arp -s %local%
  arp -s 网关IP 网关MAC


  这个批处理可以绑定网关IP和MAC,但是还是有缺陷,要依赖于本机上存在的ARP缓存!

  改进方法为在最后加一个arp -s 网关IP和MAC!

  四、原理和一相同,进一步改进!

  通过ping网关三次得到了网关的MAC其实以上的批都可以通过这个来搞定网关的IP和MAC,但是如果开机的时候正在发生ARP欺骗的话 这样你绑的IP和MAC就是错的,不能上网了。

      @echo off
  :::::::::::::清除所有的ARP缓存
  arp -d
  :::::::::::::读取本地连接配置
  ipconfig /all>ipconfig.txt
  :::::::::::::读取内网网关的IP
  for /f "tokens=13" %%I in (find "Default Gateway" ipconfig.txt) do set GatewayIP=%%I
  ::::::::::::ING三次内网网关
  ping %GatewayIP% -n 3
  :::::::::::::读取与网关arp缓存
  arp -a|find "%GatewayIP%">arp.txt
  :::::::::::::读取网关MAC并绑定
  for /f "tokens=1,2" %%I in (find "%GatewayIP%" arp.txt) do if %%I==%GatewayIP% arp -s %%I %%J
  :::::::::::::读取本机的 IP+MAC
  for /f "tokens=15" %%i in (find "IP Address" ipconfig.txt) do set ip=%%i
  for /f "tokens=12" %%i in (find "Physical Address" ipconfig.txt) do set mac=%%i
  :::::::::::::绑定本机的 IP+MAC
  arp -s %ip% %mac%
  :::::::::::::删除所有的临时文件
  del ipconfig.txt
  del arp.txt
  exit


  不过这种情况很少,发过来试一下先吧!

  以上P可以配合路由上对客户机的IP和MAC进行绑定实现完全防ARP,只是单绑下面机和网关IP及MAC

  没有多大用处,关于路由上面的,因为大家用的路由不一样,所以这个就不写了,希望会给用户带来一定的帮助。



« 参加瑞星杀毒软件2008公测活动获奖[图] 珊瑚虫作者被捕 服务器被扣【完整版wmv视频】 »

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
如原创文章转载,请注明: 转自:夜火&轨迹's Blog [ http://www.15897.com/ ]

本文链接地址: http://www.15897.com/blog/post/181.html

收藏到网摘

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

订阅本站

    订阅 夜火&轨迹's Blog - 可以即时阅读本blog的最新文章 订阅 夜火&轨迹's Blog

Search


最近发表

最新评论及回复

最近留言

图标汇集


  • 知识共享署名-非商业性使用-相同方式共享 2.5 中国大陆许可协议
  • RainbowSoft Studio Z-Blog   本站支持WAP访问
  • 订阅本站 RSS 2.0 新闻聚合

您可能需要这些?



网站分类

夜火的碎碎念

文章归档

ADs

    Powered By Z-Blog 1.8 Walle Build 91204

    Copyright © 夜火 & 轨迹's Blog All Rights Reserved.  苏ICP备09031555号   |   Sitemap   |