黑客通常會根據已知的漏洞來發動攻擊,而對mysql的版本號進行加固處理,可以使攻擊者無法準確瞭解數據庫系統的弱點,增加攻擊難度,防止黑客利用已知的漏洞攻擊系統。
1.查看mysql版本號的兩種方式
1.1外部探測
使用telnet命令:
[root@upm-bj-bigdata-host-1 ~]# telnet XX.XX.XXX.XX 3306 Trying XX.XX.XXX.XX... Connected to XX.XX.XXX.XX. Escape character is '^]'. J 5.7.25 f dr0..!2UR *zsZo%Imysql_native_passwordConnection closed by foreign host. |
使用nmap命令:
[root@upm-bj-bigdata-host-1 ~]# nmap -T4 -sC -sV -p 3306 XX.XX.XXX.XX Starting Nmap 6.40 ( http://nmap.org ) at 2024-02-21 14:43 CST Nmap scan report for XX.XX.XXX.XX Host is up (0.00014s latency). PORT STATE SERVICE VERSION 3306/tcp open mysql MySQL 5.7.25 | mysql-info: Protocol: 10 | Version: 5.7.25 | Thread ID: 13 | Some Capabilities: Long Passwords, Connect with DB, Compress, ODBC, Transactions, Secure Connection | Status: Autocommit |_Salt: s\x14rN B?m Service detection performed. Please report any incorrect results at http://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in 2.15 seconds |
1.2.在數據庫服務器上查看版本號
# 無需登錄數據庫查看 [root@upm-bj-bigdata-host-3 ~] # mysql -V mysql Ver 14.14 Distrib 5.7.25 , for linux-glibc2.12 (x86_64) using EditLine wrapper # 登錄數據庫查看 [root@upm-bj-bigdata-host-3 ~] # mysql -hxx.xx.xxx.xx -P3306 -uxx -pxx mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 14 Server version: 5.7.25 MySQL Community Server (GPL) Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> select version(); +-----------+ | version() | +-----------+ | 5.7.25 | +-----------+ 1 row in set (0.00 sec) |
2.MySql版本號處理方式
2.1.只想對外部探測隱藏mysql真實版本信息,只需修改mysqld二進制文件:
# 先找到 mysqld 二進制文件,然後備份 [root@upm-bj-bigdata-host-3 ~] # whereis mysqld mysqld: /usr/local/mysql/bin/mysqld [root@upm-bj-bigdata-host-3 ~] # cp /usr/local/mysql/bin/mysqld /usr/local/mysql/bin/mysqld.bak # 使用 vi 命令,同時在命令編輯器中使用 “/” 命令查找 “5.7.25” 然後回車,找到版本號, “i” 開啓插入模式,將版本修改成預期版本號,然後退出編輯模式保存( “esc”->":wq" ) [root@upm-bj-bigdata-host-3 ~] # vi /usr/local/mysql/bin/mysqld # 修改完成之後重啓數據庫 , 在進行外部探測發現顯示的已經是修改後的版本號 [root@upm-bj-bigdata-host-3 ~] # /etc/init.d/mysqld restart |
2.2.需要隱藏數據庫服務器上可以查詢到的版本信息,還需修改mysql文件:
# 先找到 mysql 二進制文件,然後備份 [root@upm-bj-bigdata-host-3 ~] # whereis mysql mysql: /usr/lib64/mysql /usr/local/mysql /usr/local/mysql/bin/mysql [root@upm-bj-bigdata-host-3 ~] # cp /usr/local/mysql/bin/mysql /usr/local/mysql/bin/mysql.bak # 使用 vi 命令,同時在命令編輯器中使用 “/” 命令查找 “5.7.25” 然後回車,找到版本號, “i” 開啓插入模式,將版本修改成預期版本號,然後退出編輯模式保存( “esc”->":wq" ) [root@upm-bj-bigdata-host-3 ~] # vi /usr/local/mysql/bin/mysql # 修改完成之後重啓數據庫 , 在進行數據庫版本號查詢時已經是修改後的版本號 [root@upm-bj-bigdata-host-3 ~] # /etc/init.d/mysqld restart [root@upm-bj-bigdata-host-3 ~] # mysql -V mysql Ver 14.14 Distrib 5.7.44 , for linux-glibc2.12 (x86_64) using EditLine wrapper |
注意:
- mysql和mysqld二進制文件中的版本號不能刪減或者修改其他信息,否則會導致服務不能啓動,所以在修改前一定要備份。
- 可以根據想要驗證漏洞的版本來修改,比如想要驗證升級到5.7.44版本漏洞掃出的情況,則可將版本號修改爲5.7.44。
- 經過5.7.25版本的測試,版本號修改爲5.7.44 或者 8.0.36 數據庫服務均可以正常啓動,且系統運行正常。
參考:https://www.php.cn/faq/500881.html