select version();" command; 2. Start the MySQL service and add a firewall policy; 3. Back up the file "mysqld.bak"; 4. Open the "/usr/sbin/mysqld" file and replace the version information in it."/> select version();" command; 2. Start the MySQL service and add a firewall policy; 3. Back up the file "mysqld.bak"; 4. Open the "/usr/sbin/mysqld" file and replace the version information in it.">

Home  >  Article  >  Database  >  How to hide mysql version

How to hide mysql version

藏色散人
藏色散人Original
2023-02-14 10:08:473732browse

Methods to hide the mysql version: 1. Check the current mysql version through the "mysql -uroot -p> select version();" command; 2. Start the MySQL service and add a firewall policy; 3. Back up the file "mysqld .bak"; 4. Open the "/usr/sbin/mysqld" file and replace the version information in it.

How to hide mysql version

## The operating environment of this tutorial: CentOS 7.6 system, MySQL5. 7 version, Dell G3 computer.

Hide MySQL/MariaDB real version information

In the project, Party A conducted a security scan on the server and found that there were many MySQL low version vulnerabilities and required them to be repaired. However, considering the impact on the business, it is inconvenient to directly upgrade the current version, and our business is deployed in an intranet environment and has network access restrictions, so the actual security risks are relatively small. Here we try to find other ways to circumvent it, that is, modify the MySQL version number and hide its true version information.

The test process is recorded as follows,
Risk operations, for reference only.

Detect MySQL/MariaDB version information

There are many ways to check the current version, the common ones are:

    Execute on the server
  • mysql -V
  • Log in to mysql and use sql statements to query
mysql -uroot -p> select version();
If you do not have login permission, you can also use telnet or nmap tools to perform detection scans and obtain mysql Version information:

    telnet
telnet [host] [port]
    nmap
nmap -T4 -sC -sV -p [port] [ip]

Hide MySQL real version information

Test environment

Serial numberNameVersionRemarks 1Linux operating systemCentOS 7.6IP: 192.168.64.1472MySQL database5.7.22rpm installation

安装过程

  1. 下载安装 rpm 包
yum -y install wget telnet nmap net-toolswget -P /opt/mysql https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.22-1.el7.x86_64.rpm-bundle.tartar -xf /opt/mysql/mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar -C /opt/mysqlcd /opt/mysqlls -lh /opt/mysql/
yum -y remove mariadb*
yum -y install \
  mysql-community-common-5.7.22-1.el7.x86_64.rpm \
  mysql-community-libs-5.7.22-1.el7.x86_64.rpm \
  mysql-community-client-5.7.22-1.el7.x86_64.rpm \
  mysql-community-server-5.7.22-1.el7.x86_64.rpm

How to hide mysql version
How to hide mysql version
How to hide mysql version
2. 开启 MySQL 服务,添加防火墙策略

systemctl start mysqld && systemctl status mysqld
firewall-cmd --permanent --add-port=3306/tcp
firewall-cmd --reload
firewall-cmd --list-all

How to hide mysql version
3. 设置密码

passwd=`grep 'password' /var/log/mysqld.log|awk '{print $NF}'`mysqladmin -u root -p$passwd password Aa123456.

How to hide mysql version
4. 设置远程连接

mysql -uroot -pAa123456.
mysql> use mysql;mysql> select user,host from user;mysql> update user set host='%' where user='root';mysql> flush privileges;mysql> select user,host from user;

How to hide mysql version
5. 查看当前版本

mysql> select version();mysql> \q
mysql -V

How to hide mysql version

版本信息探测

telnet 192.168.64.147 3306
nmap -T4 -sC -sV -p 3306 192.168.64.147

How to hide mysql version

修改版本信息

  1. 备份文件
cp /usr/bin/mysql /usr/bin/mysql.bakcp /usr/sbin/mysqld /usr/sbin/mysqld.bak

How to hide mysql version
2. 编辑二进制文件,替换其中的版本信息
如果只想对外部探测 MySQL 的真实版本信息进行隐藏,只需改 /usr/sbin/mysqld 文件。
❗️❗️❗️注意:版本号不可为空或删减其他信息,否则可能导致服务无法启用!

vi /usr/bin/mysql# 搜索关键字“Linux”快速定位,修改版本号,建议改为官网最新的稳定版本^@fwrite^@\0^@\t^@\n^@\\^@ERROR^@ %d (%s)^@ at line %lu^@ in file: '%s'^@ERROR %d (%s): ^@ERROR %d: ^@ERROR: ^@UNKNOWN USER^@MysqlClient^@LOGNAME^@LOGIN^@SUDO_USER^@Linux^@5.7.22^@x86_64^@Show warnings enabled.^@Show warnings disabled.^@Aborted^@Bye^@Writing history-file %s# 参考案例:^@fwrite^@\0^@\t^@\n^@\\^@ERROR^@ %d (%s)^@ at line %lu^@ in file: '%s'^@ERROR %d (%s): ^@ERROR %d: ^@ERROR: ^@UNKNOWN USER^@MysqlClient^@LOGNAME^@LOGIN^@SUDO_USER^@Linux^@5.7.37^@x86_64^@Show warnings enabled.^@Show warnings disabled.^@Aborted^@Bye^@Writing history-file %s

How to hide mysql version
How to hide mysql version
How to hide mysql version

vi /usr/sbin/mysqld
# 搜索关键字“--language”快速定位,修改版本号,建议改为官网最新的稳定版本
H^P1öéz¬,ÿ1Òëõ^@^@Hì^HHÄ^HÃ^@^@^@^@^@^@^@^@^@^@^@^A^@^B^@^@^@^@^@^@^@^@^@^@^@^@^@%s: %s^@MYSQL_AUDIT_GENERAL_ERROR^@OFF^@BOTH^@NO_AUTO_CLEAR^@NO_INTERNAL_LOOKUP^@Unknown^@tcp^@MYSQL_TCP_PORT^@/var/lib/mysql/mysql.sock^@MYSQL_UNIX_PORT^@Unable to delete pid file: %s^@%.3f^@.lower-test^@.LOWER-TEST^@Can't create test file %s^@Shutting down slave threads^@'--lc-messages-dir'^@--language/-l^@--binlog_max_flush_queue_time^@5.7.22^@Linux^@%s  Ver %s for %s on %s (%s)

# 参考案例:
H^P1öéz¬,ÿ1Òëõ^@^@Hì^HHÄ^HÃ^@^@^@^@^@^@^@^@^@^@^@^A^@^B^@^@^@^@^@^@^@^@^@^@^@^@^@%s: %s^@MYSQL_AUDIT_GENERAL_ERROR^@OFF^@BOTH^@NO_AUTO_CLEAR^@NO_INTERNAL_LOOKUP^@Unknown^@tcp^@MYSQL_TCP_PORT^@/var/lib/mysql/mysql.sock^@MYSQL_UNIX_PORT^@Unable to delete pid file: %s^@%.3f^@.lower-test^@.LOWER-TEST^@Can't create test file %s^@Shutting down slave threads^@'--lc-messages-dir'^@--language/-l^@--binlog_max_flush_queue_time^@5.7.37^@Linux^@%s  Ver %s for %s on %s (%s)

How to hide mysql version
How to hide mysql version
How to hide mysql version
3. 重启服务

systemctl restart mysqld
systemctl status mysqldnetstat -nplt |grep mysqld

How to hide mysql version
4. 确认版本

mysql -V
mysql -h 192.168.64.147 -uroot -pAa123456.
mysql> select version();mysql> \q

How to hide mysql version
5. 其他业务相关的测试

版本信息复测

telnet 192.168.64.147 3306
nmap -T4 -sC -sV -p 3306 192.168.64.147

How to hide mysql version

隐藏MariaDB真实版本信息

测试环境

序号 名称 版本 备注
1 Linux操作系统 CentOS 7.6 IP:192.168.64.147
2 MariaDB数据库 5.5.68 rpm安装

安装过程

  1. yum安装
yum -y install mariadb-server telnet nmap net-tools

How to hide mysql version
2. 开启 MySQL 服务,添加防火墙策略

systemctl start mariadb && systemctl status mariadb
firewall-cmd --permanent --add-port=3306/tcp
firewall-cmd --reload
firewall-cmd --list-all

How to hide mysql version
3. 设置密码和远程连接

mysqladmin -u root password "Aa123456."mysql -uroot -pAa123456.
MariaDB [(none)]> use mysql;MariaDB [mysql]> select user,host from user;MariaDB [mysql]> update user set host='%' where user='root';MariaDB [mysql]> flush privileges;MariaDB [mysql]> select user,host from user;

How to hide mysql version
How to hide mysql version
4. 查看当前版本

MariaDB [mysql]> select version();MariaDB [mysql]> \q
mysql -V

How to hide mysql version

版本信息探测

telnet 192.168.64.147 3306
nmap -T4 -sC -sV -p 3306 192.168.64.147

How to hide mysql version

修改版本信息

  1. 备份文件
cp /usr/bin/mysql /usr/bin/mysql.bakcp /usr/libexec/mysqld /usr/libexec/mysqld.bak

How to hide mysql version
2. 编辑二进制文件,替换其中的版本信息
如果只想对外部探测 MariaDB 的真实版本信息进行隐藏,只需改 /usr/libexec/mysqld 文件。
❗️❗️❗️注意:版本号不可为空或删减其他信息,否则可能导致服务无法启用!

vi /usr/bin/mysql# 搜索关键字“-MariaDB”快速定位,修改版本号,建议改为官网最新的稳定版本^@KILL %s%lu^@ERROR^@ at line %lu^@ in file: '%s'^@ERROR %d (%s)^@ERROR %d^@Linux^@5.5.68-MariaDB^@readline^@x86_64^@vi^@EDITOR^@VISUAL^@Command '%.40s' failed^@Show warnings disabled.^@Show warnings enabled.^@Usage: \! shell-command^@Charset changed^@Charset is not found^@show databases^@show tables^@%.64s.%.64s^@*** NONE ***^@Connection id:    %lu^@Current database: %.128s# 参考案例:^@KILL %s%lu^@ERROR^@ at line %lu^@ in file: '%s'^@ERROR %d (%s)^@ERROR %d^@Linux^@10.7.3-MariaDB^@readline^@x86_64^@vi^@EDITOR^@VISUAL^@Command '%.40s' failed^@Show warnings disabled.^@Show warnings enabled.^@Usage: \! shell-command^@Charset changed^@Charset is not found^@show databases^@show tables^@%.64s.%.64s^@*** NONE ***^@Connection id:    %lu^@Current database: %.128s

How to hide mysql version
How to hide mysql version
How to hide mysql version

vi /usr/libexec/mysqld 
# 同样通过搜索关键字“-MariaDB”快速定位,修改版本号,建议改为官网最新的稳定版本^@CLOSE_CONNECTION^@unauthenticated^@unconnected^@Error in accept^@5.5.68-MariaDB^@x86_64^@Linux^@%s  Ver %s for %s on %s (%s)# 参考案例:^@CLOSE_CONNECTION^@unauthenticated^@unconnected^@Error in accept^@10.7.3-MariaDB^@x86_64^@Linux^@%s  Ver %s for %s on %s (%s)

How to hide mysql version
How to hide mysql version
3. 重启服务

systemctl restart mariadb
systemctl status mariadbnetstat -nplt |grep mysqld

How to hide mysql version
4. 确认版本

mysql -V
mysql -h 192.168.64.147 -uroot -pAa123456.
MariaDB [(none)]> select version();MariaDB [(none)]> \q

How to hide mysql version
5. 其他业务相关的测试

版本信息复测

为防止探测过程中出现错误连接次数太多导致IP被锁定,建议先提高允许的max_connection_errors数量;
或使用清楚缓存的方法,把计数清理掉

mysql -h 127.0.0.1 -uroot
MariaDB [(none)]> show global variables like '%max_connect_errors%';MariaDB [(none)]> set global max_connect_errors=1000;MariaDB [(none)]> show global variables like '%max_connect_errors%';MariaDB [(none)]> flush hosts;MariaDB [(none)]> \q

How to hide mysql version
复测结果

telnet 192.168.64.147 3306
nmap -T4 -sC -sV -p 3306 192.168.64.147

How to hide mysql version

推荐学习:《MySQL视频教程

The above is the detailed content of How to hide mysql version. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn