05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

• Any system call (through functions such as system( ), exec( ), passthru( ), and<br />

popen( )) can access only executables located in the designated safe_mode_exec_<br />

dir in your php.ini or httpd.conf file.<br />

• If safe_mode_protected_env_vars is set in your php.ini or httpd.conf file, scripts<br />

are unable to overwrite the environment variables listed there.<br />

• If a prefix is set in safe_mode_allowed_env_vars in your php.ini or httpd.conf file,<br />

scripts can manipulate only environment variables starting with that prefix.<br />

• When using HTTP authentication, the numerical user ID of the current <strong>PHP</strong><br />

script is appended to the realm * string to prevent cross-script password sniffing,<br />

and the authorization header in the getallheaders( ) and phpinfo( ) output is<br />

hidden.<br />

• The functions set_time_limit( ), dl( ), and shell_exec( ) are disabled, as is the<br />

backtick (``) operator.<br />

To configure safe_mode and the various related settings, you can set the serverwide<br />

default in your php.ini file like this:<br />

safe_mode = On<br />

safe_mode_include_dir = /usr/local/php/include<br />

safe_mode_exec_dir = /usr/local/php/bin<br />

safe_mode_gid = On<br />

safe_mode_allowed_env_vars = <strong>PHP</strong>_<br />

safe_mode_protected_env_vars = LD_LIBRARY_PATH<br />

Alternately, you can set these from your httpd.conf file using the php_admin_value<br />

directive.Remember, these are system-level settings, and they cannot be set in your<br />

.htaccess file.<br />

<br />

ServerName domainA.com<br />

DocumentRoot /web/sites/domainA<br />

php_admin_value safe_mode On<br />

php_admin_value safe_mode_include_dir /usr/local/php/include<br />

php_admin_value safe_mode_exec_dir /usr/local/php/bin<br />

<br />

Concealing <strong>PHP</strong> Libraries<br />

Many a hacker has learned of weaknesses by downloading include files or data that<br />

are stored alongside HTML and <strong>PHP</strong> files in the web server’s document root.To prevent<br />

this from happening to you, all you need to do is store code libraries and data<br />

outside the server’s document root.<br />

For example, if the document root is /home/httpd/html, everything below that directory<br />

can be downloaded through a URL.It is a simple matter to put your library<br />

* This realm-mangling took a little vacation in <strong>PHP</strong> 4.0.x but is back in <strong>PHP</strong> 4.1 and later.<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.<br />

Concealing <strong>PHP</strong> Libraries | 293

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!