找回密码
 新建账号

Discuz X 3.5 您当前的访问请求当中含有非法字符,已经被系统拒绝

[复制链接]
php 发表于 2022/12/28 11:16 | 显示全部楼层 |阅读模式
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 行
  1. private function _xss_check() {

  2.                 static $check = array('"', '>', '<', '\'', '(', ')', 'CONTENT-TRANSFER-ENCODING');

  3.                 if(isset($_GET['formhash']) && $_GET['formhash'] !== formhash()) {
  4.                         if(defined('CURMODULE') && constant('CURMODULE') == 'logging' && isset($_GET['action']) && $_GET['action'] == 'logout') {
  5.                                 header("HTTP/1.1 302 Found");
  6.                                 header("Location: index.php");
  7.                                 exit();
  8.                         } else {
  9.                                 system_error('request_tainting');
  10.                         }
  11.                 }

  12.                 if($_SERVER['REQUEST_METHOD'] == 'GET' ) {
  13.                         $temp = $_SERVER['REQUEST_URI'];
  14.                 } elseif(empty ($_GET['formhash'])) {
  15.                         $temp = $_SERVER['REQUEST_URI'].http_build_query($_POST);
  16.                 } else {
  17.                         $temp = '';
  18.                 }

  19.                 if(!empty($temp)) {
  20.                         $temp = strtoupper(urldecode(urldecode($temp)));
  21.                         foreach ($check as $str) {
  22.                                 if(strpos($temp, $str) !== false) {
  23.                                         system_error('request_tainting');
  24.                                 }
  25.                         }
  26.                 }

  27.                 return true;
  28.         }
复制代码
修改为以下代码,当遇到非法访问时直接跳转到网站首页,而不是把错误信息暴露出来。
  1. private function _xss_check() {
  2.                 global $_G;
  3.                 static $check = array('"', '>', '<', '\'', '(', ')', 'CONTENT-TRANSFER-ENCODING');
  4.                 $isSecure = true;

  5.                 if(isset($_GET['formhash']) && $_GET['formhash'] !== formhash()) {
  6.                         $isSecure = false;
  7.                 }

  8.                 if($_SERVER['REQUEST_METHOD'] == 'GET' ) {
  9.                         $temp = $_SERVER['REQUEST_URI'];
  10.                 } elseif(empty ($_GET['formhash'])) {
  11.                         $temp = $_SERVER['REQUEST_URI'].http_build_query($_POST);
  12.                 } else {
  13.                         $temp = '';
  14.                 }

  15.                 if(!empty($temp)) {
  16.                         $temp = strtoupper(urldecode(urldecode($temp)));
  17.                         foreach ($check as $str) {
  18.                                 if(strpos($temp, $str) !== false) {
  19.                                         $isSecure = false;
  20.                                         $break;
  21.                                 }
  22.                         }
  23.                 }
  24.                
  25.                 if(!$isSecure){
  26.                         header('location: ' . $_G['siteurl']);
  27.                         exit;
  28.                 }

  29.                 return true;
  30.         }
复制代码

点评

好  发表于 2022/12/28 19:30

手机版|轻松E站

GMT+8, 2024/4/19 13:03

快速回复 返回顶部 返回列表