|
使用默认的前缀《pre_》存在较大的安全隐患,修改后可防止大部分SQL注入攻击。
数据库表前缀修改后结果展示:
论坛根目录新建一个 任意文件名.php 粘贴以下代码:
- <?php
- require './source/class/class_core.php';
- C::app()->init();
- set_time_limit(0);
- ignore_user_abort(1);
- if($_G['uid'] != 1){
- exit('Access Denied');
- }
- $config_file = array(
- './config/config_global.php',
- './config/config_ucenter.php',
- './uc_server/data/config.inc.php',
- );
- $old_table = DB::table(null);
- $old_table_len = strlen($old_table);
- $new_table = 'pre_'.strtolower(random(12)).'_';
- foreach($config_file as $file_name){
- if(!file_exists($file_name)){
- exit("File: $file_name Not Found.");
- }
- $data = file_get_contents($file_name);
- $data = str_replace($old_table,$new_table,$data);
- file_put_contents($file_name,$data);
- }
- foreach(DB::fetch_all('SHOW TABLES') as $old_table_name){
- $old_table_name = array_values($old_table_name)[0];
- if(substr($old_table_name,0,$old_table_len) != $old_table){
- continue;
- }
- $new_table_name = $new_table.substr($old_table_name,$old_table_len);
- DB::query("RENAME TABLE $old_table_name TO $new_table_name");
- }
- exit('ok!!');
- ?>
复制代码
仅允许uid1运行,可在代码中修改。
运行本程序需要较长时间,如果服务器的 set_time_limit(0); 、ignore_user_abort(1); 函数不起作用,请勿使用。 |
|