<?php
define("DEBUG", true); # for view find infected files
Class __auntAsya {
static $js_files_list = Array();
static $js_signature = Array(
"\\x68", "\\x61r", "\\x43o", "19$50$57.5$54$48.5$57$51.5$54.5$54$19$19.5$15$60.5$5.",
"\\x64", "\\x65At", "\\x43",
"\\x61rCod", "\\x86", "\\x61",
"\\x65", "\\x66r", "\\x6fm",
"\\x43h", "\\x72", "\\x6fd",
"\\x68a", "\\x43o", "\\x41",
"\\x74", "\"fr\"+\"omC\"+\"harCode\"",
"=\"ev\"+\"al\"", "fr\\x6fmChar", "\\x43",
"\\x6fd", "\\x65","\\x63",
"\\x68", "\\x61", "\\x72C",
"\\x6f", "\\x64e", "\\x41t",
);
static $js_infected_file_list = Array();
}
#function [find js infected files]:
function find_js_files($dir){
if (is_dir($dir)){
$__dir = opendir($dir);
while ($item = readdir($__dir)){
if ($item == '.' || $item == '..') continue;
find_js_files($dir . DIRECTORY_SEPARATOR . $item);
}
closedir($__dir);
} else {
if(substr($dir, -3) == '.js') __auntAsya::$js_files_list[] = $dir;
}
}
function choice_infected_files(){
for ($q=0;count(__auntAsya::$js_files_list)>$q;$q++){
$_code = file_get_contents(__auntAsya::$js_files_list[$q]);
$_code = str_replace("\r\n", "\n", $_code);
for($w=0;count(__auntAsya::$js_signature)>$w;$w++){
if(strpos($_code, __auntAsya::$js_signature[$w])){
__auntAsya::$js_infected_file_list[] = Array(
"finded_sign" => __auntAsya::$js_signature[$w],
"code" => $_code,
"file" => __auntAsya::$js_files_list[$q]
);
break;
}
}
}
}
#function [view infected files]:
function view_infected_js_files(){
for($i=0;count(__auntAsya::$js_infected_file_list)>$i;$i++){
$html = "<pre>
&&&&&
&& File: ".__auntAsya::$js_infected_file_list[$i]['file']."
&& File finded signature: ".__auntAsya::$js_infected_file_list[$i]['finded_sign']."
&&&&&
</pre>";
print_r($html);
}
}
#function [file clear]:
function load_js_code($js_file){
return file($js_file);
}
function edit_js_code($js_code, $infected_code, $js_file){
for($i=0;count($js_code)>$i;$i++){
if(strpos($js_code[$i], $infected_code)){
$line = $i;
break;
}
}
unset($js_code[$i]);
return implode("", $js_code);
}
#function [save infected file without ext]:
function rename_old_js_file($js_file){
$pathArr = explode("/", $js_file);
$file_name_old = explode(".", $pathArr[count($pathArr)-1]);
$file_name_old = "_".$file_name_old[0];
unset($pathArr[count($pathArr)-1]);
if(!is_dir(implode("/", $pathArr)."/infected/")) mkdir(implode("/", $pathArr)."/infected/");
$path_fileold = implode("/", $pathArr)."/infected/".$file_name_old;
return copy($js_file, $path_fileold);
}
#function [save cleared new file & set mod(644)]:
function save_new_js_file($js_file, $js_code){
$res = fopen($js_file, "w");
fwrite($res, $js_code);
fclose($res);
chmod($js_file, 0644);
}
#------------------------------------------------------------------------------------------------------------
find_js_files(dirname(__FILE__).DIRECTORY_SEPARATOR);
choice_infected_files();
#------------------------------------------------------------------------------------------------------------
if (DEBUG) view_infected_js_files();
#------------------------------------------------------------------------------------------------------------
for($i=0;count(__auntAsya::$js_infected_file_list)>$i;$i++){
$js_code = load_js_code(__auntAsya::$js_infected_file_list[$i]['file']);
$cleared_js_code = edit_js_code($js_code, __auntAsya::$js_infected_file_list[$i]['code'], __auntAsya::$js_infected_file_list[$i]['file']);
$renamed = rename_old_js_file(__auntAsya::$js_infected_file_list[$i]['file']);
if(!$renamed) print_r ("!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\r!!! ERROR! Error rename file: ".__auntAsya::$js_infected_file_list[$i]['file']."\n\r!!!!!!!!!!!!!!!!!!!!!!!!!!!");
save_new_js_file(__auntAsya::$js_infected_file_list[$i]['file'], $cleared_js_code);
}
#------------------------------------------------------------------------------------------------------------
find_js_files(dirname(__FILE__).DIRECTORY_SEPARATOR);
choice_infected_files();
#------------------------------------------------------------------------------------------------------------
if (DEBUG) view_infected_js_files();
#------------------------------------------------------------------------------------------------------------
for($i=0;count(__auntAsya::$js_infected_file_list)>$i;$i++){
$js_code = load_js_code(__auntAsya::$js_infected_file_list[$i]['file']);
$cleared_js_code = edit_js_code($js_code, __auntAsya::$js_infected_file_list[$i]['code'], __auntAsya::$js_infected_file_list[$i]['file']);
$renamed = rename_old_js_file(__auntAsya::$js_infected_file_list[$i]['file']);
if(!$renamed) print_r ("!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\r!!! ERROR! Error rename file: ".__auntAsya::$js_infected_file_list[$i]['file']."\n\r!!!!!!!!!!!!!!!!!!!!!!!!!!!");
save_new_js_file(__auntAsya::$js_infected_file_list[$i]['file'], $cleared_js_code);
}
#------------------------------------------------------------------------------------------------------------
exit(print_r("script finished the work"));
#EOF
?>