


Linux安全之PHP木馬查殺與防范
服務(wù)器安全防范篇
1.服務(wù)器自身系統(tǒng)安全:
使用最新的操作系統(tǒng),或者最新的穩(wěn)定版(比如Ubuntu的LTS),定期打好更新,系統(tǒng)權(quán)限合理劃分,重要文件做權(quán)限安全保護(hù)。
比如
# chattr +i /etc/passwd
# chattr +i /etc/group
# chattr +i /etc/shadow
# chattr +i /etc/gshadow
# chattr +i /etc/ssh/sshd_config
使用DenyHost程序防止SSH被暴力攻擊,具體方法見站外文章:http://www.myhack58.com/Article/48/66/2011/28833.htm
2.Web服務(wù)器和PHP的安全規(guī)則:
首先根據(jù)需求更新Web服務(wù)器和PHP,在網(wǎng)站程序目錄中嚴(yán)格定義權(quán)限,比如不會(huì)修改的地方 做好禁止寫入權(quán)限, upload目錄和cache等臨時(shí)目錄需要做好限制PHP或相關(guān)腳本運(yùn)行。
nginx規(guī)則相關(guān)腳本:
location ~ .*\.(php|php5)?$ {
…….
#——————————————
rewrite ^/(uc\_client|templates|include|plugins|admin|attachments|images|
forumdata)/.*\.(php|php5)?$ /50x.php last;
#——————————————-
}
apache規(guī)則相關(guān)腳本
<Directory "D:\opt\www\webroot\upload"> //注意:這里改成你需要屏蔽的目錄 比如upload目錄
php_flag engine off
<Files ~ "\.(php|jsp)">
Order allow,deny
Deny from all
</Files>
</Directory>
PHP.INI需要修改的地方(很重要)
查找:disable_functions
找到后在=后面添加
exec,system,passthru,error_log,ini_alter,dl,openlog,syslog,readlink,symlink,link,leak,fsockopen,proc_open,
popepassthru,chroot,scandir,chgrp,chown,escapeshellcmd,escapeshellarg,shell_exec,proc_get_status,popen
這里都是禁止在php里面執(zhí)行的函數(shù)
服務(wù)器木馬查殺篇(PHP)
1.安裝殺毒軟件,我的服務(wù)器使用的是avast效果還算比較好。
2.根據(jù)木馬特征掃描人工排查(人工排查這個(gè)就需要個(gè)人經(jīng)驗(yàn)判斷了)
PHP木馬的最明顯特征是使用了eval與base64_decode這個(gè)函數(shù)還有一些比較危險(xiǎn)的函數(shù)。
可以輸入下面的命令 進(jìn)行查詢
find /home/www/ -type f -name "*.php" | xargs grep "eval(" |more
增強(qiáng)版(在網(wǎng)站目錄執(zhí)行):
find ./ -name "*.php" |xargs egrep "phpspy|c99sh|milw0rm|eval\(gunerpress|eval\(base64_decoolcode|spider_bc"> /tmp/php.txt
grep -r –include=*.php '[^a-z]eval($_POST' . > /tmp/eval.txt
grep -r –include=*.php 'file_put_contents(.*$_POST\[.*\]);' . > /tmp/file_put_contents.txt
find ./ -name "*.php" -type f -print0 | xargs -0 egrep "(phpspy|c99sh|milw0rm|eval\(gzuncompress\(base64_decoolcode|eval\(base64_decoolcode|spider_bc|gzinflate)" | awk -F: '{print $1}' | sort | uniq
上面代碼最終會(huì)講名單輸出到 /tmp 目錄中 請(qǐng)直接查看列表 根據(jù)情況進(jìn)行處理。
查找最近一天被修改的PHP文件
#find -mtime -1 -type f -name \*.php
修改網(wǎng)站的權(quán)限
find -type f -name \*.php -exec chmod 444 {} \;
find ./ -type d -exec chmod 555{} \;
以上就是我最近在互聯(lián)網(wǎng)上查詢到的一些安全與查殺木馬的一些方法,也許還不是很全面,歡迎各位大大在留言中補(bǔ)充。
補(bǔ)充1:學(xué)會(huì)利用日志功能,查看黑客訪問了哪些文件逐條查詢,也許你會(huì)發(fā)現(xiàn)意想不到的東西-w-
補(bǔ)充2:如果覺得日志太多了,可以考慮刪除掉,然后過一會(huì)再來看。當(dāng)然大型網(wǎng)站 就麻煩了。
關(guān)鍵字:Linux、安全、服務(wù)器
新文章:
- CentOS7下圖形配置網(wǎng)絡(luò)的方法
- CentOS 7如何添加刪除用戶
- 如何解決centos7雙系統(tǒng)后丟失windows啟動(dòng)項(xiàng)
- CentOS單網(wǎng)卡如何批量添加不同IP段
- CentOS下iconv命令的介紹
- Centos7 SSH密鑰登陸及密碼密鑰雙重驗(yàn)證詳解
- CentOS 7.1添加刪除用戶的方法
- CentOS查找/掃描局域網(wǎng)打印機(jī)IP講解
- CentOS7使用hostapd實(shí)現(xiàn)無AP模式的詳解
- su命令不能切換root的解決方法
- 解決VMware下CentOS7網(wǎng)絡(luò)重啟出錯(cuò)
- 解決Centos7雙系統(tǒng)后丟失windows啟動(dòng)項(xiàng)
- CentOS下如何避免文件覆蓋
- CentOS7和CentOS6系統(tǒng)有什么不同呢
- Centos 6.6默認(rèn)iptable規(guī)則詳解