最近一段時(shí)間很多使用pbootcms建設(shè)的網(wǎng)站都遭遇到了掛馬的問(wèn)題,表現(xiàn)形式便是頁(yè)面增加了很多?id=123,?/?id=55662567.csv,?id=55674554.shtml 等等形態(tài)。當(dāng)我們查看后臺(tái)系統(tǒng)日志中的蜘蛛訪(fǎng)問(wèn)或者首頁(yè)上多了這些鏈接的時(shí)候,基本上就是被掛馬了,這個(gè)時(shí)候我們需要及時(shí)作出處理要不然就容易被百度降權(quán)甚至嚴(yán)重的時(shí)候會(huì)被關(guān)站。
備注:本次掛馬應(yīng)該是程序自動(dòng)掛馬,很多使用pbootcms的網(wǎng)站都在短時(shí)間范圍內(nèi)受到了攻擊。
處理步驟:
1)替換apps以及core文件,如果本地沒(méi)有備份保存,那么可以選擇升級(jí)到最近版本,目前官方也根據(jù)這個(gè)問(wèn)題進(jìn)行了更新處理.
2)修改robots.txt文件添加針對(duì)首頁(yè)問(wèn)題的拒絕訪(fǎng)問(wèn)規(guī)則
# Robots
Disallow: /admin/*
Disallow: /skin/
Disallow: /template/
Disallow: /static/*
Disallow: /api/*
Disallow: /?*
3) 修改源碼,在apps/home/controller/IndexController.php 文件中添加針對(duì)首頁(yè)帶參數(shù)問(wèn)題的處理。代碼大概在200行以后找到//一級(jí)目錄這里,在上方添加
if(strstr(URL,"?")){ _404('您訪(fǎng)問(wèn)的路徑錯(cuò)誤,請(qǐng)核對(duì)后重試!'); } |
如下:在這里的后方加上else流程,進(jìn)入主頁(yè)流程的操作,同時(shí)加上urlJump方法(或者升級(jí)到最新版本以后再進(jìn)行修改)
urlJump方法
//首頁(yè)跳轉(zhuǎn)并過(guò)濾注入字符 /* * @param $type url模式 * @param $isSecSiteDir 是否為二級(jí)目錄 boolean * */ private function urlJump($type, $isSecSiteDir){ $http = is_https() ? 'https://' : 'http://'; $matches1 = ''; switch ($type){ //普通模式 case 1: $preg1 = ''; if($isSecSiteDir === true){ if($_SERVER['REQUEST_URI'] == SITE_DIR . '/index.php'){ $preg1 = '/^/.*?/index.php/'; } elseif($_SERVER['REQUEST_URI'] == '/index.php'){ $preg1 = '/^/index.php/'; } } else { $preg1 = '/^/index.php/'; } preg_match($preg1,$_SERVER['REQUEST_URI'],$matches1); break; //偽靜態(tài) case 2: $preg2 = ''; if($isSecSiteDir === true){ if($_SERVER['REQUEST_URI'] == SITE_DIR . '/'){ $preg2 = '/^/.*/'; } elseif($_SERVER['REQUEST_URI'] == '/'){ $preg2 = '/^/$/'; } } else { $preg2 = '/^/.*/'; } preg_match($preg2,$_SERVER['REQUEST_URI'],$matches1); break; //兼容模式 case 3: $preg3 = ''; if($isSecSiteDir === true){ if(strpos($_SERVER['REQUEST_URI'], SITE_DIR) === 0){ $preg3 = '/(^/.*?/index.php)|(^/.*)/'; } elseif(strpos($_SERVER['REQUEST_URI'], '/') === 0){ $preg3 = '/(^/index.php)|(^/)/'; } } else { $preg3 = '/(^/index.php)|(^/)/'; } preg_match($preg3,$_SERVER['REQUEST_URI'],$matches1); break; } if($matches1[0]){ if($_SERVER['REQUEST_URI'] == $matches1[0]){ $this->getIndexPage(); } else { header("Location: " . $http . $_SERVER['HTTP_HOST'] . $matches1[0], true, 301); } } else { _404('您訪(fǎng)問(wèn)的頁(yè)面不存在,請(qǐng)核對(duì)后重試!'); } } |
通過(guò)以上三步基本上就可以杜絕本次批量被掛馬的問(wèn)題,后續(xù)就是要加強(qiáng)服務(wù)器上的安全驗(yàn)證的問(wèn)題了.
=======================分割線(xiàn)。