PHP腳本木馬的高級(jí)防范經(jīng)驗(yàn)
發(fā)布日期:2022-01-28 16:51 | 文章來(lái)源:gibhub
1、首先修改httpd.conf,如果你只允許你的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中設(shè)置 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木馬拿我們沒(méi)轍了,遺憾的是這樣的話,利用文本數(shù)據(jù)庫(kù)的那些東西就都不能用了。
如果是在windos平臺(tái)下搭建的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。
我們打開計(jì)算機(jī)管理器,選服務(wù),點(diǎn)apache服務(wù)的屬性,我們選擇log on,選擇this account,我們填入上面所建立的賬戶和密碼,重啟apache服務(wù),ok,apache運(yùn)行在低權(quán)限下了。
實(shí)際上我們還可以通過(guò)設(shè)置各個(gè)文件夾的權(quán)限,來(lái)讓apache用戶只能執(zhí)行我們想讓它能干的事情,給每一個(gè)目錄建立一個(gè)單獨(dú)能讀寫的用戶。這也是當(dāng)前很多虛擬主機(jī)提供商的流行配置方法哦,不過(guò)這種方法用于防止這里就顯的有點(diǎn)大材小用了。
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中設(shè)置 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木馬拿我們沒(méi)轍了,遺憾的是這樣的話,利用文本數(shù)據(jù)庫(kù)的那些東西就都不能用了。
如果是在windos平臺(tái)下搭建的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。
我們打開計(jì)算機(jī)管理器,選服務(wù),點(diǎn)apache服務(wù)的屬性,我們選擇log on,選擇this account,我們填入上面所建立的賬戶和密碼,重啟apache服務(wù),ok,apache運(yùn)行在低權(quán)限下了。
實(shí)際上我們還可以通過(guò)設(shè)置各個(gè)文件夾的權(quán)限,來(lái)讓apache用戶只能執(zhí)行我們想讓它能干的事情,給每一個(gè)目錄建立一個(gè)單獨(dú)能讀寫的用戶。這也是當(dāng)前很多虛擬主機(jī)提供商的流行配置方法哦,不過(guò)這種方法用于防止這里就顯的有點(diǎn)大材小用了。
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。
相關(guān)文章