本文通過介紹一些技巧介紹了針對PHP木馬攻擊的防御之道,通過這些方面您能夠更好的防范木馬程式。提供網(wǎng)站安全系數(shù)
1、防止跳出web目錄
首先修改 httpd.conf(Apache配置文件),假如您只允許您的php腳本程式在web目錄里操作,還能夠修改httpd.conf文檔限制php的操作路徑。
比如您的web目錄是/usr/local/apache/htdocs,那么在httpd.conf里加上這么幾行:
php_admin_value open_basedir /usr/local/apache /htdocs
這樣,假如腳本要讀取/usr/local/apache/htdocs以外的文檔將不會(huì)被允許,假如錯(cuò)誤顯示打開的話會(huì)提示這樣的錯(cuò)誤:
Warning: open_basedir restriction in effect. File is in wrong directory in /usr/local/apache/htdocs/open.php on line 4 等等。
2、防止php木馬執(zhí)行webshell
打開safe_mode,或者 在php.ini中配置disable_functions= passthru,exec,shell_exec,system
二者選一即可,也可都選
3、防止php木馬讀寫文檔目錄
在php.ini中的disable_functions= passthru,exec,shell_exec,system后面加上php處理文檔的函數(shù)
主要有
fopen,mkdir,rmdir,chmod,unlink,dir
fopen,fread,fclose,fwrite,file_exists
closedir,is_dir,readdir.opendir
fileperms.copy,unlink,delfile
即成為
disable_functions=passthru,exec,shell_exec,system,fopen,mkdir,rmdir,chmod,unlink,dir,fopen,fread,fclose,fwrite,file_exists,closedir,is_dir,readdir.opendir,fileperms.copy,unlink,delfile
ok,大功告成,php木馬拿我們沒轍了,遺憾的是這樣的話,利用文本數(shù)據(jù)庫的那些東西就都不能用了。
假如是在windos平臺下搭建的apache我們還需要注意一點(diǎn),apache默認(rèn)運(yùn)行是system權(quán)限,這很恐怖,這讓人感覺很不爽.那我們就給apache降降權(quán)限吧。
net user apache fuckmicrosoft /add
net localgroup users apache /del
ok.我們建立了一個(gè)不屬于任何組的用戶apche。
我們打開電腦管理器,選服務(wù),點(diǎn)apache服務(wù)的屬性,我們選擇log on,選擇this account,我們填入上面所建立的賬戶和密碼,重啟apache服務(wù),ok,apache運(yùn)行在低權(quán)限下了。
實(shí)際上我們還能夠通過配置各個(gè)文檔夾的權(quán)限,來讓apache用戶只能執(zhí)行我們想讓他能干的事情,給每一個(gè)目錄建立一個(gè)單獨(dú)能讀寫的用戶。
這也是當(dāng)前很多虛 擬主機(jī)提供商的流行配置方法哦,但是這種方法用于防止這里就顯的有點(diǎn)大材小用了。