dsniff  2.4b2
About: A collection of tools for network auditing
  Fossies Dox: dsniff-2.4b2.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

macof.c
Go to the documentation of this file.
1 /*
2  * macof.c
3  *
4  * C port of macof-1.1 from the Perl Net::RawIP distribution.
5  * Tests network devices by flooding local network with MAC-addresses.
6  *
7  * Perl macof originally written by Ian Vitek <ian.vitek@infosec.se>.
8  *
9  * Copyright (c) 1999 Dug Song <dugsong@monkey.org>
10  *
11  * $Id: macof.c,v 1.15 2001/03/15 08:33:04 dugsong Exp $
12  */
13 
14 #include "config.h"
15 
16 #include <sys/types.h>
17 #include <sys/param.h>
18 #include <netinet/in.h>
19 
20 #include <stdio.h>
21 #include <string.h>
22 #include <err.h>
23 #include <libnet.h>
24 #include <pcap.h>
25 
26 #include "version.h"
27 
28 extern char *ether_ntoa(struct ether_addr *);
29 extern struct ether_addr *ether_aton(char *);
30 
33 u_char *Tha = NULL;
34 u_short Dport = 0;
35 u_short Sport = 0;
36 char *Intf = NULL;
37 int Repeat = -1;
38 libnet_t *l;
39 char errbuf[LIBNET_ERRBUF_SIZE];
40 libnet_ptag_t tcp_id, ip_id, eth_id;
41 
42 static void
43 usage(void)
44 {
45  fprintf(stderr, "Version: " VERSION "\n"
46  "Usage: macof [-s src] [-d dst] [-e tha] [-x sport] [-y dport]"
47  "\n [-i interface] [-n times]\n");
48  exit(1);
49 }
50 
51 static void
52 gen_mac(u_char *mac)
53 {
54  *((in_addr_t *)mac) = libnet_get_prand(LIBNET_PRu32);
55  *((u_short *)(mac + 4)) = libnet_get_prand(LIBNET_PRu16);
56 }
57 
58 int
59 main(int argc, char *argv[])
60 {
61  extern char *optarg;
62  extern int optind;
63  int c, i;
64  struct libnet_link_int *llif;
65  char ebuf[PCAP_ERRBUF_SIZE];
66  u_char sha[ETHER_ADDR_LEN], tha[ETHER_ADDR_LEN];
67  in_addr_t src, dst;
68  u_short sport, dport;
69  u_int32_t seq;
70  u_char pkt[LIBNET_ETH_H + LIBNET_IPV4_H + LIBNET_TCP_H];
71 
72  l = libnet_init(
73  LIBNET_RAW4, /* or LIBNET_LINK or LIBNET_RAW6 */
74  NULL, /* or device if you using LIBNET_LINK */
75  errbuf);
76 
77 
78 
79 
80  while ((c = getopt(argc, argv, "vs:d:e:x:y:i:n:h?V")) != -1) {
81  switch (c) {
82  case 'v':
83  break;
84  case 's':
85  Src = libnet_name2addr4(l,optarg, 0);
86  break;
87  case 'd':
88  Dst = libnet_name2addr4(l,optarg, 0);
89  break;
90  case 'e':
91  Tha = (u_char *)ether_aton(optarg);
92  break;
93  case 'x':
94  Sport = atoi(optarg);
95  break;
96  case 'y':
97  Dport = atoi(optarg);
98  break;
99  case 'i':
100  Intf = optarg;
101  break;
102  case 'n':
103  Repeat = atoi(optarg);
104  break;
105  default:
106  usage();
107  }
108  }
109  argc -= optind;
110  argv += optind;
111 
112  if (argc != 0)
113  usage();
114  /*
115  if (!Intf && (Intf = pcap_lookupdev(ebuf)) == NULL)
116  errx(1, "%s", ebuf);
117 
118  if ((llif = libnet_open_link_interface(Intf, ebuf)) == 0)
119  errx(1, "%s", ebuf);
120  */
121  libnet_seed_prand(l);
122 
123  for (i = 0; i != Repeat; i++) {
124 
125  gen_mac(sha);
126 
127  if (Tha == NULL) gen_mac(tha);
128  else memcpy(tha, Tha, sizeof(tha));
129 
130  if (Src != 0) src = Src;
131  else src = libnet_get_prand(LIBNET_PRu32);
132 
133  if (Dst != 0) dst = Dst;
134  else dst = libnet_get_prand(LIBNET_PRu32);
135 
136  if (Sport != 0) sport = Sport;
137  else sport = libnet_get_prand(LIBNET_PRu16);
138 
139  if (Dport != 0) dport = Dport;
140  else dport = libnet_get_prand(LIBNET_PRu16);
141 
142  seq = libnet_get_prand(LIBNET_PRu32);
143 
144 
145  tcp_id = libnet_build_tcp(sport, dport, seq, 0, TH_SYN, 512,
146  0, NULL,LIBNET_TCP_H, 0,0,l,tcp_id);
147 
148 
149  ip_id = libnet_build_ipv4(LIBNET_TCP_H + LIBNET_IPV4_H, 0, libnet_get_prand(LIBNET_PRu16), 0, 64,
150  IPPROTO_TCP,0, src, dst, NULL,0, l, ip_id);
151 
152  eth_id = libnet_build_ethernet(tha, sha, ETHERTYPE_IP,NULL,0, l, eth_id);
153 
154  //libnet_do_checksum(l, pkt + LIBNET_ETH_H + LIBNET_IPV4_H, IPPROTO_TCP, LIBNET_TCP_H);
155  //libnet_do_checksum(l, pkt + LIBNET_ETH_H, IPPROTO_IP, LIBNET_IPV4_H);
156 
157  if (libnet_write(l) < 0)
158  perror("write");
159 
160  fprintf(stderr, "%s ",
161  ether_ntoa((struct ether_addr *)sha));
162  fprintf(stderr, "%s %s.%d > %s.%d: S %u:%u(0) win 512\n",
163  ether_ntoa((struct ether_addr *)tha),
164  libnet_addr2name4(Src, 0), sport,
165  libnet_addr2name4(Dst, 0), dport, seq, seq);
166  }
167  exit(0);
168 }
l
libnet_t * l
Definition: macof.c:38
usage
static void usage(void)
Definition: macof.c:43
ip_id
libnet_ptag_t ip_id
Definition: macof.c:40
tcp_id
libnet_ptag_t tcp_id
Definition: macof.c:40
ether_ntoa
char * ether_ntoa(struct ether_addr *)
Definition: ethers.c:49
ETHER_ADDR_LEN
#define ETHER_ADDR_LEN
Definition: arp.c:90
Dst
u_int32_t Dst
Definition: macof.c:32
version.h
pkt
static u_char pkt[4+8+262144]
Definition: ssh.c:87
main
int main(int argc, char *argv[])
Definition: macof.c:59
Dport
u_short Dport
Definition: macof.c:34
gen_mac
static void gen_mac(u_char *mac)
Definition: macof.c:52
tha
Definition: tcp_raw.c:21
err.h
VERSION
#define VERSION
Definition: version.h:1
Intf
char * Intf
Definition: macof.c:36
errbuf
char errbuf[LIBNET_ERRBUF_SIZE]
Definition: macof.c:39
Sport
u_short Sport
Definition: macof.c:35
in_addr_t
#define in_addr_t
Definition: config.h:32
Src
u_int32_t Src
Definition: macof.c:31
Tha
u_char * Tha
Definition: macof.c:33
ether_aton
struct ether_addr * ether_aton(char *)
Definition: ethers.c:97
config.h
eth_id
libnet_ptag_t eth_id
Definition: macof.c:40
Repeat
int Repeat
Definition: macof.c:37