首先修改httpd.conf,如果你只允许你的php脚本程序在web目录里操作,还可以修改httpd.conf文件限制php的操作路径。比如你的web目录是/usr/local/apache/htdocs,那么在httpd.conf里加上这么几行:
# R4 L2 V' f" N php_admin_value open_basedir /usr/local/apache/htdocs9 z9 j7 l# U/ ]( w+ X- E
, h1 y1 ~, c# H- g* @ 这样,如果脚本要读取/usr/local/apache/htdocs以外的文件将不会被允许,如果错误显示打开的话会提示这样的错误:1 q% c, Z8 h. ^8 t% r0 v2 x
Warning: open_basedir restriction in effect. File is in wrong directory in
+ ^5 S- b+ m/ e3 ? /usr/local/apache/htdocs/open.php on line 41 x0 _1 n( p# D. q
等等。# \$ j- R& I$ a F f
2.防止php木马执行webshell
0 p& B. ~+ [: {3 A) ? 打开safe_mode,
% g" o& N1 V* c 在,php.ini中设置
: U @! r9 K; S: S( y: i disable_functions= passthru,exec,shell_exec,system
z8 V y( ] n' Z8 q( b- C 二者选一即可,也可都选 , D6 f2 x/ T" o5 i1 Z, M
3.防止php木马读写文件目录 1 x) p* Q- F! f5 T9 r
在php.ini中的" V2 M1 \9 v. B4 g5 r, U
disable_functions= passthru,exec,shell_exec,system - v* E6 ~ z& ?& z, U" l
后面加上php处理文件的函数6 T# m: r( l/ Q8 R9 g3 l, o$ O" J
主要有
1 }& Q. H E5 s! O( L8 I. a: e fopen,mkdir,rmdir,chmod,unlink,dir
- U% T4 D+ Q+ G; T fopen,fread,fclose,fwrite,file_exists
1 l# C" X7 x4 k6 ^0 N0 { closedir,is_dir,readdir.opendir
6 l) S! v! b# n$ n fileperms.copy,unlink,delfile
* S" o$ S* K! x/ D) ~$ w 即成为
J- d- `3 s2 T disable_functions= passthru,exec,shell_exec,system,fopen,mkdir,rmdir,chmod,unlink,dir B; y1 h+ Q' `+ w* i5 x4 F d
,fopen,fread,fclose,fwrite,file_exists |5 j; l$ O2 X) B5 o4 {
,closedir,is_dir,readdir.opendir4 g2 Y9 M- s, \5 p0 w0 V( I6 I
,fileperms.copy,unlink,delfile5 Q% `# l2 O9 P( X& q. [, w+ A
ok,大功告成,php木马拿我们没辙了,^_^3 e* g' A2 V0 C* S
遗憾的是这样的话,利用文本数据库的那些东西就都不能用了。 ) c( V9 W$ q0 P7 B" O
如果是在windos平台下搭建的apache我们还需要注意一点,apache默认运行是system权限,这很恐怖,这让人感觉很不爽.那我们就给apache降降权限吧.
6 E1 J5 J0 \' S8 |" I8 l net user apache ****microsoft /add
5 M4 j+ ]8 n/ S% t* {9 e7 E! }9 ` net localgroup users apache /del
0 b+ `" d3 `) F4 x$ C; ? ok.我们建立了一个不属于任何组的用户apche.
0 @& l: R1 ?, x4 B7 B$ h; R9 f( D 我们打开计算机管理器,选服务,点apache服务的属性,我们选择log on ,选择this account ,我们填入上面所建立的账户和密码,重启apache服务,ok,apache运行在低权限下了.
/ {/ A, L$ i0 C @ 实际上我们还可以通过设置各个文件夹的权限,来让apache用户只能执行我们想让它能干的事情,给每一个目录建立一个单独能读写的用户.这也是当前很多虚拟主机提供商的流行配置方法哦,不过这种方法用于防止这里就显的有点大材小用了。 : w! {& N' ~/ w% {9 a9 \5 i
|