Announcement

Collapse
No announcement yet.

Common Attacks in Apache

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Common Attacks in Apache

    Because Apache is complex, coding errors are possible. Fortunately, Apache is mature enough that this is not a frequent occurrence, and occasionally, overlooked errors are found and fixed. This chapter covers some basics of Apache’s vulnerabilities and recent known security problems. (From Hardening Apache by Tony Mobily, Apress, 2004, ISBN: 1590593782.)
    Because of its complexity (and the inherent complexity of Internet technologies), the Apache software provides numerous opportunities for coding errors to be made, and sometimes they are. Fortunately, Apache is mature enough that this is not a frequent occurrence, and occasionally, overlooked errors are found and fixed.

    In this chapter, I explain some basic terminology to help you understand Apache’s vulnerabilities. I then show some of the known security problems that have affected Apache over the last 24 months. The goal of these descriptions is not to understand these specific problems, but so you can see what kind of vulnerabilities Apache can have, how to research them, and where you can find and read the advisories (and understand them).


    Common Terms
    In this section, I will introduce some key words often used in security advisories. These words are often misunderstood by less-experienced system administrators.

    Exploits
    An exploit is a simple program used to show how to take advantage of a server’s vulnerability. Exploits can be quite dangerous, because they allow less experienced people (sometimes called script kiddies) to use them blindly and break into many servers on the Internet illegally. Many commercial companies do not like exploits at all and would like to make their publication illegal.

    However, having an exploit “out in the wild” is also extremely important because:

    If companies know that an exploit is available, they will be more likely to release a patch to the problem as soon as possible, because their cus tomers are effectively easy targets.

    Exploits prove that a vulnerability is actually there and needs fixing. Sometimes software vendors are skeptical and deny that a vulnerability actually exists.

    Exploits are very useful in learning about computer security. They usually explain where the problem came from (that is, which piece of code was buggy in the original piece of software) and show you exactly how to exploit it.
    Many different tricks have been used in order to discourage people from misusing exploits: some were intentionally published with errors so that they can only be used by programmers who understand what the code is doing; others were published in a kind of cryptic format, requiring the user to write a small program to decode the source file of the exploit itself, and so on.

    Buffer Overflows
    Most programs allocate a reasonable amount of memory to the storage of information provided by the user. If a user deliberately tries to use more than the allocated amount of memory, he or she can damage the program, or even execute malicious code. For example, look at the following program (you should be able to understand it even with very little programming experience):

    #include <stdio.h>

    main(int argc, char **argv){
    /* Was it the right number of parameters? */
    if(argc != 2){
    fprintf(stdout,"Usage: %s PARAMETERn",argv[0]);
    exit(1);
    }
    /* OK, display the parameter! */
    display_stuff(argv[1]);
    }


    /* Function called from main(), used to display the parameter */
    int display_stuff(char *parameter){

    /* copy_of_parameter is a buffer of 256 bytes */
    char copy_of_parameter[80];

    /* This means copy_of_parameter=parameter */
    /* And yes, this is very insecure */
    strcpy(copy_of_parameter,parameter);

    /* Print out the parameter! */
    printf("The parameter was: %sn",copy_of_parameter);
    }

  • #2
    Apache2 with PHP5 and PHP4 enabled at the same time

    Apache2 with PHP5 and PHP4 enabled at the same time. Because it is not possible to run both PHP5 and PHP4 as Apache modules, we must run one of them as CGI, the other one as Apache module. In this document I will use PHP5 as Apache module and PHP4 as CGI, and I will describe the setup for the Linux distributions Debian Sarge (3.1) and Ubuntu 5.10 (Breezy Badger).

    I want to say first that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!


    1 Setup For Debian Sarge (3.1)
    First, you must at least have a working basic Debian installation, as described on the first two pages of the "Perfect Setup" tutorial for Debian Sarge here on HowtoForge: http://www.howtoforge.com/perfect_setup_debian_sarge and http://www.howtoforge.com/perfect_setup_debian_sarge_p2

    Because PHP5 is not available in the official Debian Sarge repositories, we have to add another repository (packages.dotdeb.org) to /etc/apt/sources.list. Add these two lines:

    deb http://packages.dotdeb.org stable alldeb-src http://packages.dotdeb.org stable all

    to /etc/apt/sources.list (mine looks like this then:

    deb http://ftp2.de.debian.org/debian/ stable maindeb-src http://ftp2.de.debian.org/debian/ stable maindeb http://packages.dotdeb.org stable alldeb-src http://packages.dotdeb.org stable alldeb http://security.debian.org/ stable/updates main

    ) and run

    apt-get update

    afterwards.

    Now we can install Apache2 as well as the Apache2-PHP5 module and the PHP4-CGI:

    apt-get install apache2 apache2-doc
    apt-get install libapache2-mod-php5 php4-cgi

    Next, we can install all the PHP5 and PHP4 modules we need on our server, like this:

    apt-get install php5-curl php5-dev php5-gd php5-gmp php5-imap php5-ldap php5-mcrypt php5-mhash php5-ming php5-mysql php5-mysqli php5-odbc php5-pdo-mysql php5-pdo-sqlite php5-pear php5-pspell php5-snmp php5-sybase php5-tidy php4-curl php4-domxml php4-gd php4-gmp php4-imap php4-ldap php4-mcal php4-mcrypt php4-mhash php4-ming php4-mysql php4-odbc php4-pspell php4-recode php4-snmp php4-xslt php4-xdebug curl libwww-perl imagemagick (1 line!)

    Edit /etc/apache2/apache2.conf. Change

    DirectoryIndex index.html index.cgi index.pl index.php index.xhtml

    to

    DirectoryIndex index.html index.htm index.shtml index.cgi index.pl index.php index.php4 index.xhtml

    and add these two lines as well (in the section where you can find AddType and AddHandler directives):

    AddHandler php-script .php4Action php-script /cgi-bin/php4

    This will make sure that PHP files with the extension .php4 are executed as CGI. PHP files with the extension .php will be run by the Apache2-PHP5 module.

    Next, we have to enable a few Apache modules, like for example the actions module (otherwise we cannot run PHP4 as CGI):

    a2enmod actions
    a2enmod ssl
    a2enmod rewrite
    a2enmod suexec
    a2enmod include

    Restart Apache, and you're done!

    /etc/init.d/apache2 restart

    Now we can test our installation: Put two files, info.php and info.php4, with the same content:

    <?phpphpinfo();?>

    into /var/www (this is the default document root of Debian's Apache2) and try to access them in a browser (if the server's IP address is 192.168.0.100, for example, you would type http://192.168.0.100/info.php and http://192.168.0.100/info.php4). You should see two different PHP versions, one run as Apache module (PHP5), the other one (PHP4) called as CGI

    Comment

    Working...
    X