一、问题由来

mysql在5.6.5上开始在命令行中直接填入用户密码会提示错误,例如:

$./mysql -h10.10.30.18 -uwoqutech -pwoqutech -ss -e 'select @@server_id'

Warning: Using a password on the command line interface can be insecure.

330618

如果你要写一个脚本调用mysql命令来获得server_id的值,这个Warning的信息绝对是你的噩梦。

提示这个安全原因本来无可厚非,但是坑爹的是,没有任何一个参数或者开关能关闭这个Warning。

2012年liu wei同学就提交了这个bug,到了2017年的今天,还是没有解决。期间有n多人开骂,其中Van Stokes骂的最经典:

How about this insane idea....

How about MySQL quits trying to save the world from itself and REMOVE THIS STUPID WARNING MESSAGE. It's NONE OF YOUR BUSINESS if I want to use a password on the command line or not. So quit worrying about it. Remove the warning. We don't need to be nannied to death by the likes of you.

翻译过来就是:

你们脑子秀逗了,赶紧把这个傻×报警信息清理掉,再不清理麻烦就大了!

骂归骂,也有很多人提供了对应的解决方案,甚至包括修改MySQL的汇编代码来解决。

二、人间大炮一级准备:脚本自己解决

最简单的,mysql自己不解决,我们脚本里面可以过滤。拿到这两行信息以后,通过grep -v或者各自程序语言去过滤掉这个错误信息。

但是每个脚本都需要有额外的逻辑来处理这个信息,也是大家非常不爽的原因。

Karl Nicoletti就很不爽:

Does the MySQL development team have ANY idea how many man-hours of work they have inflicted on DBAs and developers relying on command line input responses that DO NOT return the word "Warning" or "Error" in the case of successful execution???  I alone will be spending at least 100 hours to upgrade and test all our in-house maintenance, and installation scripts to work around this idiotic warning. Maybe, just MAYBE you could use the word "NOTE:" instead of "Warning:"??? Better yet, provide an option, --no-cmd-line-warning that would shut the damn thing off?

三、人间大炮二级准备:MYSQL_PWD,mysql_config_editor解决

还好,有一些其他的解决方案也可以解决这个问题。

mysql_config_editor

利用mysql_config_editor来保存用户名密码,避免输出Warning信息

mysql_config_editor set --login-path=woqutech --host=10.10.30.18 --user=woqutech --password

mysql --login-path=woqutech  -e "select @@server_id"

这种方式必须手工输入密码,在脚本里面用也非常坑爹。

MYSQL_PWD

通过设置MYSQL_PWD变量来避免输出Warning信息

$MYSQL_PWD='woqutech' ./mysql  -h10.10.30.18 -uwoqutech  -ss -e 'select @@server_id'

330618

这种方式相对接受度比较高。

四、人间大炮三级准备:源码解决

既然MySQL是开源的,那我们当然希望通过源码解决拉,

源码其实很简单

void print_cmdline_password_warning()

{

static my_bool password_warning_announced= FALSE;

if (!password_warning_announced)

{

fprintf(stderr, "Warning: Using a password on the command line "

"interface can be insecure.\n");

(void) fflush(stderr);

password_warning_announced= TRUE;

}

}

阿里的印风就提交了一个patch 供大家参考。

五、人间大炮发射:汇编解决

源码解决方案的问题在于需要维护自己的版本,每次MySQL新的版本发布都需要重新打patch,并重新编译。

还有什么其他的办法列,Andrew McGill和Perry Harrington提供了在汇编层面解决这个问题的办法!

5.1 删除汇编中Warning信息

Andrew McGill使用的是perl,解决方案如下

perl -p -i -e 's/(Warning: Using a password on the command line interface can be insecure..)/"\0"x(length($1))/es' /usr/local/mysql/bin/mysql

简单解释一下:

mysql程序编译出来就是一个汇编的代码

\0代表是空字符,"\0"x(length($1)表示多个空字符,不会打印任何字符

Andrew McGill利用perl将Warning: Using a password on the command line interface can be insecure.的信息都替换为空,也就不会打印Warning信息了。

5.2print_cmdline_password_warning函数逻辑修改

Perry Harrington提供了一种匪夷所思的汇编代码修改方式:

原版在测试环境下不可用:

printf '\x75' | dd of=./mysql bs=1 seek=$((16#$(objdump --disassemble -F mysql |grep password_warning|grep je|awk '{print $1}'|cut -d: -f1|sed -e 's/^.//g'))) count=1 conv=notrunc

可用版本:

printf '\xeb' | dd of=./mysql bs=1 seek=$((16#$(objdump --disassemble -F mysql |grep password_warning|grep jne|awk '{print $1}'|cut -d: -f1|sed -e 's/^.//g'))) count=1 conv=notrunc

这个需要解释一下

print_cmdline_password_warning函数中会判断password_warning_announced是否为FALSE,由于password_warning_announced是静态变量,再次进入这个函数将不会打印错误信息,函数代码如下:

/**

* This function should be called to print a warning message

* if password string is specified on the command line.

*/

void print_cmdline_password_warning()

{

static my_bool password_warning_announced= FALSE;

if (!password_warning_announced)

{

fprintf(stderr, "Warning: Using a password on the command line "

"interface can be insecure.\n");

(void) fflush(stderr);

password_warning_announced= TRUE;

}

}

汇编代码中只需要把判断password_warning_announced的逻辑修改成直接跳转,就可以不打印出来了。

怎么修改列,通过objdump 可以查看到print_cmdline_password_warning函数的逻辑如下:

000000000044d980 (File Offset: 0x4d980):

44d980:       55                      push   %rbp

44d981:       48 89 e5                mov    %rsp,%rbp

44d984:       53                      push   %rbx

44d985:       48 83 ec 08             sub    $0x8,%rsp

44d989:       80 3d e0 aa 59 00 00    cmpb   $0x0,0x59aae0(%rip)        # 9e8470 <_zz30print_cmdline_password_warninge26password_warning_announced> (File Of

fset: 0x5e8470)

44d990:       75 2f                   jne    44d9c1 (File Offset: 0x4d9c1)

44d992:       48 8b 1d 07 00 4c 00    mov    0x4c0007(%rip),%rbx        # 90d9a0 <_dynamic> (File Offset: 0x50d9a0)

44d999:       48 8d 3d 40 c7 08 00    lea    0x8c740(%rip),%rdi        # 4da0e0 (File Offset: 0xda0e0)

44d9a0:       ba 49 00 00 00          mov    $0x49,%edx

44d9a5:       be 01 00 00 00          mov    $0x1,%esi

44d9aa:       48 8b 0b                mov    (%rbx),%rcx

44d9ad:       e8 26 df fb ff          callq  40b8d8 (File Offset: 0xb8d8)

44d9b2:       48 8b 3b                mov    (%rbx),%rdi

44d9b5:       e8 ce e0 fb ff          callq  40ba88 (File Offset: 0xba88)

44d9ba:       c6 05 af aa 59 00 01    movb   $0x1,0x59aaaf(%rip)        # 9e8470 <_zz30print_cmdline_password_warninge26password_warning_announced> (File Offset: 0x5e8470)

44d9c1:       48 83 c4 08             add    $0x8,%rsp

44d9c5:       5b                      pop    %rbx

44d9c6:       c9                      leaveq

44d9c7:       c3                      retq

44d9c8:       0f 1f 84 00 00 00 00    nopl   0x0(%rax,%rax,1)

44d9cf:       00

我们看到44d990行,上一行比较了password_warning_announced的值,jne表示不等于就跳转到函数尾44d9c1(退出堆栈),我们把汇编指令修改成无论如何都跳转jmp不就解决了这个问题吗?

44d990:       75 2f                   jne    44d9c1 (File Offset: 0x4d9c1)

所以修改的策略就是把jne修改成jmp,对应的就是要把75修改为eb。汇编指令操作码可以查考csdn

75是jne

eb是jmp

所以最终的修改方式就是这么一个诡异的命令:

printf '\xeb' | dd of=./mysql bs=1 seek=$((16#$(objdump --disassemble -F mysql |grep password_warning|grep jne|awk '{print $1}'|cut -d: -f1|sed -e 's/^.//g'))) count=1 conv=notrunc

objdump –disassemble -F mysql |grep password_warning|grep jne|awk '{print $1}'|cut -d: -f1|sed -e 's/^.//g' 获得要修改的mysql汇编文件字节偏移位置

seek=$((16#$(objdump –disassemble -F mysql |grep password_warning|grep jne|awk '{print $1}'|cut -d: -f1|sed -e 's/^.//g'))) 获得16进制“要修改的mysql汇编文件字节偏移位置”

printf '\xeb' | dd of=./mysql bs=1 seek=$((16#$(objdump –disassemble -F mysql |grep password_warning|grep jne|awk '{print $1}'|cut -d: -f1|sed -e 's/^.//g'))) count=1 conv=notrunc 将mysql汇编文件中print_cmdline_password_warning函数中jne修改为jmp,直接跳转,不打印错误信息

七、总结

MySQL出于安全的考虑,建议大家不要在命令行中写password,但是只是在命令行中提示,并且还不能关闭,确实比较坑,我们要做一个企业级的产品也需要对每一个细节和功能考虑的更加仔细和细致,避免出现类似的问题。

虽然官方也不知道啥时候能解决这个Warning的问题,但是各路大神各出奇招来解决这个问题,也给我们提供了很多思路,很有借鉴意义。

mysql cmd insecure_看各路神仙如何大战MySQL insecure warning报警有感相关推荐

  1. PHP实习之路—NO.1(看LINUX、APACHE、MYSQL、PHP文档)

    PHP实习之路-NO.1(看LINUX.APACHE.MYSQL.PHP文档): 基本功一定要扎实! 本文转自 Lee_吉  博客,原文链接:    http://blog.51cto.com/121 ...

  2. Linux中Mysql root用户看不到mysql库问题解决方式

    Linux中Mysql root用户看不到mysql库问题解决方式 参考文章: (1)Linux中Mysql root用户看不到mysql库问题解决方式 (2)https://www.cnblogs. ...

  3. mysql 设置 0、1 用什么数据类型_什么是MySQL数据库?看这一篇干货文章就够了!...

    前言 为啥学习MySQL呢?因为MySQL是最流行的关系型数据库管理系统之一,在web应用方面,MySQL是最好的软件.MySQL所使用的sql语言是用于访问数据库的最常用标准化语言. 这篇文章,我会 ...

  4. MySQL : Access denied for user ''@'localhost' to database 'mysql'问题看点。

    问题描述:     MySQL命令行,登陆root账户的时候,密码为不为空,但是执行'use mysql;'命令的时候,总是提示:'Access denied for user "@'loc ...

  5. mysql CMD命令窗连接 - 转载

    cmd连接mysql的方法详解 首先需要进入mysql的安装文件夹bin目录下:cd + C:\Program Files\MySQL\MySQL Server 5.5\bin 连接:mysql -h ...

  6. mysql版本号怎么看

    怎么看mysql版本号 1. 在命令行中直接查看版本号 2. 在 mysql --help 中查找与版本相关的信息 3. 在mysql命令行里面查看版本信息 4. 在mysql命令号里面查看statu ...

  7. mysql 查看表v空间自增涨_面试问烂的 MySQL 查询优化,看完屌打面试官!

    Java技术栈 www.javastack.cn 优秀的Java技术公众号 作者:唐立勇 https://segmentfault.com/a/1190000013672421 什么影响了数据库查询速 ...

  8. 面试问烂的 MySQL 查询优化,看完屌打面试官!

    Java大数据修炼之道 优秀的Java技术公众号 作者:唐立勇 https://segmentfault.com/a/1190000013672421 相关阅读 面试问烂的 MySQL 四种隔离级别, ...

  9. cmd到指定目录并执行命令 mysql到bin目录并执行命令 cmd bat进入指定文件夹中并执行命令

    其实就一条命令:(保存为bat格式,注意:有两个and希腊字母 && ) cmd /k "cd /d Your ProjectPath&&Your CMD c ...

最新文章

  1. java socket安全策略文件
  2. 新玩法,CentOS7中LVM通过扩展逻辑卷扩展swap空间
  3. 瞧瞧UC浏览器对CSS样式的“关怀”
  4. LeetCode 1200. 最小绝对差
  5. 活动执行手册_如何从一无所知到独立规划陈列手册?
  6. Polyfill工作笔记001---简介
  7. mysql 获取select结果_php如何操作mysql获取select 结果
  8. 机器视觉——棱镜的妙用
  9. 139. php://
  10. 蓝桥杯C/C++A组省赛历年真题题解(2013~2021)
  11. 小米10青春版刷鸿蒙,没有高刷弱不禁风?小米10青春版刷新低价,这次用户或许会满意!...
  12. 计算机键盘的删除键,电脑删除键在哪 删除的快捷键是什么
  13. mac下Sed批量替换文件字符串
  14. Monitor对象是什么?
  15. 腾讯发布智能硬件全民WiFi 可提高游戏速度
  16. cf85d treap
  17. 蓝桥杯:约数个数(C++)
  18. NLP01(自然语言处理)第一章 绪论
  19. crash: mod命令
  20. 如何调试Excel VBA代码

热门文章

  1. 锁定td的高度_如何固定单元格的高度
  2. mysql 语言 总结
  3. 双一次算法作业hhhhhhhhh
  4. 手机\固定电话座机呼叫转移设置方法
  5. Amazon ParallelCluster 3 集成 ANSYS CFD 计算
  6. Photoshop设计一款Iphone风格导航菜单教程
  7. java学习笔记(22)java输入标签,单选框,复选框,添加文件,文本域,下拉框
  8. Gradually Vanishing Bridge for Adversarial Domain Adaptation
  9. 《JeolOnSoftware》
  10. 【C++】VS中读写操作(fclose.cpp)引发中断——将一个无效参数传递给了将无效参数视为严重错误的函数