Wordpress Getting Hacked?

Bulletproof was mentioned above. I've mashed what I've learned there with WP-Padlock and some YouTube videos.
Go to my site secure-your-website dot com. The $17 plug-in (I renamed WP-Padlock) does add another layer of security,
but you can get away with what I've written via the link down the page "My Written Instructions". It's a heck of lot easier
than everything suggested in Bulletproof. My instructions include a few simple tests (from Bulletproof) to see if a WordPress site is secure.

The two most important are:

1. Change your user name from admin to something else.
2. Use Login Lockdown plugin so that log-in attempts are limited to three tries and then the system
shuts down for an hour.
 
Last edited:
This is a pretty regular occurrence.

Only download plugins and themes from trusted sources. If you do go down the cracked route.. make sure to run it through virus total before putting it on any of your sites.. I actually have a cheap host with a random domain on it that I frequently test these things on and run through some security features I have on my server and through a few WP plugins that can scan these things.

Then I drop onto money site. For starters change pass for WP, Data Base and FTP.. This will get you started in the right direction.
 
Its quite possible that its an issue with your hosting. I was using shared hosting for some of my sites and they constantly got hacked, regardless of how secure I made them. Turns out that a site on another person's hosting account (on the same server) got hacked and that led to mine getting hacked as well.
 
What I do when I get hacked is I delete any untrustworthy plugins.
Delete all unused themes from my theme directory and consider changing my theme to the default one until I'm sure I'm clean and not being re-infected.
Then I check theses files for oddities:
index.php
wp-config.php
wp-settings.php


I check for and delete these files because they are malicious:
/wp-admin/js/config.php
/wp-admin/common.php
feed_file.php
feed-files.php
udp.php
/wp-content/uploads/r1.php
/wp-content/uploads/lib.php
/wp-content/uploads/am3.php
/wp-content/uploads/create.php
timthumb.php


Then I check my .htaccess file to see if it was hacked.
Then I check my wp-content/uploads/ directory and subdirectory for oddities


I make sure all the blogs on my host are updated and repeat the process for any blog I suspect has been compromised...
most of the time all blogs on a host will be compromised if one is...


But it might be better to just delete all your wordpress files for each site and reupload them along with trustworthy plugins and themes.


Hassle!




and also be careful with this script, but it can be modified to help clear an infection if you know how to pattern the infection.
Warning! Make sure you know what's going on before you try to run this on your site! This is for people who have PHP knowledge!


Code:
<?php
$level=5;
function get_sorted($path)
{
    //$ignore = array('.',"'","error_log");
    $dh = @opendir( $path );
    while ($file = @readdir( $dh ))
    {
        if (!strstr($file,'.')&&!strstr($file,"'")&&!strstr($file,"error_log")&&!strstr($file,"README")&&!strstr($file,"cookietxt")&&$file!='.'&&$file!='..')
        {
            $directories[] = $file;
        }
        else
        {
            if ($file!='.'&&$file!='..')
            {
                $files[] = $file;
            }
        }
    }
    
    $array = array($directories,$files);
    return $array;
}




function clean_files($files, $path)
{
    //echo 1;exit;
    if ($files)
    {
        foreach($files as $key=>$val)
        {
            //echo $val;
            if ($val == 'index.php')
            {
                //echo 1; exit;
                //fopen .htacess
                $targetFile = "$path/$val"; 
                echo "Checking: $targetFile <br>";




                $handle1 = fopen($targetFile, 'r');      
                $data = @fread($handle1,filesize($targetFile)); 
                fclose($handle1);
                
                
                   
                $string = preg_match('/eval.base64_decode(.*?)\;/', $data, $matches );
                $string = $matches[0];
            
                if ($string)
                {
                    echo "MALWARE FOUND IN $targetFile ! ... rewriting!<br>";
                    $data = str_replace($string,'', $data);
                    $handle1 = fopen($targetFile, 'w');
                    fwrite($handle1, $data);
                    fclose($handle1);
                    //exit;
                }
                unset($string);
                unset($data);
                
            }
            else if (strstr($val,'htaccess'))
            {
                //echo 1; exit;
                //fopen .htacess
                $targetFile = "$path/$val"; 
                
                echo "Checking: $targetFile <br>";




                $handle1 = fopen($targetFile, 'r');      
                $data = @fread($handle1,filesize($targetFile)); 
                fclose($handle1);
                
             }  


            else if (strstr($val,'wp-config.php'))
            {
                //echo 1; exit;
                //fopen .htacess
                $targetFile = "$path/$val"; 
                
                echo "Checking: $targetFile <br>";




                $handle1 = fopen($targetFile, 'r');      
                $data = @fread($handle1,filesize($targetFile)); 
                fclose($handle1);
                
                
                   
            
                if (strstr($data,'get_userdatabylogin'))
                {
                    echo "MALWARE FOUND IN $targetFile ! ... rewriting!<br>";
                    
                    mail("[email protected]","WP-Config FILE CORRUPTED! MANUAL EDIT REQUIRED ","SEE $targetFile");
                }
                unset($string);
                unset($data);
                
            }    
            else if (strstr($val,'wp-settings.php'))
            {
                //echo 1; exit;
                //fopen .htacess
                $targetFile = "$path/$val"; 
                
                echo "Checking: $targetFile <br>";




                $handle1 = fopen($targetFile, 'r');      
                $data = @fread($handle1,filesize($targetFile)); 
                fclose($handle1);
                
                
                   
            
                if (strstr($data,'google_bot'))
                {
                    echo "MALWARE FOUND IN $targetFile ! ... rewriting!<br>";
                    
                    mail("[email protected]","WP-Config FILE CORRUPTED! MANUAL EDIT REQUIRED ","SEE $targetFile");
                }
                unset($string);
                unset($data);
                
            }
            else if (strstr($val,'thumbs.db'))
            {
                
                echo "MALWARE FOUND IN $targetFile ! ... rewriting!<br>";
                unlink($targetFile);
                
                    
                mail("[email protected]","THMBS.DB FILE FOUND! ","SEE $targetFile");
                
            }
            else if (strstr($val,'feed_file.php'))
            {
                
                echo "MALWARE FOUND IN $targetFile ! ... rewriting!<br>";
                unlink($targetFile);                    
                mail("[email protected]","MALWARE FILE FOUND! ","SEE $targetFile");
                
            }
            Else if (strstr($targetFile,'/wp-admin/js/config.php'))
            {
                
                echo "MALWARE FOUND IN $targetFile ! ... rewriting!<br>";
                unlink($targetFile);                    
                mail("[email protected]","MALWARE FILE FOUND! ","SEE $targetFile");
                
            }
            Else if (strstr($targetFile,'/wp-admin/common.php'))
            {
                
                echo "MALWARE FOUND IN $targetFile ! ... rewriting!<br>";
                unlink($targetFile);                    
                mail("[email protected]","MALWARE FILE FOUND! ","SEE $targetFile");
                
            }
            Else if (strstr($targetFile,'udp.php'))
            {
                
                echo "MALWARE FOUND IN $targetFile ! ... rewriting!<br>";
                unlink($targetFile);                    
                mail("[email protected]","MALWARE FILE FOUND! ","SEE $targetFile");
                
            }
            Else if (strstr($targetFile,'feed-files.php'))
            {
                
                echo "UDP MANUAL DELETE! MALWARE FOUND IN $targetFile ! ... rewriting!<br>";
                unlink($targetFile);                    
                mail("[email protected]","MALWARE FILE FOUND! ","SEE $targetFile");
                
            }
            Else if (strstr($targetFile,'feed-file.php'))
            {
                
                echo "UDP MANUAL DELETE! MALWARE FOUND IN $targetFile ! ... rewriting!<br>";
                unlink($targetFile);                    
                mail("[email protected]","MALWARE FILE FOUND! ","SEE $targetFile");
                
            }
            Else if (strstr($targetFile,'/wp-content/uploads/r1.php'))
            {
                
                echo "UDP MANUAL DELETE! MALWARE FOUND IN $targetFile ! ... rewriting!<br>";
                unlink($targetFile);                    
                mail("[email protected]","MALWARE FILE FOUND! ","SEE $targetFile");
                
            }
            Else if (strstr($targetFile,'/wp-content/uploads/r2.php'))
            {
                
                echo "UDP MANUAL DELETE! MALWARE FOUND IN $targetFile ! ... rewriting!<br>";
                unlink($targetFile);                    
                mail("[email protected]","MALWARE FILE FOUND! ","SEE $targetFile");
                
            }
            Else if (strstr($targetFile,'/wp-content/uploads/lib.php'))
            {
                
                echo "UDP MANUAL DELETE! MALWARE FOUND IN $targetFile ! ... rewriting!<br>";
                unlink($targetFile);                    
                mail("[email protected]","MALWARE FILE FOUND! ","SEE $targetFile");
                
            }    
            Else if (strstr($targetFile,'/wp-content/uploads/am3.php'))
            {
                
                echo "UDP MANUAL DELETE! MALWARE FOUND IN $targetFile ! ... rewriting!<br>";
                unlink($targetFile);                    
                mail("[email protected]","MALWARE FILE FOUND! ","SEE $targetFile");
                
            }
            Else if (strstr($targetFile,'/wp-content/uploads/create.php'))
            {
                
                echo "UDP MANUAL DELETE! MALWARE FOUND IN $targetFile ! ... rewriting!<br>";
                unlink($targetFile);                    
                mail("[email protected]","MALWARE FILE FOUND! ","SEE $targetFile");
                
            }
            Else if (strstr($targetFile,'timthumb.php'))
            {
                
                echo "MALWARE FOUND IN $targetFile ! ... rewriting!<br>";
                unlink($targetFile);
                
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL, "http://timthumb.googlecode.com/svn/trunk/timthumb.php");
                curl_setopt($ch, CURLOPT_HEADER, false);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
                $data = curl_exec($ch);
                curl_close($ch);
                
                                
                $handle1 = fopen($targetFile, 'w');
                fwrite($handle1, $data);
                fclose($handle1);
                                    
            }
            
        }
    }
    else
    {
        echo "<br>No files discovered in $path<br>";
    }
}




//clean first level
$array = get_sorted('.');
$directories = $array[0];
$files = $array[1];
clean_files($files,'.');




//get second level & clean
foreach ($directories as $key=>$val)
{
    $p_1 = "./$val";
    $a_1 = get_sorted($val);
    $d_1 = $a_1[0];
    $f_1 = $a_1[1];
    
    //echo $val;
    //print_r($d_1);
    //echo "<hr>";
    clean_files($f_1, "{$p_1}");
    
    //check and clean level 2
    if ($d_1)
    {
        foreach ($d_1 as $k_1=>$v_1)
        {
            //echo $v_1;exit;
            $p_2 = $p_1.'/'.$v_1;
            $a_2 = get_sorted($p_2);
            $d_2 = $a_2[0];
            $f_2 = $a_2[1];
            
            clean_files($f_2, $p_2);
            
            if ($d_2)
            {
                //check and clean level 3
                foreach ($d_2 as $k_2=>$v_2)
                {
                    
                    $p_3 = $p_2.'/'.$v_2;
                    //echo $p_3;
                    $a_3 = get_sorted($p_3);
                    $d_3 = $a_3[0];
                    $f_3 = $a_3[1];
                    //echo"<hr>$v_2";
                    //print_r($f_3);exit;
                    clean_files($f_3, $p_3);
                    //unset($
                }
                
                //check and clean level 4
                if ($d_3)
                {
                    foreach ($d_3 as $k_3=>$v_3)
                    {
                        $p_4 = $p_3.'/'.$v_3;
                        $a_4 = get_sorted($p_4);
                        $d_4 = $a_4[0];
                        $f_4 = $a_4[1];
                        
                        clean_files($f_4, $p_4);
                    }
                    
                    //check and clean level 5
                    if ($d_4&&$level==5)
                    {
                        foreach ($d_4 as $k_4=>$v_4)
                        {
                            $p_5 = $p_4.'/'.$v_4;
                            $a_5 = get_sorted($p_5);
                            $d_5 = $a_5[0];
                            $f_5 = $a_5[1];
                            
                            clean_files($f_5, $p_5);
                        }
                    }
                }
            }
        }
    }
    
}
















?>
 
Two of my sites got hacked 5 times in one week. The only solution to keep them safe that worked for me is to disable acces to admin directory with .htaccess and permit only by ip. Since then, they didn't hacked my sites anymore.
 
check if your anonymous ftp is enabled, if yes disable it and also change all your ftp passwords and wp-login passwords.

Yes there is a possibility of this risk ..
But it is alarming today that wordpress hacked so often :(
 
Back
Top