| 1 |
Description: Fix mysql.server panic on crafted client handshake (remote DoS). |
| 2 |
Author: Simone Margaritelli <[email protected]> |
| 3 |
Origin: upstream, https://github.com/bettercap/bettercap/commit/0eaa375c5e5446bfba94a290eff92967a5deac9e.patch |
| 4 |
Bug: https://github.com/bettercap/bettercap/issues/1265 |
| 5 |
Bug-Debian: https://bugs.debian.org/1136448 |
| 6 |
Forwarded: not-needed |
| 7 |
Reviewed-By: Francisco Vilmar Cardoso Ruviaro <[email protected]> |
| 8 |
Last-Update: 2026-07-10 |
| 9 |
|
| 10 |
--- a/modules/mysql_server/mysql_server.go |
| 11 |
+++ b/modules/mysql_server/mysql_server.go |
| 12 |
@@ -121,15 +121,20 @@ func (mod *MySQLServer) Start() error { |
| 13 |
if _, err := conn.Write(packets.MySQLGreeting); err != nil { |
| 14 |
mod.Warning("error while writing server greeting: %s", err) |
| 15 |
continue |
| 16 |
|
| 17 |
+ } else if read, err = reader.Read(readBuffer); err != nil { |
| 18 |
mod.Warning("error while reading client message: %s", err) |
| 19 |
continue |
| 20 |
} |
| 21 |
|
| 22 |
+ if read < 37 { |
| 23 |
+ mod.Warning("client handshake too short (%d bytes)", read) |
| 24 |
+ continue |
| 25 |
+ } |
| 26 |
+ |
| 27 |
// parse client capabilities and validate connection |
| 28 |
// TODO: parse mysql connections properly and |
| 29 |
// display additional connection attributes |
| 30 |
|
| 31 |
+ capabilities := fmt.Sprintf("%016b", (int(uint32(readBuffer[4]) | uint32(readBuffer[5])<<8))) |
| 32 |
loadData := string(capabilities[8]) |
| 33 |
username := string(bytes.Split(readBuffer[36:], []byte{0})[0]) |
| 34 |
|