首先修改httpd.conf,如果你只允许你的php脚本程序在web目录里操作,还可以修改httpd.conf文件限制php的操作路径。比如你的web目录是/usr/local/apache/htdocs,那么在httpd.conf里加上这么几行: 5 C" s8 U/ i( v- W/ e
php_admin_value open_basedir /usr/local/apache/htdocs
, A; p" b' @6 I4 C ! j3 W$ s, }3 q \ ?
这样,如果脚本要读取/usr/local/apache/htdocs以外的文件将不会被允许,如果错误显示打开的话会提示这样的错误:4 k- Y1 h" ?- M: T$ E( E0 `
Warning: open_basedir restriction in effect. File is in wrong directory in. i' d' B. D; n' X7 a+ F* c
/usr/local/apache/htdocs/open.php on line 42 h9 N1 A3 [" I, \$ M) \ c+ _, ^
等等。) O9 ~: H$ Z. y" q
2.防止php木马执行webshell
@' D- f- K! \* `/ } 打开safe_mode,1 |' [$ X3 l/ D3 M5 R" q3 O
在,php.ini中设置5 b# B& U( m9 l) l9 t7 Q a& r
disable_functions= passthru,exec,shell_exec,system
1 O. d$ i) _# l 二者选一即可,也可都选 G" [& g( s/ J* P- d( x' n# n: |) F
3.防止php木马读写文件目录 5 ~0 |. z# j& ?& l
在php.ini中的
" s0 Y- G8 a( V3 N4 X disable_functions= passthru,exec,shell_exec,system ) }1 R/ m( m1 q& @
后面加上php处理文件的函数
/ F' o- r) b. i# q. [" Z 主要有& X: m e! ]1 X$ w1 q4 y3 s% p7 W
fopen,mkdir,rmdir,chmod,unlink,dir
1 L) ^' x( H: x. M( F7 j9 e r fopen,fread,fclose,fwrite,file_exists
, J9 \4 V2 h! d7 t! P closedir,is_dir,readdir.opendir" E" P% t" N* V, M S7 `. [' g
fileperms.copy,unlink,delfile0 d5 k! L9 g0 v9 }: |; g1 ?2 K# P
即成为$ {( x6 ]& ] R& Q
disable_functions= passthru,exec,shell_exec,system,fopen,mkdir,rmdir,chmod,unlink,dir! S5 I! Q( G( I2 i
,fopen,fread,fclose,fwrite,file_exists
7 o$ s* `' W- b! k ,closedir,is_dir,readdir.opendir
2 L/ f1 S) {+ C6 W2 q! R3 |, K ,fileperms.copy,unlink,delfile; M8 m1 W$ `& z$ w& \5 c i
ok,大功告成,php木马拿我们没辙了,^_^
# _9 d% R9 \$ K' @$ i" \" ?/ Z 遗憾的是这样的话,利用文本数据库的那些东西就都不能用了。 : { O1 @. H, Z" { B5 \" T
如果是在windos平台下搭建的apache我们还需要注意一点,apache默认运行是system权限,这很恐怖,这让人感觉很不爽.那我们就给apache降降权限吧. # u' h# @# |9 s6 R3 Q0 e
net user apache ****microsoft /add
! Z# C4 B- T- r! t$ B net localgroup users apache /del
) G/ `9 V% f, }2 T! b% i: G3 d- U2 k ok.我们建立了一个不属于任何组的用户apche.
3 j" b$ Z: e4 U' X 我们打开计算机管理器,选服务,点apache服务的属性,我们选择log on ,选择this account ,我们填入上面所建立的账户和密码,重启apache服务,ok,apache运行在低权限下了.- P$ T3 b6 Y! b( o" g
实际上我们还可以通过设置各个文件夹的权限,来让apache用户只能执行我们想让它能干的事情,给每一个目录建立一个单独能读写的用户.这也是当前很多虚拟主机提供商的流行配置方法哦,不过这种方法用于防止这里就显的有点大材小用了。
- E9 `/ p/ A5 R3 k% a l! J |