Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 154 lines (129 sloc) 4.364 kB
4668e9c @msantos Add a license.
authored
1 /* Copyright (c) 2005-2010, Michael Santos <michael.santos@gmail.com>
2 * All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * Neither the name of the author nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
6afc24f @msantos Imported from http://code.google.com/p/tweag/ cause I <3 github
authored
33 /*
34 * drench, a connection exhaustion test tool
35 *
36 * Stateless TCP connection flood
37 *
38 */
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <unistd.h>
43 #include <err.h>
44
45 #include <pcap.h>
46 //#include <dnet.h>
47
48 #include <netinet/if_ether.h>
49 #include <netinet/ip.h>
50 #include <netinet/tcp.h>
51 #include <netinet/ip_icmp.h>
52 #include <arpa/inet.h>
53
54 #include <libnet.h>
55
56 #define DRENCH_BUILD "0.3"
57
58 #define PCAP_ERRBUF(x) do { \
59 if ((x) == NULL) \
60 errx(EXIT_FAILURE, "%s: %s", #x, errbuf); \
61 } while (0);
62
63 #define PCAP_ERR(x) do { \
64 if ((x) != 0) \
65 errx(EXIT_FAILURE, "%s: %s", #x, pcap_geterr(p)); \
66 } while (0);
67
68 #define LIBNET_ERR(x) do { \
69 if ((x) == -1) { \
70 libnet_destroy(dp->l); \
71 errx(EXIT_FAILURE, "%s: %s", #x, libnet_geterror(dp->l)); \
72 } \
73 } while (0);
74
75 #define ISNULL(x) do { \
76 if ((x) == NULL) {\
77 (void)fprintf(stderr, "%s", #x); \
78 return (1); \
79 } \
80 } while (0)
81
82 #define ISZERO(x) do { \
83 if ((x) == 0) {\
84 (void)fprintf(stderr, "%s", #x); \
85 return (1); \
86 } \
87 } while (0)
88
89 #define LTZERO(x) do { \
90 if ((x) < 0) {\
91 (void)fprintf(stderr, "%s", #x); \
92 return (1); \
93 } \
94 } while (0)
95
96 #define ISSET(x, y) do { \
97 if (th->th_flags & x) {\
98 (void)fprintf(stdout, "%s", #y); \
99 } \
100 } while (0)
101
102
103 #define TCP_PHASE(x,y,z) ((x) == TH_SYN ? (y) : (z))
104
105 extern char *__progname;
106
107 #define SNAPLEN 60
108 #define PROMISC 1 /* true */
109 #define TIMEOUT 500 /* ms */
110 #define PCAP_FILT "tcp and src %s and src port %u"
111 #define MAXFILT 256
112
113 #define TCP_WINSIZE 32768 /* 0 */
114 #define MAX_TTL 64
115
116 #define PAYLOAD "GET / HTTP/1.1\nHost: www.example.com\r\n";
117
118 typedef struct {
119 u_int8_t flags;
120 u_int16_t winsize;
121 u_int8_t range; /* range of addresses to allocate */
122 u_int32_t opts; /* options */
123 u_int32_t secret; /* Seed for sequence number */
124 char *saddr;
125 char *daddr;
126 in_port_t dport;
127 libnet_ptag_t p_tcp;
128 libnet_ptag_t p_ip;
129 libnet_t *l;
130 char *payload;
131 } pkt_t ;
132
133 enum {
134 O_ACK = 1, /* continue ACK'ing */
135 O_REPEAT = 2, /* repeat the scan */
136 O_CHKISN = 4, /* check if the sequence number in the returned ACK is valid */
137 };
138
139 void drench_writer(pkt_t *dp, u_int32_t count, u_int32_t group, u_int32_t use);
140 void drench_reader(pkt_t *dp, pcap_t *p);
141 void drench_cleanup(int sig);
142
143 void drench_send_tcp(pkt_t *dp, u_int8_t offset, u_char *pkt);
144 int create_arp_pool(libnet_t *l, u_int8_t iprange);
145 int create_arp_pool1(pkt_t *dp);
146 int destroy_arp_pool1(pkt_t *dp);
147 void usage(void);
148
149 void drench_err(int rv, char *fmt, ...);
150 void drench_errx(int rv, char *fmt, ...);
151 void drench_warn(char *fmt, ...);
152 void drench_warnx(char *fmt, ...);
153
Something went wrong with that request. Please try again.