mysql登录抓包_MySQL登录验证的抓包
理論知識部分摘錄自:
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,相等則驗證通過。
下圖是我從mysql5.7.22代碼里面截取的偽代碼:
官方文檔:
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的部分截圖:
第5~7個包是三次握手包。
第8個包:
server告知客戶端,當前服務器的字符集、認證使用的插件。并將隨機生成的一個salt值發給client。
第9個包:
client端收到server端發來的salt值,然后使用salt值和本地的登錄密碼生成一個新的隨機串,然后將新的串發往服務端(就是上圖中的dd249f24....這串字符串)。服務端check字符串反解析。
第10個包,是server-->client的ACK包。
第11個包開始及之后的一些packet就是client server之間的通訊了。
總結
以上是生活随笔為你收集整理的mysql登录抓包_MySQL登录验证的抓包的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql什么情况会扫描所有_造成MyS
- 下一篇: mysql开启定时器_MySQL定时器开