Apache
  Home arrow Apache arrow Page 2 - Logging in Apache
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
APACHE

Logging in Apache
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 20
    2005-05-12


    Table of Contents:
  • Logging in Apache
  • Security Issues of Log Files
  • Reading the Log Files
  • Remote Logging
  • Logging on a Remote Host
  • Advantages and Disadvantages of Logging on a Remote Machine
  • A Powerful, Hybrid Design
  • Room for Improvement

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Logging in Apache - Security Issues of Log Files
    ( Page 2 of 8 )

    Logging appears to be a simple process, and you might wonder why security is involved at all. There are some very basic security problems connected to logging. For example:

    • Logs are written as root, and permission problems can be dangerous.

    • Logs are written in plain text, and can be easily modified and forged.

    • Logging programs are executed as root; if they are vulnerable, an attacker may gain root access.

    • Logs can cause a DOS if they run out of disk space (an attacker might do this deliberately).

    • Logging can be unreliable; if Apache dies (for example after an attack), they could be incomplete.

    I will discuss each of these problems in the following sections.

    Logs and Root Permissions

    Apache is normally started by the root user, in order to be able to listen to port 80 (non-root processes can only listen to ports higher than 1024). After starting up, Apache opens the log files, and only then drops its privileges. This allows the Apache server to write to files that no other user may access (if the permissions are set properly), protecting the log files. If the log files were opened after dropping privileges, they would be a lot more vulnerable.

    This implies that if the directory where the logs are stored is writable by common users, then an attacker can do this (note the wrong permissions for the logs directory):

    [merc@localhost merc]$ cd /usr/local/apache2/
    [merc@localhost apache2]$
    ls -l
    total 52
    drwxr-xr-x 2 root root 4096 Oct 4  14:50 bin
    drwxr-xr-x 2 root root 4096 Sep 13 23:18 build
    drwxr-xrwx 2 root root 4096 Oct 5  18:10
    logs
    [...]
    drwxr-xr-x 2 root root 4096 Oct 4  18:50 modules
    [merc@localhost apache2]$
    cd logs
    [merc@localhost logs]$
    ls -l
    total 212
    -rw-r--r--1 root root 124235 Oct 5 18:11 access_log
    -rw-r--r--1 root root 74883  Oct 5 18:10 error_log
    -rw-r--r--1 root root 5      Oct 5 18:10 httpd.pid
    [merc@localhost logs]$
    rm access_log
    rm: remove write-protected file 'access_log'?
    y
    [merc@localhost logs]$
    ln -s /etc/passwd_for_example 
                           access_log
    [merc@localhost logs]$
    ls -l
    total 84
    lrwxrwxrwx 1 merc merc 23   Oct 5 19:26 access_log ->
    /etc/passwd_for_example
    -rw-r--r--1 root root 75335 Oct 5 19:27 error_log
    -rw-r--r--1 root root 5     Oct 5 19:27 httpd.pid
    [merc@localhost logs]$

    Obviously, this can only be done if the attacker has login access to the web server. The next time Apache is run, the web server will append to /etc/passwd. This would make the system unstable and prevent any further login by users. The solution is to ensure that the logs directory is not writable by other users.

    Logs As Modifiable Text Files

    Log files are usually stored as text files, and they are therefore very easy to:

    • Forge. A cracker might want hide any trace of his or her attack, and might therefore edit out those lines that would highlight the attacks.

    • Delete. Logs might be quite valuable for your company for access-analyzing purposes, and missing information might represent a problem—and a loss of money.

    • Steal. This wouldn’t happen very often, but it’s a possibility, especially if your logs have any value for data mining.

    A possible solution to this problem is to protect the logs (and your system) properly so that these things can’t happen. Another solution is remote logging, discussed in the second part of this chapter.

    Logging Programs and Security

    Because the logger program is run as root, it must be kept simple, and the code must be audited for vulnerabilities like buffer overflows. In addition, the directory where the program resides must be owned by root, and non-root users must not have write permissions. Otherwise, they could delete the logging program and replace it with a malicious one.

    Logs and Disk Space

    Because Apache logs can be big, you need to monitor their size. For instance, a cracker might send many requests, with the sole purpose of filling up the disk space, and then perform an attack (buffer overflow, for instance). If Apache’s logs and other system logs share the same partition, the cracker will be able to perform any kind of buffer overflow attack without being logged.

    Remember that all the system logs should be directed to a partition that will not cause system-wide interruptions if it fills up, such as /var. Further, the log files should be compressed once they are archived to save disk space. In addition, you can use a script that periodically checks the size of the log directory and issues a warning if too much disk space is being used, or if the log partition is full. The script could be as simple as this:

    #!/bin/bash

    partition="/dev/hda5"

    free_space=`df | grep $partition | cut -b 41-50`
    echo $free_space

    if [ $free_space -le 5000 ];then
           message="WARNING: Only $free_space blocks left on
                    $partition";
           logger -p local0.crit $message 
           echo $message | mail -s "Partition problem"
                                   
    merc@localhost
    fi

    This script assumes that the log partition is /dev/hda5. The available free space is taken out of the df command using cut (free_space=`df | grep $partition | cut -b 41-50). If there are fewer than 5000 blocks left (if [ $free_space -le 5000 ];then), the script logs the problem using logger, and sends an e-mail to merc@localhost. This script should be placed in your crontab, and should be executed every 15 minutes. This script can easily be improved so that it stores the available space each time in /tmp/free_space, and warns you if there has been a drastic change in the available space on the log partition. See Chapter 7 for more scripts aimed at automated system administration tasks.

    Unreliable Logging

    After a DOS attack, the server’s accountability (the logs) may be compromised; therefore, Apache might not be able to write the entries about the attack on the log files. This means that if an attacker performed a DOS attack against your server, you might not be able to investigate the attack.



     
     
    >>> More Apache Articles          >>> More By Apress Publishing
     

       

    APACHE ARTICLES

    - Creating a VAMP (Vista, Apache, MySQL, PHP) ...
    - Putting Apache in Jail
    - Containing Intrusions in Apache
    - Server Limits for Apache Security
    - Setting Permissions in Apache
    - Installing Apache
    - Apache Installation and Configuration
    - Apache Tapestry and Custom Components: DateI...
    - Tapestry and AJAX: Autocompleter and InlineE...
    - PropertySelection and IPropertySelectionMode...
    - The DatePicker and Shell Components of Apach...
    - Apache Tapestry: ASO and More Components
    - Apache Tapestry and DirectLink, IoC and DI
    - Making a CelebrityCollector with Apache Tape...
    - Apache Tapestry and Listener Methods, Condit...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT