-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsend_pac.c
166 lines (144 loc) · 8.29 KB
/
send_pac.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
//linux sniffer
#include <sys/socket.h>
#include <sys/types.h>
//#include <linux/in.h>
//#include <linux/if_ether.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <string.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <features.h> /* for the glibc version number */
#include <netpacket/packet.h>
#include <net/ethernet.h> /* the L2 protocols */
#include <stdio.h>
#include <netinet/in.h>
//#define PAC_LEN 64
//#define PAC_LEN 60
#define PAC_LEN 118
//#define PAC_LEN 42
int main(int argc, char **argv) {
int sock, n;
int i;
#if 0
/*
unsigned char buffer[2048] = {
0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x11, 0x11, 0x11, 0x11, 0x11, 0x86, 0xdd, 0x60, 0x00,
0x00, 0x00, 0x00, 0x20, 0x3a, 0xff, 0x20, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x20, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x88, 0x00, 0xc2, 0x62, 0x20, 0x00, 0x00, 0x00, 0x20, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x02, 0x01,
0x11, 0x11, 0x11, 0x11, 0x11, 0x11
};//!< 86bytes
*/
unsigned char buffer[2048] = {
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0xb8, 0xac, 0x6f, 0x3b, 0x28, 0xbf, 0x86, 0xdd, 0x60, 0x00,
0x00, 0x00, 0x00, 0x40, 0x3a, 0x40, 0x3f, 0xfe, 0x12, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x3f, 0xfe, 0x12, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x88, 0xd2, 0x61, 0x04, 0x00, 0x74, 0xd5, 0x41,
0xf1, 0x4e, 0x35, 0x3f, 0x0a, 0x00, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11,
0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21,
0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31,
0x32, 0x33, 0x34, 0x35, 0x36, 0x37
};//!< 118 bytes
#else
/*
unsigned char buffer[2048] = {
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x00, 0x50, 0xc2, 0x4b, 0x11, 0x87, 0x08, 0x06, 0x00, 0x01,
0x08, 0x00, 0x06, 0x04, 0x00, 0x02, 0x00, 0x50, 0xc2, 0x4b, 0x11, 0x87, 0xac, 0xa8, 0x2c, 0x63,
0xb8, 0xac, 0x6f, 0x3b, 0x28, 0xbf, 0xac, 0xa8, 0x2c, 0xa9
};//!< 42bytes
unsigned char buffer[2048] = {
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xb8, 0xac, 0x6f, 0x3b, 0x28, 0xbf, 0x08, 0x06, 0x00, 0x01,
0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0xb8, 0xac, 0x6f, 0x3b, 0x28, 0xbf, 0x0a, 0x18, 0x46, 0xa9,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x18, 0xff, 0xfb
};//42bytes
*/
unsigned char buffer2[256] = {
0x00,0x11,0x00,0x22,0x00,0x40, 0x64, 0x55, 0x7f, 0x4d, 0x01, 0x63, 0x08, 0x00, 0x45, 0x00,
0x00,0xa0,0xc4,0x9c,0x00,0x00, 0xff, 0x06, 0x10, 0xa9, 0x96, 0x96, 0x02, 0xd3, 0xa6, 0xa6,
0xa6, 0x02, 0x00, 0x50, 0x9c, 0xc4, 0x77, 0x0a, 0xaa, 0x51, 0xae, 0x4e, 0xe6, 0xdf, 0x50, 0x18,
0x7f, 0xff, 0x24, 0xec, 0x00, 0x00, 0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31, 0x20, 0x33,
0x30, 0x32, 0x20, 0x4f, 0x4b, 0x0d, 0x0a, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x69, 0x6f,
0x6e, 0x3a, 0x20, 0x4b, 0x65, 0x65, 0x70, 0x2d, 0x41, 0x6c, 0x69, 0x76, 0x65, 0x0d, 0x0a, 0x4c,
0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x3a, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f,
0x31, 0x31, 0x36, 0x2e, 0x31, 0x31, 0x36, 0x2e, 0x31, 0x31, 0x36, 0x2e, 0x38, 0x2f, 0x3f, 0x43,
0x4f, 0x4c, 0x4c, 0x43, 0x43, 0x3d, 0x34, 0x31, 0x34, 0x39, 0x34, 0x33, 0x38, 0x34, 0x39, 0x33,
0x26, 0x0d, 0x0a, 0x0d, 0x0a, 0x20, 0x3c, 0x68, 0x74, 0x6d, 0x6c, 0x3e, 0x72, 0x65, 0x64, 0x69,
0x72, 0x65, 0x63, 0x74, 0x2e, 0x2e, 0x2e, 0x3c, 0x2f, 0x68, 0x74, 0x6d, 0x6c, 0x3e
};
unsigned char buffer1[128] = {
0x00,0x11,0x00,0x22,0x00,0x40,0x64,0x55,0x7f,0x4d,0x01,0x63, 0x08,0x00,0x45,0x00,
0x00,0x28,0x97,0xc4,0x00,0x00,0xff,0x06,0x3e,0x31,0x96,0x96,0x02,0x9b,0xa6,0xa6,
0xa6,0x02,0x00,0x50,0xc4,0x97,0xf6,0x7e,0x1d,0x6e,0xf6,0x72,0x38,0x27,0x50,0x14,
0xff,0xfd,0xc2,0xbe,0x00,0x00
};
unsigned char buffer[2048] = {
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x00, 0x02, 0x6f, 0x3b, 0x28, 0xbf, 0x08, 0x00, 0x45, 0x00,
0x00, 0x34, 0x5e, 0x82, 0x40, 0x00, 0x40, 0x06, 0xc9, 0xcd, 0x0a, 0x18, 0x46, 0xa9, 0xc0, 0xa8,
0x01, 0x0b, 0xe5, 0x12, 0x00, 0x6e, 0x07, 0x5a, 0x5c, 0x98, 0xad, 0x2a, 0x73, 0x7a, 0x80, 0x10,
0x00, 0x5c, 0x12, 0x9b, 0x00, 0x00, 0x01, 0x01, 0x08, 0x0a, 0x05, 0x7e, 0x02, 0x17, 0x09, 0xc3,
0x41, 0xd9
};//!< 66bytes
unsigned char buf[62] = {
0x64, 0x55, 0x7f, 0x4d, 0x00, 0x7b, 0x00, 0x25, 0x84, 0x7b, 0x94, 0x40, 0x08, 0x00, 0x45, 0x08, 0x00, 0x30, 0xa3, 0x86, 0x00, 0x00, 0xf7, 0x06, 0x7b, 0xe5, 0x05, 0x05, 0x05, 0x01, 0x4d, 0x4d, 0x4d, 0x01, 0x02, 0x4a, 0x00, 0x50, 0xa5, 0x49, 0xfd, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x70, 0x02, 0xff, 0xff, 0x39, 0x79, 0x00, 0x00, 0x02, 0x04, 0x05, 0xb4, 0x01, 0x01, 0x04, 0x02
};
unsigned char buf1[66] = {
0x01, 0x80, 0xc2, 0x00, 0x00, 0x00, 0x00, 0x1e, 0x7a, 0xe2, 0xd6, 0x5d, 0x00, 0x26, 0x42, 0x42, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x25, 0x84, 0x7b, 0x94, 0x40, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x25, 0x84, 0x7b, 0x94, 0x40, 0x83, 0x06, 0x00, 0x00, 0x14, 0x00, 0x02, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
unsigned char buf2[90] = {
0x01, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x24, 0xb6, 0x57, 0x99, 0x81, 0x2c, 0x00, 0x4c, 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x0c, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc, 0x24, 0xb6, 0x57, 0x99, 0x81, 0x2c, 0x00, 0x28, 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x0c, 0x20, 0x04, 0x01, 0x00, 0x01, 0x00, 0x0b, 0x44, 0x65, 0x76, 0x4e, 0x65, 0x74, 0x00, 0x00, 0x02, 0x00, 0x05, 0x04, 0x00, 0x03, 0x00, 0x05, 0x45, 0x00, 0x04, 0x00, 0x0a, 0x24, 0xb6, 0x57, 0x99, 0x81, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe5, 0x1b, 0xec, 0x5d
};
unsigned char buf3[64] = {
0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcd, 0xc8, 0x4c, 0x75, 0x4d, 0x71, 0xa7, 0x00, 0x32, 0xaa, 0xaa,
0x03, 0x00, 0x00, 0x0c, 0x01, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x08, 0x00, 0x25, 0x84,
0x7b, 0x94, 0x40, 0x00, 0x00, 0x00, 0x00, 0x80, 0x08, 0x00, 0x25, 0x84, 0x7b, 0x94, 0x40, 0x82,
0x08, 0x00, 0x00, 0x14, 0x00, 0x02, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x08
};
unsigned char buf4[118] = {
0xc2, 0x05, 0x63, 0x4d, 0x00, 0x00, 0xc2, 0x03, 0x63, 0x3e, 0x00, 0x00, 0x88, 0x47, 0x00, 0x01, 0x21, 0xfe, 0x45, 0x00, 0x00, 0x64, 0x00, 0x19, 0x00, 0x00, 0xfe, 0x01, 0x09, 0x2d, 0xc0, 0xa8, 0x0a, 0x01, 0xc0, 0xa8, 0x28, 0x01, 0x08, 0x00, 0x6d, 0x99, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x10, 0x88, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd
};//mpls
unsigned char rst[64] = {
0xac,0x4b,0xc8,0x2e,0x6a,0x40,0x64,0x55,0x7f,0x4d,0x01,0x64,0x08,0x00,0x45,0x00
,0x00,0x28,0xc4,0x9c,0x00,0x00,0xff,0x06,0x11,0x24,0xa6,0xa3,0xa6,0x02,0x96,0x96
,0x02,0xd3,0x9c,0xc4,0x00,0x50,0xae,0x4e,0xe5,0xba,0x77,0x0a,0xaa,0x51,0x50,0x14
,0x00,0x00,0x77,0x47,0x00,0x00
}; //rst to server
#endif
struct ifreq ethreq;
struct sockaddr_ll sll;
memset(&sll, 0, sizeof(sll)); // Maybe no need
sll.sll_ifindex = 2;//It seems only need this to specify which NIC to use
//sock=socket(PF_PACKET, SOCK_RAW,
if ( (sock=socket(PF_PACKET, SOCK_RAW,
htons(ETH_P_ALL)))<0) {
perror("socket");
return 1;
}
/* Set the network card in promiscuos mode */
strncpy(ethreq.ifr_name,"eth1",IFNAMSIZ);
if (ioctl(sock,SIOCGIFFLAGS,ðreq)==-1) {
perror("ioctl");
close(sock);
return 1;
}
ethreq.ifr_flags|=IFF_PROMISC;
if (ioctl(sock,SIOCSIFFLAGS,ðreq)==-1) {
perror("ioctl");
close(sock);
return 1;
}
#if 1
for (i = 0;i<10000 ; i++) {
//i = 0;
//printf("----------\n");
//n = sendto(sock, buffer, 42, 0, &sll, sizeof(sll));// recv(fw_net_sockfd,buf,BUFSIZE,0);
n = sendto(sock, rst,256, 0, &sll, sizeof(sll));// recv(fw_net_sockfd,buf,BUFSIZE,0);
usleep(100);
//while(++i < 200);
}
#else
n = sendto(sock, buffer, PAC_LEN, 0, &sll, sizeof(sll));// recv(fw_net_sockfd,buf,BUFSIZE,0);
#endif
}