设为首页 收藏本站
查看: 914|回复: 0

[经验分享] MySQL登录验证的抓包

[复制链接]

尚未签到

发表于 2018-10-10 11:19:21 | 显示全部楼层 |阅读模式
  理论知识部分摘录自:
  http://blog.chinaunix.net/uid-9234131-id-5088292.html
  http://blog.csdn.net/sissiyinxi/article/details/7660389
  1.服务器端会随机生成一个random string发送给客户端;
  2.客户端收到random string后,进行hash加密
  第一步,将密码hash,得到hash值hash_stage1;  eg.hash_stage1=sha1("password");
  第二步,二次hash,得到hash_stage2;  eg. hash_stage2=sha1(hash_stage1);
  第三步,将密码二次hash得到的值与random string进行hash,得到hash_stage3; eg. hash_stage3=sha1("randomstring",hash_stage2);
  第四步,异或处理准备发送给服务器端,得到reply=xor(hash_stage1,hash_stage3);
  最后,将reply的值发送给服务器端。
  3.服务器端收到reply后同样进行hash运算
  第一步,将保存的hash形式的密码hashpassword与random string进行hash,得到server_hash_stage1=sha1("randomstring","hashpassword");
  第二步,将客户端发送的reply与刚才得到的hash值进行异或运算,得到xor_value; eg. xor_value=xor(reply,server_hash_stage1);
  第三步,将得到的异或值进行hash,得到server_hash_stage2; eg. server_hash_stage2=sha1(server_hash_stage1);
  第四步,验证,将最后得到的hash值server_hash_stage2与保存的密码hashpassword进行比较。eg.   server_hash_stage2==hashpassword,相等则验证通过。
  伪代码如下:
  SERVER:  public_seed=create_random_string()
  send(public_seed)
  CLIENT:  recv(public_seed)
  hash_stage1=sha1("password")
  hash_stage2=sha1(hash_stage1)
  reply=xor(hash_stage1,sha1(public_seed,hash_stage2)
  // this three steps are done inscramble()
  send(reply)
  SERVER:  recv(reply)
  hash_stage1=xor(reply,sha1(public_seed,hash_stage2))
  candidate_hash2=sha1(hash_stage1)
  check(candidate_hash2==hash_stage2)
  // this three steps are done incheck_scramble()
  官方文档:
  MySQL uses passwords in two phasesof client/server communication:
  When a client attempts to connectto the server, there is an initial authentication step in which the client mustpresent a password that has a hash value matching the hash value stored in theuser table for the account the client wants to use.
  After the client connects, it can(if it has sufficient privileges) set or change the password hash for accountslisted in the user table. The client can do this by using the PASSWORD()function to generate a password hash, or by using a password-generatingstatement (CREATE USER, GRANT, or SET PASSWORD).
  > SELECT PASSWORD('Abcd@1234');   # mysql用户密码的计算方式:(hash方式)
  +-------------------------------------------+
  | PASSWORD('Abcd@1234')                     |
  |-------------------------------------------|
  |*47B150E012313114C04A1C9336709424085B6BD0 |
  +-------------------------------------------+
  使用wireshark抓取通过navicat登录虚拟机的mysql-5.7的部分截图:
DSC0000.png

  5~7个包是三次握手包。
  8个包:
DSC0001.png

DSC0002.png

DSC0003.png

  server告知客户端,当前服务器的字符集、认证使用的插件。并将随机生成的一个salt值发给client。
  9个包:
DSC0004.png

  client端收到server端发来的salt值,然后使用salt值和本地的登录密码生成一个新的随机串,然后将新的串发往服务端(就是上图中的dd249f24....这串字符串)。服务端check字符串反解析。
  10个包,是server-->client ACK包。
  11个包开始及之后的一些packet就是client server 之间的通讯了。
DSC0005.png

DSC0006.png



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-619900-1-1.html 上篇帖子: SQL Server2008 链接远程MySQL 下篇帖子: OpenStack HA集群1-Galera Cluster for Mysql
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

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