Sunday, April 11, 2010

This site may harm your computer

SkyHi @ Sunday, April 11, 2010
Today the website of one of the clients was blacklisted by Google by containing malicious software that downloads and installs without user’s consent. Google displayed “This site may harm your computer” under website in the results page.
Analyzing site’s sources we found obfuscated JavaScript code inserted near body, html tags in .html, .php, .tpl files and a .htaccess file with following content:
RewriteEngine On
RewriteCond %{HTTP_REFERER} .*google.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} .*aol.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} .*msn.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} .*yahoo.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} .*yandex.*$ [NC,OR]^M
RewriteCond %{HTTP_REFERER} .*rambler.*$ [NC,OR]^M
RewriteCond %{HTTP_REFERER} .*ya.*$ [NC]
RewriteRule .* [R,L]
Hmm, visitors from search engines were redirected to This website is a scam that shows some JavaScript animation fulling the user with a message that his computer is infected and prompts him to download and install a fake AntiVirus.
Analyzing IP addresses from ftp logs we found connections from Russia and China that altered client’s website. Somehow they got user’s ftp password (it can be done in so many ways: weak password, traffic sniffing, virus, keylogger, trojan, …) and they altered website files.
You can use this simple Ruby script to analyze your ftp logs. By default it is configured for a Plesk server, and it will show suspicious lines (change IGNORE variables to fit your needs). You may need to install rubygems and geoip gem.
require 'rubygems'
require 'geoip'
require 'zlib'
# hide logs from these countries
# Example: RO US
# free geoip database is not 100% accurate
# we may need to ignore a few ip addresses
IGNORE_IP = %w{}
files = Dir.glob("/usr/local/psa/var/log/xferlog*")
geoip ='/var/lib/GeoIP/GeoIP.dat')
def ip2country(geoip, ip)
  country =[3]
ip_list = []
files.each do |filename|
  puts ""
  puts "Processing #{filename} ..." do |f|
    input = f
    input = if File.extname(filename) == ".gz"
    while line = input.gets do
      ip = line.split(/\s+/)[6]
      unless ip_list.include? ip
        country = ip2country(geoip, ip)
        unless IGNORE_COUNTRIES.include? country.upcase or IGNORE_IP.include? ip
          puts " [#{country} : #{ip}] => #{line}"
        ip_list << ip
Steps that needs to followed:
  1. Change FTP password
  2. Upload a clean copy from the backups of the website
  3. Submit the website in the Webmaster’s Tools for reconsideration
  4. Audit your company security: computers, firewalls, antiviruses, software, …
You may find useful diagnose tool from the Google (replace with your domain):