WEB开发网
开发学院软件开发C++ 如何检测Sniffer 阅读

如何检测Sniffer

 2008-03-08 12:45:56 来源:WEB开发网   
核心提示:技术细节L0pht公司已经说明了,如下: Win9x/NT 正常情况下,如何检测Sniffer,就是说不在混乱模式,网卡检测是不是广播地址 要比较看收到的目的以太网址是否等于ff.ff.ff.ff.ff.ff

  技术细节 L0pht 公司已经说明了,如下:
Win9x/NT
   正常情况下,就是说不在混乱模式,网卡检测是不是广播地址
要比较看收到的目的以太网址是否等于ff.ff.ff.ff.ff.ff
是则认为是广播地址。
   在混乱模式时,网卡检测是不是广播地址只看收到包的目的以太
网址的第一个八位组值,是0xff则认为是广播地址。
利用这点细微差别就可以检测出Sniffer.
linux
   以前就提出过,一些版本内核有这种问题:
   当混杂模式时,每个包都被传到了操作系统内核以处理。
在处理某些包,只看ip地址而不看以太网头中的源物理地址。
所以:
   使用一个不存在的目的MAC,正确的目的IP,受影响
的内核将会由于是混杂模式而处理它,并将之交给相应系统
堆栈处理。从而实现检测Sniffer
   总之,只要发一个以太网头中目的地址是ff.00.00.00.00.00
的ARP包(l0pht公司是ff.ff.ff.ff.ff.00)就可以检测出Linux和
Windows网卡处于混乱状态的计算机.
   以下是一个Linux下用于检测Linux下Sniffer的程序,很多地方都贴
过了,我只改了一句话,这样也可以检测出Windows机器。:)
/*
gcc -lbsd -O3 -o linuxanti linuxanti.c
*/
/*
Network PRomiscuous Ethernet Detector.
Linux 2.0.x / 2.1.x, libc5 & GlibC
-----------------------------------------
(c) 1998 savage@apostols.org
-----------------------------------------
Scan your subnet, and detect promiscuous
Windows & linuxes. It really works, not a joke.
-----------------------------------------
$Id: neped.c,v 1.4 1998/07/20 22:31:52 savage EXP $
*/
#include <stdio.h>
#include <fcntl.h> /* for nonblocking */
#include <sys/ioctl.h>
#include <sys/socket.h> /* basic socket definitions */
#include <net/if.h> /* for ifreq */
#include <arpa/inet.h> /* inet(3) functions */
#define ETH_P_ARP 0x0806
#define MAX_PACK_LEN 2000
#define ETHER_HEADER_LEN 14
#define ARPREQUEST 1
#define ARPREPLY 2
#define perr(s) fprintf(stderr,s)
strUCt arp_struct
{
u_char dst_mac[6];
u_char src_mac[6];
u_short pkt_type;
u_short hw_type;
u_short pro_type;
u_char hw_len;
u_char pro_len;
u_short arp_op;
u_char sender_eth[6];
u_char sender_ip[4];
u_char target_eth[6];
u_char target_ip[4];
};
union

{
u_char full_packet[MAX_PACK_LEN];
struct arp_struct arp_pkt;
}
a;
#define full_packet a.full_packet
#define arp_pkt a.arp_pkt
char *
inetaddr ( u_int32_t ip )
{
struct in_addr in;
in.s_addr = ip;
return inet_ntoa(in);
}
char *
hwaddr (u_char * s)
{
static char buf[30];
sprintf (buf, "%02X:%02X:%02X:%02X:%02X:%02X", s[0], s[1], s[2], s[3],
s[4], s[5]);
return buf;
}
void
main (int argc, char **argv)
{
int rec;
int len, from_len, rsflags;
struct ifreq if_data;
struct sockaddr from;
u_int8_t myMAC[6];
u_int32_t myIP, myNETMASK, myBROADCAST, ip, dip, sip;
if (getuid () != 0)
{
perr ("You must be root to run this program!\\n");
exit (0);
}
if (argc != 2)
{
fprintf(stderr,"Usage: %s eth0\\n", argv[0]);
exit (0);
}
if ((rec = socket (AF_INET, SOCK_PACKET, htons (ETH_P_ARP))) < 0)
{
perror("socket");
exit (0);
}
printf ("----------------------------------------------------------\\n");
strcpy (if_data.ifr_name, argv[1]);
if (ioctl (rec, SIOCGIFHWADDR, &if_data) < 0) {
perr ("can't get HW addres of my interface!\\n");
exit(1);
}
memcpy (myMAC, if_data.ifr_hwaddr.sa_data, 6);
printf ("> My HW Addr: %s\\n", hwaddr (myMAC));
if (ioctl (rec, SIOCGIFADDR, &if_data) < 0) {
perr ("can't get IP addres of my interface!\\n");
exit(1);
}
memcpy ((void *) &ip, (void *) &if_data.ifr_addr.sa_data + 2, 4);
myIP = ntohl (ip);
printf ("> My IP Addr: %s\\n", inetaddr(ip));
if (ioctl (rec, SIOCGIFNETMASK, &if_data) < 0)
perr ("can't get NETMASK addres of my interface!\\n");
memcpy ((void *) &ip, (void *) &if_data.ifr_netmask.sa_data + 2, 4);
myNETMASK = ntohl (ip);
printf ("> My NETMASK: %s\\n", inetaddr(ip));
if (ioctl (rec, SIOCGIFBRDADDR, &if_data) < 0)
perr ("can't get BROADCAST addres of my interface!\\n");
memcpy ((void *) &ip, (void *) &if_data.ifr_broadaddr.sa_data + 2, 4);
myBROADCAST = ntohl (ip);
printf ("> My BROADCAST: %s\\n", inetaddr(ip));
if ((rsflags = fcntl (rec, F_GETFL)) == -1)
{
perror ("fcntl F_GETFL");
exit (1);
}
if (fcntl (rec, F_SETFL, rsflags O_NONBLOCK) == -1)
{
perror ("fcntl F_SETFL");
exit (1);
}
printf ("----------------------------------------------------------\\n");
printf ("> Scanning ....\\n");

for (dip = (myIP & myNETMASK) + 1; dip < myBROADCAST; dip++)
{
bzero(full_packet, MAX_PACK_LEN);
memcpy (arp_pkt.dst_mac, "\\255\\255\\255\\255\\255\\0", 6); /* ff:ff:ff:ff:ff:00
:) */
/* Only change this line! */
memcpy (arp_pkt.src_mac, myMAC, 6);
arp_pkt.pkt_type = htons( ETH_P_ARP );
arp_pkt.hw_type = htons( 0x0001 );
arp_pkt.hw_len = 6;
arp_pkt.pro_type = htons( 0x0800 );
arp_pkt.pro_len = 4;
arp_pkt.arp_op = htons (ARPREQUEST);
memcpy (arp_pkt.sender_eth, myMAC, 6);
ip = htonl (myIP);
memcpy (arp_pkt.sender_ip, &ip, 4);
memcpy (arp_pkt.target_eth, "\\0\\0\\0\\0\\0\\0", 6);
ip = htonl (dip);
memcpy (arp_pkt.target_ip, &ip, 4);
strcpy(from.sa_data, argv[1]);
from.sa_family = 1;
if( sendto (rec, full_packet, sizeof (struct arp_struct), 0, &from,
sizeof(from)) < 0)
perror ("sendto");
usleep (50);
len = recvfrom (rec, full_packet, MAX_PACK_LEN, 0, &from, &from_len);
if (len <= ETHER_HEADER_LEN)
continue;
memcpy (&ip, arp_pkt.target_ip, 4);
memcpy (&sip, arp_pkt.sender_ip, 4);
if (ntohs (arp_pkt.arp_op) == ARPREPLY
&& ntohl (ip) == myIP
&& ( dip - ntohl(sip) >= 0 )
&& ( dip - ntohl(sip) <= 2 ) )
{
printf ("*> Host %s, %s **** Promiscuous mode detected !!!\n",
inetaddr (sip),
hwaddr (arp_pkt.sender_eth));
}
}
printf ("> End.\\n");
exit (0);
}



Sniffer Scaner

   Ace Studio , 1999. (AceStudio@hotmail.com)

运行环境:Win95/98,无需Winsock

本程序可以检测出本网络内正在运行Sniffer的计算机,或者说
网卡处于混乱状态。对方的操作系统可以是Win95/98/NT,Linux。

   Sniffer一般只能监听连到同一集线器上计算机(这主要看网络的
拓扑结构),但检测Sniffer可没这种限制,只要与对方通讯可以不过
路由。只要符合此条件其他网络中的Sniffer也可以查出。

   一般不必配置,程序会自动检测网络配置。一

Tags:如何 检测 Sniffer

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接