Recently I had a very sobering experience that demonstrated just how serious the threat of hacked WordPress sites is. I discovered hidden link injections in some posts on a few of my old sites. These are sites that I no longer actively maintain, they were kind of neglected, and haven’t been updated in a while.
The hack inserted links to drug sites (the viagra and cialis bunch) using “display: none” attribute to hide them from the page. I think Google disregards these hidden type of links, but having them can penalize your site nevertheless.
Creating a Solution
Having assessed the situation, I decided I needed a code snippet that I can run on these sites to find all suspicious posts and later clean them.
I came up with the snippet below. It has two modes, preview and update. In the preview mode (on by default) it will only list suspicious posts which is useful for testing as you can manually inspect the posts to see if they are indeed infected. When you change $preview_only to 0 you activate the update mode where it will also attempt to clean the posts (effectively replacing the link with blank).
The snippet is currently set to look for “display: none” pattern which is commonly used to hide links.
// By default only preview infected posts. Change to 0 to clean posts $preview_only = 1; // This is the pattern to search and replace with blank $pattern = '|author
20 responses
Hey Vladimir,
Thank you for adding this to the code snippets! I had to upgrade to the professional to use it, but I think it’s worth the investment and will help save me some time.
~Brett
We will be able to use the code above without using ManageWP? If yes, how?
Thanks
The Sucuri Scanner plugin and online service is a great tool to use.
What is this ManageWP you speak of. I have several sites that have had this problem and I have been doing complete re-installs to try and remedy this!
Sorry for sounding like such a noob but a tool like this would help me tremendously.
Hi!
This is great! Thx (I noticed my DB grew primo this yesr to 2x the size (Could be the new theme with a ton of features?
But to make sure I wanted to check with this snippet!
But my Managewp plan is not BIG enuf (PRO).Is it possible to install “Code Snippets” by Shea Bunge?
Copy in this snippet as is (without PHP tags)
Activate it and just go about… The snippet will be running
But nothing shows?
( I dis change the preview to 0 )??
After some minutes my DB is still the same size? So if this worked… I’m clean?Best regards
Peter
Hi, I tried it out on a test WP domain which had the default Twenty Twelve. It displayed Zero Infected files. So, after removing the code from the functions.php file, it gives an error which says “Cannot modify header”. Luckily this was a test site. So, how to remove the code safely? Would like to know. Thanks.
Hello,
Your product looks great! To clarify, the Sucuri integration requires a separate account and payments to Sucuri correct?
Thank you,
MarkHi
I am very frustrate with attack.. i have many wordpress sites around 49 and everyday one or more site is being attached by this attack but i have to solve this my going to phpmyadmin of each site then by running below set of query to database
SELECT * FROM wp_posts WHERE post_content LIKE ‘%
then remove one by one..
isn’t there any way i can use managewp to solve this issue ??
by the way above code is not working. I tried to run it showing 0 result for all sites 🙁
I tried all of this (including paying for the upgrade) but there are still all of the hidden links in my site – http://blog.localdemocracy.org.uk – it keeps saying that there are no suspicious posts but a quick look finds plenty of them.
The infection that I had has injected loads of hidden links but also lots of visible ones as well. Am I right in guessing that the only way of getting rid of those ones is to do it all manually?
THanks
PEMany Thanks..
I was looking for this solution. I have many bad links inserted in my post through pingbacks.. This is gonna really helpfulHello, I just signed up for managewp. I wanted to try the code snippet to clean up a site, but under tools – code snippet , there is no code? please can you help Regards,
I can’t get the snippet running. If I leave the PHP opening tag it gives the following error:
syntax error, unexpected ‘:’ occurred in wp-content/plugins/worker/functions.php(1150) : eval()’d code on line 8
Leave a Reply