Online Book Reader

Home Category

Apache Security - Ivan Ristic [80]

By Root 1924 0
parent.

File type: regular file, inode - 426313, device - 2050

The descriptor is: /usr/local/apache/logs/error_log

File's actual permissions: 644

File descriptor mode is: write only, append

----

Open file descriptor: 7

User ID of File Owner: root

Group ID of File Owner: root

WARNING - Descriptor is leaked from parent.

File type: regular file, inode - 426314, device - 2050

The descriptor is: /usr/local/apache/logs/access_log

File's actual permissions: 644

File descriptor mode is: write only, append

Exploiting the leakages is easy. For example, compile and run the following program (from the PHP script) instead of the audit utility. (You may need to change the descriptor number from 6 to the value you got for the error log in your audit report.)

#define ERROR_LOG_FD 6

int main( ) {

char *msg = "What am I doing here?\n";

write(ERROR_LOG_FD, msg, strlen(msg));

}

As expected, the message will appear in the web server error log! This means anyone who can execute binaries from PHP can fake messages in the access log and the error log. They could use this ability to plant false evidence against someone else into the access log, for example. Because of the nature of the error log (it is often used as stderr for scripts), you cannot trust it completely, but the ability to write to the access log is really dangerous. Choosing not to use PHP as a module, but to execute it through suEXEC instead (as discussed later in this chapter) avoids this problem.

* * *

Tip


Any of the active Apache modules can cause a file descriptor leak. You should test your final configuration to determine whether any leaks occur.

* * *

Distributing Configuration Data

Apache configuration data is typically located in one or more files in the conf/ folder of the distribution, where only the root user has access. Sometimes, it is necessary or convenient to distribute configuration data, and there are two reasons to do so:

Distributed configuration files can be edited by users other than the root user.

Configuration directives in distributed configuration files are resolved on every request, which means that any changes take effect immediately without having to have Apache restarted.

* * *

Tip


If you trust your developers and want to give them more control over Apache or if you do not trust a junior system administrator enough to give her control over the whole machine, you can choose to give such users full control only over Apache configuration and operation. Use Sudo (http://www.courtesan.com/sudo/) to configure your system to allow non-root users to run some commands as root.

* * *

Apache distributes configuration data by allowing specially-named files, .htaccess by default, to be placed together with the content. The name of the file can be changed using the AccessFileName directive, but I do not recommend this. While serving a request for a file somewhere, Apache also looks to see if there are .htaccess files anywhere on the path. For example, if the full path to the file is /var/www/htdocs/index.html, Apache will look for the following (in order):

/.htaccess

/var/.htaccess

/var/www/.htaccess

/var/www/htdocs/.htaccess

For each .htaccess file found, Apache merges it with the existing configuration data. All .htaccess files found are processed, and it continues to process the request. There is a performance penalty associated with Apache looking for access files everywhere. Therefore, it is a good practice to tell Apache you make no use of this feature in most directories (see below) and to enable it only where necessary.

The syntax of access file content is the same as that in httpd.conf. However, Apache understands the difference between the two, and understands that some access files will be maintained by people who are not to be fully trusted. This is why administrators are given a choice as to whether to enable access files and, if such files are enabled, which of the Apache features to allow in them.

* * *

Warning


Another way to distribute Apache configuration

Return Main Page Previous Page Next Page

®Online Book Reader