Bash 脚本删除 iframe 病毒

发布于 2024-08-04 11:43:08 字数 64 浏览 3 评论 0原文

我想要一个 bash 脚本来递归读取目录中的所有文件并从中删除一些代码(即 iframe 病毒)并保存回原始文件。

I want a bash script to read all files recursively in a directory and remove some code (i.e a iframe virus) from it and save back the orignal file.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

记忆里有你的影子 2024-08-11 11:43:08

您需要显示要删除的 iframe 片段,但通常您可以使用 find & 来完成此操作sed。如果您不确切知道如何编写此类脚本,请向我们提供更多信息,例如要删除的 html 文件扩展名和 iframe 模式(特别是如果它并不总是相同)。

好的,假设您有 PHP 文件,并且想要删除每个 iframe 标记(因此,没有其他有用的 iframe),您可以使用以下解决方案:首先,编写 change.sh shell 脚本,如下所示:

#!/bin/bash

sed 's/<iframe[^>]*>.*<\/iframe>//g' < "$1" > "$1.tmp"
mv "$1.tmp" "$1"

然后,你可以使用这个:

find . -name "*.php" | xargs -i ./change.sh {} \;

这样就可以完成工作。我的测试通过了。

You need to show that piece of iframe to remove, but generally you can do this with find & sed. If you don't know exactly how to write such script, give us more information like html files extensions and iframe pattern to remove (especially if it is not always the same).

OK, suppose you have PHP files and you want to remove every iframe tag (so, there are no other useful iframes), you can use this solution: first, write change.sh shell script like this:

#!/bin/bash

sed 's/<iframe[^>]*>.*<\/iframe>//g' < "$1" > "$1.tmp"
mv "$1.tmp" "$1"

Then, you can use this:

find . -name "*.php" | xargs -i ./change.sh {} \;

And that will do the job. My tests passed.

故笙诉离歌 2024-08-11 11:43:08

这个 合适吗?

Would this be appropriate?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文