2011-11-24 51 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 '{}' ';' 

超过当前目录中的所有文件运行脚本及其所有子目录(递归)。