防范php木马
1、防止跳出web目录 (严重采用)
首先修改httpd.conf,如果你只允许你的php脚本程序在web目录里操作,还可以修改httpd.conf文件限制php的操作路径。比如你的web目录是/usr/local/apache/htdocs,那么在httpd.conf里加上这么几行:
php_admin_value open_basedir /usr/local/apache/htdocs
这样,如果脚本要读取/usr/local/apache/htdocs以外的文件将不会被允许,如果错误显示打开的话会提示这样的错误:
Warning: open_basedir restriction in effect. File is in wrong directory in /usr/local/apache/htdocs/open.php on line 4 等等。
如果有多个基于域名的虚拟主机
<VirtualHost *>
ServerName www.test1.com
DocumentRoot /usr/local/apache/htdocs/test1
<Directory /usr/local/apache/htdocs/test1>
php_admin_value open_basedir /usr/local/apache/htdocs/test1
</Directory>
</VirtualHost>
注意:在php_admin_value open_basedir别忘了加上php.ini中指定的PHP临时上传目录和session保存目录,不然会无法上传文件、存取session
php.ini中按如下配置:
upload_tmp_dir = "/tmp"
session.save_path = "/var/phpsession"
2、防止php木马执行webshell (严重采用)
打开safe_mode,
在,php.ini中设置
disable_functions= passthru,exec,shell_exec,system
二者选一即可,也可都选
3、防止php木马读写文件目录 (好像没有要求这么严格,不推荐采用。)
在php.ini中的
disable_functions= passthru,exec,shell_exec,system
后面加上php处理文件的函数
主要有
fopen,mkdir,rmdir,chmod,unlink,dir
fopen,fread,fclose,fwrite,file_exists
closedir,is_dir,readdir.opendir
fileperms.copy,unlink,delfile
即成为
disable_functions= passthru,exec,shell_exec,system,fopen,mkdir,rmdir,chmod,unlink,dir
,fopen,fread,fclose,fwrite,file_exists
,closedir,is_dir,readdir.opendir
,fileperms.copy,unlink,delfile
ok,大功告成,php木马拿我们没辙了.
相关文档:
环境软件版本介绍:
APACHE 2.0.59
PHP5.2.3
MYSQL5.0.45
GD-2.0.35
Zend Optimizer v3.3.0
  ......
<?php
/********************************************************************
* FileName: class.msn.php
* by changwei, 2010-4-13
* Contact MSN: changwei0112@hotmail.com
* 获取MSN好友Email列表
*
========================== ......
PHP Code one: //php获取ip的算法
$iipp=$_SERVER["REMOTE_ADDR"];
echo $iipp; PHP Code two: //php获取ip的算法
$user_IP = ($_SERVER["HTTP_VIA"]) ? $_SERVER["HTTP_X_FORWARDED_FOR"] : $_SERVER["REMOTE_ADDR"];
$user_IP = ($user_IP) ? $user_IP : $_SERVER["REMOTE_ADDR"];
echo $ ......
刚写完前面的日志,又发现一个Bug:
根据Oracle官方提供的说明:
http://www.oracle.com/technology/documentation/berkeley-db/db/programmer_reference/ext_php.html
class Db4的声明如下:
class Db4 {
function Db4($dbenv = null) {} // create a new Db4 object using
......
从php5.10开始,php中加入了时区的设置,在php中显示的时间都是格林威治标准时间,这就造成了我们中国的用户会差八个小时的问题!
相关设置是修改php.ini中的 date.timezone 参数:
[Date]
; Defines the default timezone used by the date functions
;date.timezone =
默认是关闭的,只需把注释去掉,改为即可
[Dat ......