Discuz! System Error
您当前的访问请求当中含有非法字符,已经被系统拒绝
PHP Debug
[Line: 0024]home.php(discuz_application->init)
[Line: 0072]source/class/discuz/discuz_application.php(discuz_application->_init_misc)
[Line: 0602]source/class/discuz/discuz_application.php(discuz_application->_xss_check)
[Line: 0391]source/class/discuz/discuz_application.php(system_error)
[Line: 0023]source/function/function_core.php(discuz_error::system_error)
[Line: 0024]source/class/discuz/discuz_error.php(discuz_error::debug_backtrace)
www.51-n.com 已经将此出错信息详细记录, 由此给您带来的访问不便我们深感歉意
这是 Discuz! 对非法访问网站的检测,但这段代码设计不合理,容易暴露服务器信息,做适当的修改后更安全。
Discuz! 的检测逻辑是符合以下条件即为非法请求
- 如果 GET 参数有 formhash 字段并且和 formhash() 不同
- REQUEST_URI 或 POST 参数包含 ", >, <, ', (, ), CONTENT-TRANSFER-ENCODING 中的任意一个值
找到 source\class\discuz\discuz_application.php 第 363 行
- private function _xss_check() {
- static $check = array('"', '>', '<', '\'', '(', ')', 'CONTENT-TRANSFER-ENCODING');
- if(isset($_GET['formhash']) && $_GET['formhash'] !== formhash()) {
- if(defined('CURMODULE') && constant('CURMODULE') == 'logging' && isset($_GET['action']) && $_GET['action'] == 'logout') {
- header("HTTP/1.1 302 Found");
- header("Location: index.php");
- exit();
- } else {
- system_error('request_tainting');
- }
- }
- if($_SERVER['REQUEST_METHOD'] == 'GET' ) {
- $temp = $_SERVER['REQUEST_URI'];
- } elseif(empty ($_GET['formhash'])) {
- $temp = $_SERVER['REQUEST_URI'].http_build_query($_POST);
- } else {
- $temp = '';
- }
- if(!empty($temp)) {
- $temp = strtoupper(urldecode(urldecode($temp)));
- foreach ($check as $str) {
- if(strpos($temp, $str) !== false) {
- system_error('request_tainting');
- }
- }
- }
- return true;
- }
复制代码 修改为以下代码,当遇到非法访问时直接跳转到网站首页,而不是把错误信息暴露出来。
- private function _xss_check() {
- global $_G;
- static $check = array('"', '>', '<', '\'', '(', ')', 'CONTENT-TRANSFER-ENCODING');
- $isSecure = true;
- if(isset($_GET['formhash']) && $_GET['formhash'] !== formhash()) {
- $isSecure = false;
- }
- if($_SERVER['REQUEST_METHOD'] == 'GET' ) {
- $temp = $_SERVER['REQUEST_URI'];
- } elseif(empty ($_GET['formhash'])) {
- $temp = $_SERVER['REQUEST_URI'].http_build_query($_POST);
- } else {
- $temp = '';
- }
- if(!empty($temp)) {
- $temp = strtoupper(urldecode(urldecode($temp)));
- foreach ($check as $str) {
- if(strpos($temp, $str) !== false) {
- $isSecure = false;
- $break;
- }
- }
- }
-
- if(!$isSecure){
- header('location: ' . $_G['siteurl']);
- exit;
- }
- return true;
- }
复制代码 |
|