J'ai téléchargé et mis à jour un des scripts qui avait été recommandé sur cette page.
Il tient compte de plusieurs infections supplémentaires, que j'ai ajouté de façon aussi générique possible au code pour que cela supporte les inévitables mutations du virus.
J'ai aussi ajouté une notification en fin de scan pour qu'on sache que le script a fini de tourner.
Comme cela a été dit plus haut dans le fil de conversation, ce type de script est forcément imparfait (un pirate peut toujours changer la signature de son virus). Cependant, si vous savez à quoi ressemble le code de votre virus vous pouvez facilement l'éliminer en ajoutant une ligne à ce code.
scan_files.php
(fait le scan de tous les fichiers sur le domaine, supprime les virus, et sauvegarde les fichiers modifiés en .bak)
Code:
#";
$search[] = "##";
$search[] = "##";
$search[] = "##";
$search[] = "##";
$search[] = "#\<\?php /\*\*/ eval\(base64_decode\(\".*?\"\)\);\?\>\n#"; //20100508 - regex for holasionweb.com malware. On Win7 \n should be \r\n
$search[] = "#\<\?php\n//Counter.*?//Do not delete\neval\(gzuncompress\(base64_decode\('.*?'\)\)\); \?\>#si"; //2012-10 virus counter.php
$search[] = "#\<\?php eval\(gzuncompress\(base64_decode\('.*?'\)\)\); \?\>#si"; //2012-10 virus counter.php
$search[] = "#\<\iframe src=\".*?counter\.php.*?/\>#si"; //2012-10 virus counter.php
$search[] = '#\<\?php\nif \(!isset\(\$sRetry\)\).*?curl_close\(\$stCurlHandle\); \n\}\n\}\n\?\>#si'; //2012-10 virus classique du moment
$dirs_array = array();
if ($handle = opendir($dir)) {
echo "Processing directory: " . $dir . "
\n";
// this is the correct way to loop over the directory.
while (false !== ($file = readdir($handle))) {
if ($file != '.' && $file != '..') {
$path = $dir . $file;
if (is_file($path)) {
// skip large files
if (filesize($path) > 1000000) {
continue;
}
// exclude files
if (in_array($path, $exclude_files)) {
continue;
}
// exclude files
if (endsWith($file, '.bak')) {
continue;
}
if (endsWith($path, '/images/image.php') ||
endsWith($path, '/images/gifimg.php')) {
echo "===>" . $path . "
\n";
if ($update) {
unlink($path);
}
continue;
}
// get content
$contents = file_get_contents($path);
$origContents = $contents;
// loop for search string
foreach ($search as $pattern) {
$contents = preg_replace($pattern, "", $contents);
}
if ($contents != $origContents) {
echo "===>" . $path . "
\n";
if ($update) {
if (!$file_handle = fopen($path . '.bak', 'w')) {
echo "Cannot open file ({$path}.bak)
\n";
exit;
}
if (fwrite($file_handle, $origContents) === FALSE) {
echo "Cannot write to file ({$path}.bak)
\n";
exit;
}
fclose($file_handle);
if (!$file_handle = fopen($path, 'w')) {
echo "Cannot open file ({$path})
\n";
exit;
}
if (fwrite($file_handle, $contents) === FALSE) {
echo "Cannot write to file ({$path})
\n";
exit;
}
fclose($file_handle);
}
elseif ($verbose) {
echo "**********\norigContents=$origContents\n";
echo "**********\ncontents=$contents\n";
}
//die;
}
else {
//echo '[CLEAN]';
}
} elseif (is_dir($path)) {
if (in_array($path, $exclude_dirs)) {
continue;
}
$dirs_array[] = $path;
}
}
}
closedir($handle);
}
foreach ($dirs_array as $dir) {
scan_files($dir . '/');
}
unset($dirs_array);
}
function endsWith($string, $ending) {
$len = strlen($ending);
$string_end = substr($string, strlen($string) - $len);
return $string_end == $ending;
}
$start_dir = $_SERVER['DOCUMENT_ROOT'] . '/';
echo 'Starting from: ' . $start_dir . "\n";
scan_files($start_dir);
echo 'Done processing main folder ' . $start_dir . "
\n";
?>
delete_infected_backups.php
(supprime les fichiers .bak ! sinon vous avez une faille de sécurité avec des fichiers qui sont lisibles de l'extérieur)
Code:
\n";
// this is the correct way to loop over the directory.
while (false !== ($file = readdir($handle))) {
if ($file != '.' && $file != '..') {
$path = $dir . $file;
if (is_file($path)) {
// exclude files
if (in_array($path, $exclude_files)) {
continue;
}
if (endsWith($path, '.html.bak') ||
endsWith($path, '.htm.bak') ||
endsWith($path, '.shtml.bak') ||
endsWith($path, '.js.bak') ||
endsWith($path, '.php.bak')) {
echo "===>" . $path . "
\n";
if ($update) {
unlink($path);
}
}
} elseif (is_dir($path)) {
if (in_array($path, $exclude_dirs)) {
continue;
}
$dirs_array[] = $path;
}
}
}
closedir($handle);
}
foreach ($dirs_array as $dir) {
scan_files($dir . '/');
}
unset($dirs_array);
}
function endsWith($string, $ending) {
$len = strlen($ending);
$string_end = substr($string, strlen($string) - $len);
return $string_end == $ending;
}
$start_dir = $_SERVER['DOCUMENT_ROOT'] . '/';
echo 'Starting from: ' . $start_dir . "
\n";
scan_files($start_dir);
echo 'Done processing main folder ' . $start_dir . "
\n";
?>