曹え 5811 发布于:2025-07-23 03:37:04
把下面代码替换根目录的 index.php
<?php // +---------------------------------------------------------------------- // | FrPHP { a friendly PHP Framework } // +---------------------------------------------------------------------- // | Copyright (c) 2018-2099 http://frphp.jizhicms.com All rights reserved. // +---------------------------------------------------------------------- // | Author: 如沐春 <2581047041@qq.com> // +---------------------------------------------------------------------- // | Date:2022/04/11 // +---------------------------------------------------------------------- /** * 检测输入参数中的非法字符以防止SQL注入 * 发现非法字符时停止程序运行并显示错误信息 */ function checkSqlInjection() { // 定义常见的SQL注入关键词和特殊字符 $illegalPatterns = [ '/\b(union|select|insert|update|delete|drop|alter|create|exec|xp_cmdshell)\b/i', '/[\'"\;$$\-\#\*]/', '/\b(and|or)\b\s*[\d=]+/i', '/\b(1=1|0=0)\b/i', '/\bwaitfor\b\s+delay/i', '/\bsleep\s*\(/i', '/\bbenchmark\s*\(/i' ]; // 检查GET参数 foreach ($_GET as $key => $value) { if (is_array($value)) { foreach ($value as $subValue) { checkValue($key, $subValue, $illegalPatterns); } } else { checkValue($key, $value, $illegalPatterns); } } // 检查POST参数 foreach ($_POST as $key => $value) { if (is_array($value)) { foreach ($value as $subValue) { checkValue($key, $subValue, $illegalPatterns); } } else { checkValue($key, $value, $illegalPatterns); } } } /** * 检查单个值是否包含非法字符 */ function checkValue($key, $value, $illegalPatterns) { foreach ($illegalPatterns as $pattern) { if (preg_match($pattern, $value)) { // 发现潜在SQL注入攻击,停止程序运行 header('HTTP/1.1 403 Forbidden'); die("检测到非法字符或潜在SQL注入攻击,参数: $key = " . htmlspecialchars($value, ENT_QUOTES, 'UTF-8')); } } } // 在脚本开始时调用检测函数 checkSqlInjection(); // 应用目录为当前目录 define('APP_PATH', __DIR__ . '/'); define('ADMIN_MODEL','admins'); // 加载框架文件 require(APP_PATH . 'frphp/fr.php'); // 就这么简单~
登录后可以留言提问!