From 4d2145325db0eb833b0fb4f354da37979066da48 Mon Sep 17 00:00:00 2001 From: parallels Date: Thu, 26 Dec 2024 23:48:36 -0500 Subject: [PATCH] add TCP read which is more bruteforce-friendly, not logging errors on closed connections --- protocol/tcpsocket.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/protocol/tcpsocket.go b/protocol/tcpsocket.go index 88eb84e..441072b 100644 --- a/protocol/tcpsocket.go +++ b/protocol/tcpsocket.go @@ -109,3 +109,23 @@ func TCPReadAmount(conn net.Conn, amount int) ([]byte, bool) { return reply, true } + +// Read an amount and dont log errors if we fail to read from the socket +func TCPReadAmountBlind(conn net.Conn, amount int) ([]byte, bool) { + reply := make([]byte, amount) + totalRead := 0 + + // keep reading until we hit the desired amount (or an error occurs) + for totalRead < amount { + count, err := conn.Read(reply[totalRead:]) + if err != nil { + return nil, false + } + if count == 0 { + return nil, false + } + totalRead += count + } + + return reply, true +}