Linux下防御ARP病毒攻击


Linux下防御ARP病毒攻击的类似文章网络上太多了,但效果各有千秋,这里写下我自己的心得。

方法一:

此法比较简单,简言之就是绑定网关的IP和MAC,命令如下:

$ sudo arp -s 192.168.1.1 00:14:78:BB:89:E2
前者是网关IP,后者是网关MAC,可能还需要

$ sudo ifconfig eth0 -arp
但我的archlinux如果执行这一步,将导致断网,因此我将它省掉了,没发现什么问题。

这个方法虽然简单,但有其局限性,就是必须双向绑定IP-MAC,如果你无法控制路由器,不能在网关那里设置静态IP,这个方法就无效了。

方法二:

这个方法复杂一点,需要用到arpspoof,它属于dsniff,所以先安装dsniff。

默认的arpspoof每秒执行一次,显然对付不了arp攻击,所以要修改源代码,自己重新编译arpspoof,有补丁如下:(论坛里找到的,出处忘记了)

#! /bin/sh /usr/share/dpatch/dpatch-run
diff -urNad dsniff-2.4b1+debianold/arpspoof.c dsniff-2.4b1+debian/arpspoof.c
--- dsniff-2.4b1+debianold/arpspoof.c   2001-03-15 16:32:58.000000000 +0800
+++ dsniff-2.4b1+debian/arpspoof.c   2008-02-24 20:30:11.000000000 +0800
@@ -31,6 +31,7 @@
 static struct ether_addr spoof_mac, target_mac;
 static in_addr_t spoof_ip, target_ip;
 static char *intf;
+static useconds_t interval; /* time interval, add by AutumnCat */
 
 static void
 usage(void)
@@ -156,9 +157,15 @@
   
    intf = NULL;
    spoof_ip = target_ip = 0;
+        interval = 1000000UL;
   
-   while ((c = getopt(argc, argv, "i:t:h?V")) != -1) {
+   while ((c = getopt(argc, argv, "x:i:t:h?V")) != -1) {
       switch (c) {
+                case 'x':
+                        interval = (useconds_t)atoi(optarg);
+                        if (interval < 1000UL)
+                                interval = 1000000UL;
+                        break;
       case 'i':
          intf = optarg;
          break;
@@ -197,7 +204,8 @@
       arp_send(llif, intf, ARPOP_REPLY, NULL, spoof_ip,
           (target_ip ? (u_char *)&target_mac : NULL),
           target_ip);
-      sleep(2);
+   /*   sleep(2); */
+                usleep(interval);
    }
    /* NOTREACHED */
打好补丁后编译出来的arpspoof多了一个参数x,用法如下:

$ arpspoof -i eth0 -t 网关IP 你的IP -x 50000
“-x 50000”的意思是每隔50000毫秒执行一次,也就是每秒执行20次

这个方法似乎有点暴力,以暴治暴,所以每秒执行次数不能太多,否则路由器会挂掉的。

译好的arpspoof

相关内容