首先修改httpd.conf,如果你只允许你的php脚本程序在web目录里操作,还可以修改httpd.conf文件限制php的操作路径。比如你的web目录是/usr/local/apache/htdocs,那么在httpd.conf里加上这么几行: 1 y2 m; O2 p" a
php_admin_value open_basedir /usr/local/apache/htdocs" {5 T8 _2 Y+ ^+ s" I, Y$ u! E
+ p9 D7 l' m( ]1 L2 Q( d! H# x% s S5 l
这样,如果脚本要读取/usr/local/apache/htdocs以外的文件将不会被允许,如果错误显示打开的话会提示这样的错误:
. C/ E' m) t6 w* O' Y Warning: open_basedir restriction in effect. File is in wrong directory in
3 `/ ~9 e% F6 ?9 G9 A( U /usr/local/apache/htdocs/open.php on line 4# x! x/ q- i' Q
等等。5 d2 }# y# B- M5 Z" u. }$ d% N
2.防止php木马执行webshell
" v% g8 e$ Y5 ` 打开safe_mode,0 S- S/ M Z* N
在,php.ini中设置7 n9 ]" j: b: R7 ]/ t
disable_functions= passthru,exec,shell_exec,system
( ?) W1 n9 L8 W* |9 p6 A 二者选一即可,也可都选
1 j3 Z0 ]5 s- ?) `& {$ M' X# x" j 3.防止php木马读写文件目录
* s8 c4 F7 i# X- ` 在php.ini中的8 \" g e. e( u7 l
disable_functions= passthru,exec,shell_exec,system
) G/ R1 L" H& m5 b 后面加上php处理文件的函数8 a; f+ H6 g$ G7 ~7 f0 Q
主要有) D4 |) l h# {" A9 \" c5 X4 W
fopen,mkdir,rmdir,chmod,unlink,dir( y& o; o5 |( I* I. X' b
fopen,fread,fclose,fwrite,file_exists6 j) \4 D8 E$ P5 o
closedir,is_dir,readdir.opendir
* V9 @' y+ \# k. z fileperms.copy,unlink,delfile( T8 v/ T# y, ~# l
即成为5 N: S: [1 H% L% p* o
disable_functions= passthru,exec,shell_exec,system,fopen,mkdir,rmdir,chmod,unlink,dir
( w6 }) ~4 R" L8 c, { ,fopen,fread,fclose,fwrite,file_exists
( I0 B/ W" \- f& k* c0 L% _ ,closedir,is_dir,readdir.opendir
! v- X8 k0 {) y% T( F! a ,fileperms.copy,unlink,delfile& V3 X4 V( }4 A$ g9 A. @
ok,大功告成,php木马拿我们没辙了,^_^
% R% r# h j) h7 T4 ?6 m8 P 遗憾的是这样的话,利用文本数据库的那些东西就都不能用了。 ( F. D5 `" w, V0 Q* j" d( o
如果是在windos平台下搭建的apache我们还需要注意一点,apache默认运行是system权限,这很恐怖,这让人感觉很不爽.那我们就给apache降降权限吧. 9 i+ y% F0 i! |/ S+ m3 I5 Q( {1 ~
net user apache ****microsoft /add 0 o9 m0 r8 _' u# P
net localgroup users apache /del 9 m) O( _/ x- o# b
ok.我们建立了一个不属于任何组的用户apche.
: R; j/ }6 {4 j: q$ N% ]- z 我们打开计算机管理器,选服务,点apache服务的属性,我们选择log on ,选择this account ,我们填入上面所建立的账户和密码,重启apache服务,ok,apache运行在低权限下了.
" B. D$ {& ?, L7 ^; g. D4 ~ 实际上我们还可以通过设置各个文件夹的权限,来让apache用户只能执行我们想让它能干的事情,给每一个目录建立一个单独能读写的用户.这也是当前很多虚拟主机提供商的流行配置方法哦,不过这种方法用于防止这里就显的有点大材小用了。
/ r; D7 c1 x O" H% E |