首先修改httpd.conf,如果你只允许你的php脚本程序在web目录里操作,还可以修改httpd.conf文件限制php的操作路径。比如你的web目录是/usr/local/apache/htdocs,那么在httpd.conf里加上这么几行: 9 y/ f$ m5 i6 V
php_admin_value open_basedir /usr/local/apache/htdocs4 |" U9 b6 a+ D+ [ p; p
. _( w2 I# F$ q+ H! X- m; B& Q
这样,如果脚本要读取/usr/local/apache/htdocs以外的文件将不会被允许,如果错误显示打开的话会提示这样的错误:% z- F2 @9 }$ M% O
Warning: open_basedir restriction in effect. File is in wrong directory in
$ ~6 l" q* _9 A. _$ {: R3 N /usr/local/apache/htdocs/open.php on line 4
" S. [, Z/ {* w5 e 等等。
8 |3 Y0 v& R* Y' a4 ^/ V! B" s 2.防止php木马执行webshell
t) Z4 x/ _8 L5 z2 B 打开safe_mode,7 U x C* ~5 R. [* ?8 y8 ~
在,php.ini中设置
0 j0 O0 D% D1 Z) o disable_functions= passthru,exec,shell_exec,system
9 I. J+ l1 T& W/ L- G$ U 二者选一即可,也可都选 1 ]4 E0 |3 P1 C( b. h* J
3.防止php木马读写文件目录 , O N9 _; Y) E! ?2 f" R2 u# `' d$ m
在php.ini中的4 @8 c. {5 ]: w |( k9 f: l
disable_functions= passthru,exec,shell_exec,system
) M2 g5 R6 F& M2 ? 后面加上php处理文件的函数- d8 U# [9 z$ Z, x
主要有' H- E) h; J- }; t) o
fopen,mkdir,rmdir,chmod,unlink,dir: U) E Q z2 W( T% R
fopen,fread,fclose,fwrite,file_exists' a% a' n" K Z6 U- U6 _3 r
closedir,is_dir,readdir.opendir
0 z- G( D2 [2 q T8 m! T; z: C3 H fileperms.copy,unlink,delfile0 R( o5 f* {* A% A E! s# \
即成为
+ d! d2 ?/ W8 N$ l/ R! O& v2 t disable_functions= passthru,exec,shell_exec,system,fopen,mkdir,rmdir,chmod,unlink,dir% H$ y5 i* f9 H9 H
,fopen,fread,fclose,fwrite,file_exists
/ Q8 [ k! w" G- N. r ,closedir,is_dir,readdir.opendir
$ U. b3 [ P5 p) j8 _ ,fileperms.copy,unlink,delfile
6 d# G1 d) p5 Q3 Z# c' N* x+ d& X) Y ok,大功告成,php木马拿我们没辙了,^_^
) c' {. C: j' ~. P0 D* ]& F 遗憾的是这样的话,利用文本数据库的那些东西就都不能用了。 " z C4 X. S; Z' S$ o
如果是在windos平台下搭建的apache我们还需要注意一点,apache默认运行是system权限,这很恐怖,这让人感觉很不爽.那我们就给apache降降权限吧. ; @) @2 b! G5 U
net user apache ****microsoft /add 0 v" M' T4 \& F3 R, I, F
net localgroup users apache /del ! \1 F+ x" Y7 S5 I( @ O; [8 Y" \
ok.我们建立了一个不属于任何组的用户apche.
/ }1 x$ _4 g9 b x$ B- E, e 我们打开计算机管理器,选服务,点apache服务的属性,我们选择log on ,选择this account ,我们填入上面所建立的账户和密码,重启apache服务,ok,apache运行在低权限下了.
t2 \- D& {% \0 x2 f 实际上我们还可以通过设置各个文件夹的权限,来让apache用户只能执行我们想让它能干的事情,给每一个目录建立一个单独能读写的用户.这也是当前很多虚拟主机提供商的流行配置方法哦,不过这种方法用于防止这里就显的有点大材小用了。
: q/ X8 T6 F, S# F( H |