设为首页收藏本站淘宝杂货铺

从F到0 - From F to 0

 找回密码
 注册已关闭
搜索
查看: 3564|回复: 6
收起左侧

Discuz! X 一个文件实现一键自动修改 Discuz! / UCenter 数据库表前缀 防止SQL注入

[复制链接]
发表于 2019-12-9 21:31:25 | 显示全部楼层 |阅读模式
使用默认的前缀《pre_》存在较大的安全隐患,修改后可防止大部分SQL注入攻击。
数据库表前缀修改后结果展示:
1.png
论坛根目录新建一个 任意文件名.php 粘贴以下代码:
  1. <?php
  2. require './source/class/class_core.php';
  3. C::app()->init();
  4. set_time_limit(0);
  5. ignore_user_abort(1);
  6. if($_G['uid'] != 1){
  7.         exit('Access Denied');
  8. }
  9.         $config_file = array(
  10.                 './config/config_global.php',
  11.                 './config/config_ucenter.php',
  12.                 './uc_server/data/config.inc.php',
  13.         );

  14.         $old_table = DB::table(null);
  15.         $old_table_len = strlen($old_table);
  16.         $new_table = 'pre_'.strtolower(random(12)).'_';


  17.         foreach($config_file as $file_name){
  18.                 if(!file_exists($file_name)){
  19.                         exit("File: $file_name Not Found.");
  20.                 }
  21.                 $data = file_get_contents($file_name);
  22.                 $data = str_replace($old_table,$new_table,$data);
  23.                 file_put_contents($file_name,$data);
  24.         }

  25.         foreach(DB::fetch_all('SHOW TABLES') as $old_table_name){
  26.                 $old_table_name = array_values($old_table_name)[0];
  27.                 if(substr($old_table_name,0,$old_table_len) != $old_table){
  28.                         continue;
  29.                 }
  30.                 $new_table_name = $new_table.substr($old_table_name,$old_table_len);
  31.                 DB::query("RENAME TABLE $old_table_name TO $new_table_name");
  32.         }

  33. exit('ok!!');
  34. ?>
复制代码

仅允许uid1运行,可在代码中修改。
运行本程序需要较长时间,如果服务器的 set_time_limit(0); 、ignore_user_abort(1); 函数不起作用,请勿使用。

相关帖子

您需要登录后才可以回帖 登录 | 注册已关闭

本版积分规则

QQ|手机版|Archiver|从F到0 ( 蒙ICP备17002595号-1 )
蒙公网安备15010402000325号

腾讯云安全认证

GMT+8, 2024-4-28 18:48 , Processed in 1.214069 second(s), 22 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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