首先修改httpd.conf,如果你只允许你的php脚本程序在web目录里操作,还可以修改httpd.conf文件限制php的操作路径。比如你的web目录是/usr/local/apache/htdocs,那么在httpd.conf里加上这么几行:
: V* N6 g9 f2 h$ N/ b/ M! ` S php_admin_value open_basedir /usr/local/apache/htdocs: T: ^4 D! T9 {2 `! C/ w3 e
. o# {& i. a1 A6 ^" d: h9 o8 O W$ f3 F
这样,如果脚本要读取/usr/local/apache/htdocs以外的文件将不会被允许,如果错误显示打开的话会提示这样的错误:
1 i4 w1 S) ^; e5 B0 c) {+ ? Warning: open_basedir restriction in effect. File is in wrong directory in' Z( w3 ?5 g' P& f5 U( U% V
/usr/local/apache/htdocs/open.php on line 4, ^( X* D3 p' v/ l [
等等。
( Q' ]. i; w3 p: R0 C- k 2.防止php木马执行webshell- D* D- J. r6 r: w# ?+ S$ M9 `: v/ {3 G
打开safe_mode,9 f P6 I8 {+ G* u: m* l: R
在,php.ini中设置8 D$ x5 i; r. {# e H
disable_functions= passthru,exec,shell_exec,system
/ B' L( b6 N2 |3 x! r* q& C 二者选一即可,也可都选
4 J- g7 S/ H$ R) h6 I 3.防止php木马读写文件目录
- ^% O. s! Y4 ^+ u5 Q% u 在php.ini中的
/ D$ T2 j7 V' D8 T9 @ disable_functions= passthru,exec,shell_exec,system # n7 z2 r0 s2 J" z A, R* ~
后面加上php处理文件的函数
9 J$ e; l; R2 U& ~! e s 主要有2 o" Y @5 {$ l+ Z, G9 s$ t
fopen,mkdir,rmdir,chmod,unlink,dir# M3 u/ q6 \) w0 M- [
fopen,fread,fclose,fwrite,file_exists* u3 [. `( e* L, {6 A
closedir,is_dir,readdir.opendir5 f, A; G0 _" y% o1 K3 |: {
fileperms.copy,unlink,delfile
& G, i2 `% ` i5 s 即成为
! ]8 ^5 ^% @1 J1 }9 Q disable_functions= passthru,exec,shell_exec,system,fopen,mkdir,rmdir,chmod,unlink,dir$ K2 f, A8 P. u# Z- U& E
,fopen,fread,fclose,fwrite,file_exists
4 l7 I" H/ R/ e! k ,closedir,is_dir,readdir.opendir
( N2 A" Z' \# ^' U c ,fileperms.copy,unlink,delfile9 O7 W! O! x u8 i
ok,大功告成,php木马拿我们没辙了,^_^
0 l% y% R0 J9 U' }5 O 遗憾的是这样的话,利用文本数据库的那些东西就都不能用了。 0 V) L0 i# T: t
如果是在windos平台下搭建的apache我们还需要注意一点,apache默认运行是system权限,这很恐怖,这让人感觉很不爽.那我们就给apache降降权限吧.
+ o9 \( \* k" g9 M% v# h: U) D+ G9 h net user apache ****microsoft /add
( ~. J1 K/ M6 H/ a* d4 [" n. e' b net localgroup users apache /del 5 {0 P! y6 G& {( J( c
ok.我们建立了一个不属于任何组的用户apche.
% {: W- Q* s l# e, o 我们打开计算机管理器,选服务,点apache服务的属性,我们选择log on ,选择this account ,我们填入上面所建立的账户和密码,重启apache服务,ok,apache运行在低权限下了.
5 M7 F- \+ g7 S9 L. p9 D 实际上我们还可以通过设置各个文件夹的权限,来让apache用户只能执行我们想让它能干的事情,给每一个目录建立一个单独能读写的用户.这也是当前很多虚拟主机提供商的流行配置方法哦,不过这种方法用于防止这里就显的有点大材小用了。 . q! _5 E( o G- e1 s! |' E/ O
|