mysql-net / MySqlConnector

MySQL Connector for .NET
https://mysqlconnector.net
MIT License
1.39k stars 337 forks source link

Request: Ability to retrieve the version info of the remote host without valid credentials #1400

Closed Reelix closed 11 months ago

Reelix commented 11 months ago

Is your feature request related to a problem? Please describe. As it stands, you are required to successfully run a .Open with correct credentials to populate the MySqlConnection.ServerVersion value.

Describe the solution you'd like I want a way to retrieve the version info without the Open command completing (Or even in the MySqlException class).

Describe alternatives you've considered As it stands, I can retrieve the version by initiating a raw netcat connection to the server on the port, and retrieve something that looks like

nc 10.10.84.145 3306
Y
5.5.5-10.4.28-MariaDtY@uKY[?��-��horoWE3lKnkPmysql_native_password

To retrieve the basic version, although this isn't exactly ideal, and I would prefer to do so using the library.

Additional context This is for a basic penetration testing scenario where you wish to retrieve the version without the credentials (Whilst nmap can do so, I would prefer do to so in an in-code form)

bgrainger commented 11 months ago

This feature request seems out of scope for this library: its purpose is to open MySQL connections, not perform port scanning.

Since the server sends its version in the "Initial Handshake" packet, I think it would be easiest for you to read the header off the first packet the server sends when the client connects to TCP port 3306, then close the socket. That would also avoid carrying a mostly-unnecessary MySqlConnector dependency in your code.