agnhost/netexec: handle nil pointer dereference for SCTP server

If the client immediately closes connection after SCTP handshake, the
remote-addr fetched by SCTP server can be nil, causing the server to crash.

Signed-off-by: Daman Arora <aroradaman@gmail.com>
This commit is contained in:
Daman Arora 2024-04-21 16:47:21 +05:30
parent 8946348636
commit 8cf4567f3c

View File

@ -693,7 +693,11 @@ func startSCTPServer(sctpPort int) {
for {
conn, err := listener.AcceptSCTP()
assertNoError(err, fmt.Sprintf("failed accepting SCTP connections"))
clientAddress := conn.RemoteAddr().String()
remoteAddr, err := conn.SCTPRemoteAddr(0)
if err != nil {
assertNoError(err, "failed to get SCTP client remote address")
}
clientAddress := remoteAddr.String()
n, err := conn.Read(buf)
assertNoError(err, fmt.Sprintf("failed to read from SCTP client %s", clientAddress))
receivedText := strings.ToLower(strings.TrimSpace(string(buf[0:n])))