2011-11-24 48 views
1

我運行Linux CentOS的,我試圖找到我的WordPress安裝使用此命令的一些惡意代碼:爲什麼這種模式搜索掛起?

grep -r 'php \$[a-zA-Z]*=.as.;' * |awk -F : '{print $1}' 

當我按下回車鍵,過程只是掛起...我想仔細檢查我有正確的語法,我只需要等待?

如何在搜索時獲得某種反饋/發生的事情?

感謝

+0

你想匹配什麼? – NullUserException

+0

'awk -F:'{print $ 1}''好像是一個......有趣的(?)黑客來獲得'grep -l'或'grep -h'? – sehe

回答

1

它大概考慮它的時間,由於-r *(遞歸,所有文件/迪爾斯)?

考慮

find -type f -print0 | xargs -0trn10 grep -l 'php \$[a-zA-Z]*=.as.;' 

將處理在(最大)10,以及打印這些命令,因爲它去的批的文件。

當然,這樣你也許可以優化赫克出來,利用簡便的手段像

find -type f -iname '*.php' -print0 | xargs -0trn10 grep -l 'php \$[a-zA-Z]*=.as.;' 

類相關:

你可以做類似的事情沒有找到較小的樹木,與最近的bash:

shopt -s globstar 
grep -l 'pattern' **/*.php 
+0

謝謝!......但第一個命令打印出來的究竟是什麼?我看到了一噸線lol ... – algorithmicCoder

+0

@algorithmicCoder:** 1。**剛剛閱讀'find -type f |少-SR';現在,** 2。**它是很多行,但不超過你的命令遍歷!試試'grep -lr'。?' *爲了好玩......看看它爲什麼很慢? – sehe

1

而不是使用grep -r遞歸grep,一個選項是使用find來獲取文件名列表,並將它們一次一個地提供給grep。這可以讓您在grep旁邊添加其他命令,例如echo s。例如,您可以創建一個名爲is-it-malware.sh腳本包含此:

#!/bin/bash 

if grep 'php \$[a-zA-Z]*=.as.;' "$1" >/dev/null 
then 
    "!!! $1 is malware!!!" 
else 
    " $1 is fine." 
fi 

並運行此命令:

find -type f -exec ./is-it-malware.sh '{}' ';' 

超過當前目錄中的所有文件運行腳本及其所有子目錄(遞歸)。