[英]Unable to process mysql login using raw packet on tcp socket established through python? Probably due to salt?
I am trying simulate mysql connection process through python program. 我正在尝试通过python程序模拟mysql连接过程。 In python script, I am opening a tcp socket to mysql server and writing pre-captured on socket. 在python脚本中,我正在向mysql服务器打开一个tcp套接字,并在套接字上编写了预先捕获的内容。 On login packet I get an error "#28000Access denied for user 'root'@'10.xxxxx' (using password: YES)" 在登录数据包上,我收到一个错误“#28000用户'root'@'10.xxxxx'的访问被拒绝(使用密码:是)”
import socket
import sys
import time
Host = '10.x.x.xxx'
Port = '3306'
t_con = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clust_vip = (Host, int(Port))
try:
t_con.connect(clust_vip)
print ('Socket connection established')
print "TCP connection established:", t_con.recv(4096)
byte1 = open("req_r1").read()
t_con.send(byte1)
print "Response for packet1:", t_con.recv(4096)
bytes2 = open("req_r2").read()
t_con.send(byte2)
print "Response for packet2:", t_con.recv(4096)
finally:
t_con.close()
"req_r1" and "req_r2" file used above contains raw packets (mysql protocol raw packets and not entire frame/tcp layer) 上面使用的“ req_r1”和“ req_r2”文件包含原始数据包(mysql协议原始数据包,而不是整个帧/ tcp层)
Can anyone guide me how I can overcome this issue. 谁能指导我如何克服这个问题。 I think error is due to salt used to establish the mysql connection. 我认为错误是由于盐用于建立mysql连接。
I have tried Passwordless connection as well however it didn't worked. 我也尝试过无密码连接 ,但是没有用。
Update: What I understand is on establishing tcp socket connection, db server replies with salt and I need to reuse this salt to generate encrypted password and use it in next connect packet. 更新:我了解的是建立tcp套接字连接,数据库服务器用salt答复,我需要重用此salt来生成加密密码并在下一个连接数据包中使用它。 If anyone has idea if I am on right track and how i can extract/reuse it it would be great help. 如果有人知道我是否在正确的轨道上以及如何提取/重用它,那将是很大的帮助。
You can't log in by replaying a previous session. 您无法通过重播上一个会话来登录。 As has been pointed out in comments, that would be terribly insecure. 正如评论中指出的那样,这将是非常不安全的。 It's a challenge/response mechanism, and your response varies with the challenge received. 这是一个挑战/响应机制,您的响应会随收到的挑战而变化。
See https://dev.mysql.com/doc/internals/en/client-server-protocol.html for a breakdown of the protocol. 有关协议的详细信息,请参见https://dev.mysql.com/doc/internals/zh-CN/client-server-protocol.html 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.