基于Discuzsecurity.inc.php代码的深入分析
2023-06-13 09:15:00 时间
代码如下所示:
<?php
/*
[Discuz!](C)2001-2009ComsenzInc.
ThisisNOTafreeware,useissubjecttolicenseterms
$Id:security.inc.php166882008-11-1406:41:07Zcnteacher$
*/
//如果没有设定IN_DISCUZ,则访问出错
if(!defined("IN_DISCUZ")){
exit("AccessDenied");
}
//使用位移 $attackevasive来设定论坛防御级别,如果是1或者是4的话,1=cookie刷新限制,4=二次请求
//读取上次时间到当前存放cookies数组,并将现在时间放置cookies
//将$_DCOOKIE["lastrequest"]不断加密存放last访问时间到lastrequest_cookies
if($attackevasive&1||$attackevasive&4){
$_DCOOKIE["lastrequest"]=authcode($_DCOOKIE["lastrequest"],"DECODE");
dsetcookie("lastrequest",authcode($timestamp,"ENCODE"),$timestamp+816400,1,true);
}
//如果确认被攻击,则展示提示语1
if($attackevasive&1){
if($timestamp-$_DCOOKIE["lastrequest"]<1){
securitymessage("attachsave_1_subject","attachsave_1_message");
}
}
//如检查到HTTP_X_FORWARDED_FOR有以下参数,将提示使用代理
if(($attackevasive&2)&&($_SERVER["HTTP_X_FORWARDED_FOR"]||
$_SERVER["HTTP_VIA"]||$_SERVER["HTTP_PROXY_CONNECTION"]||
$_SERVER["HTTP_USER_AGENT_VIA"]||$_SERVER["HTTP_CACHE_INFO"]||
$_SERVER["HTTP_PROXY_CONNECTION"])){
securitymessage("attachsave_2_subject","attachsave_2_message",FALSE);
}
//如果在限定的时间内访问多次,将判断为二次请求
if($attackevasive&4){
if(empty($_DCOOKIE["lastrequest"])||$timestamp-$_DCOOKIE["lastrequest"]>300){
securitymessage("attachsave_4_subject","attachsave_4_message");
}
}
//如果需要回答问题,则判断为8
if($attackevasive&8){
list($questionkey,$questionanswer,$questiontime)=explode("|",authcode($_DCOOKIE["secqcode"],"DECODE"));
include_onceDISCUZ_ROOT."./forumdata/cache/cache_secqaa.php";
if(!$questionanswer||!$questiontime||$_DCACHE["secqaa"][$questionkey]["answer"]!=$questionanswer){
if(empty($_POST["secqsubmit"])||(!empty($_POST["secqsubmit"])&&$_DCACHE["secqaa"][$questionkey]["answer"]!=md5($_POST["answer"]))){
$questionkey=array_rand($_DCACHE["secqaa"]);
dsetcookie("secqcode",authcode($questionkey."||".$timestamp,"ENCODE"),$timestamp+816400,1,true);
securitymessage($_DCACHE["secqaa"][$questionkey]["question"],"<inputtype="text"name="answer"size="8"maxlength="150"/><inputclass="button"type="submit"name="secqsubmit"value="Submit"/>",FALSE,TRUE);
}else{
dsetcookie("secqcode",authcode($questionkey."|".$_DCACHE["secqaa"][$questionkey]["answer"]."|".$timestamp,"ENCODE"),$timestamp+816400,1,true);
}
}
}
/**
*输出被攻击提示语言,如果是ajax,展示一??错误?樱如果是?求,?t展示错误?面
*@param$subject
*@param$message
*@param$reload
*@param$form
*@returnunknown_type
*/
functionsecuritymessage($subject,$message,$reload=TRUE,$form=FALSE){
$scuritylang=array(
"attachsave_1_subject"=>"频繁刷新限制",
"attachsave_1_message"=>"您访问本站速度过快或者刷新间隔时间小于两秒!请等待页面自动跳转...",
"attachsave_2_subject"=>"代理服务器访问限制",
"attachsave_2_message"=>"本站现在限制使用代理服务器访问,请去除您的代理设置,直接访问本站。",
"attachsave_4_subject"=>"页面重载开启",
"attachsave_4_message"=>"欢迎光临本站,页面正在重新载入,请稍候..."
);
$subject=$scuritylang[$subject]?$scuritylang[$subject]:$subject;
$message=$scuritylang[$message]?$scuritylang[$message]:$message;
if($_GET["inajax"]){
ajaxshowheader();
echo"<divid="attackevasive_1"class="popupmenu_option"><bstyle="font-size:16px">".$subject."</b><br/><br/>".$message."</div>";
ajaxshowfooter();
}else{
echo"<html>";
echo"<head>";
echo"<title>".$subject."</title>";
echo"</head>";
echo"<bodybgcolor="#FFFFFF">";
if($reload){
echo"<scriptlanguage="JavaScript">";
echo"functionreload(){";
echo"document.location.reload();";
echo"}";
echo"setTimeout("reload()",1001);";
echo"</script>";
}
if($form){
echo"<formaction="".$_SERVER["PHP_SELF"].""method="POST">";
}
echo"<tablecellpadding="0"cellspacing="0"border="0"width="700"align="center"height="85%">";
echo" <tralign="center"valign="middle">";
echo" <td>";
echo" <tablecellpadding="10"cellspacing="0"border="0"width="80%"align="center"style="font-family:Verdana,Tahoma;color:#666666;font-size:11px">";
echo" <tr>";
echo" <tdvalign="middle"align="center"bgcolor="#EBEBEB">";
echo" <br/><br/><bstyle="font-size:16px">".$subject."</b><br/><br/>";
echo$message;
echo" <br/><br/>";
echo" </td>";
echo" </tr>";
echo" </table>";
echo" </td>";
echo" </tr>";
echo"</table>";
if($form){
echo"</form>";
}
echo"</body>";
echo"</html>";
}
exit();
}
functionajaxshowheader(){
global$charset,$inajax;
ob_end_clean();
@header("Expires:-1");
@header("Cache-Control:no-store,private,post-check=0,pre-check=0,max-age=0",FALSE);
@header("Pragma:no-cache");
header("Content-type:application/xml");
echo"<?xmlversion=/"1.0/"encoding=/"$charset/"?>/n<root><![CDATA[";
}
functionajaxshowfooter(){
echo"]]></root>";
}
?>
相关文章
- php getrealpath,PHP SplFileInfo getRealPath()用法及代码示例「建议收藏」
- 技术实现的网络系统PHP和MySQL结合:搭建网络系统的利器.(基于php和mysql)
- PHP 操作 Redis:实现强大的数据存储 (php操作redis)
- Linux环境下,如何高效、简单地编写PHP代码(linux下写php)
- PHP操作MSSQL——实现高效读写(php读写mssql)
- 基于 PHP 和 MSSQL 的连接类开发实战(php mssql连接类)
- PHP与MSSQL的脚本技术编写更快捷的网站程序(php mssql 脚本)
- 缓存技术的实践基于 Redis 与 PHP 的实现(标签 redis php)
- 基于Redis和PHP技术的投票系统优化(投票 redis php)
- 使用PHP获取网络文件的实现代码
- PHP反向排序和随机排序代码
- 在PHP中实现Javascript的escape()函数代码
- php小型企业库存管理系统的设计与实现代码
- PHP中检查或过滤IP地址的实现代码
- PHP删除数组中的特定元素的代码
- PHP数组循环操作详细介绍附实例代码
- php在windowiis的莫名问题的测试方法
- PHP获取当前日期所在星期(月份)的开始日期与结束日期(实现代码)
- Ajax+PHP快速上手及简单应用说明
- javascript中直接写php代码的方法
- php中mysql连接和基本操作代码(快速测试使用,简单方便)
- PHP使用header()输出图片缓存实例
- 编译PHP报错configureerrorCannotfindlibmysqlclientunderusr的解决方法
- PHP基于php_imagick_st-Q8.dll实现JPG合成GIF图片的方法