diff --git a/test/images/agnhost/README.md b/test/images/agnhost/README.md index 7776f7e1674..5e27be78dcc 100644 --- a/test/images/agnhost/README.md +++ b/test/images/agnhost/README.md @@ -392,6 +392,7 @@ Starts a HTTP(S) server on given port with the following endpoints: - `/`: Returns the request's timestamp. - `/clientip`: Returns the request's IP address. +- `/serveraddress`: Returns the server address. - `/dial`: Creates a given number of requests to the given host and port using the given protocol, and returns a JSON with the fields `responses` (successful request responses) and `errors` ( failed request responses). Returns `200 OK` status code if the last request succeeded, diff --git a/test/images/agnhost/VERSION b/test/images/agnhost/VERSION index d9949ce0266..81b3a99d62f 100644 --- a/test/images/agnhost/VERSION +++ b/test/images/agnhost/VERSION @@ -1 +1 @@ -2.55 +2.56 diff --git a/test/images/agnhost/netexec/netexec.go b/test/images/agnhost/netexec/netexec.go index e59d831795b..776f9a4bcde 100644 --- a/test/images/agnhost/netexec/netexec.go +++ b/test/images/agnhost/netexec/netexec.go @@ -66,6 +66,7 @@ var CmdNetexec = &cobra.Command{ - /: Returns the request's timestamp. - /clientip: Returns the request's IP address. +- /serveraddress: Returns the server address. - /header: Returns the request's header value corresponding to the key provided or the entire header marshalled as json, if no form value (key) is provided. ("/header?key=X-Forwarded-For" or /header) @@ -121,6 +122,7 @@ It will also start a UDP server on the indicated UDP port and addresses that res - "hostname": Returns the server's hostname - "echo ": Returns the given - "clientip": Returns the request's IP address +- "serveraddress": Returns the server address The UDP server can be disabled by setting --udp-port to -1. @@ -228,6 +230,7 @@ func main(cmd *cobra.Command, args []string) { func addRoutes(mux *http.ServeMux, sigTermReceived chan struct{}, exitCh chan shutdownRequest) { mux.HandleFunc("/", rootHandler) mux.HandleFunc("/clientip", clientIPHandler) + mux.HandleFunc("/serveraddress", serverAddressHandler) mux.HandleFunc("/header", headerHandler) mux.HandleFunc("/dial", dialHandler) mux.HandleFunc("/echo", echoHandler) @@ -287,6 +290,12 @@ func clientIPHandler(w http.ResponseWriter, r *http.Request) { log.Printf("GET /clientip") fmt.Fprint(w, r.RemoteAddr) } + +func serverAddressHandler(w http.ResponseWriter, r *http.Request) { + log.Printf("GET /serveraddress") + _, _ = fmt.Fprint(w, r.Host) +} + func headerHandler(w http.ResponseWriter, r *http.Request) { key := r.FormValue("key") if key != "" { @@ -668,6 +677,10 @@ func startUDPServer(address string, udpPort int) { log.Printf("Sending clientip back to UDP client %s\n", clientAddress) _, err = serverConn.WriteToUDP([]byte(clientAddress.String()), clientAddress) assertNoError(err, fmt.Sprintf("failed to write clientip to UDP client %s", clientAddress)) + } else if receivedText == "serveraddress" { + log.Printf("Sending server address to UDP client %s\n", serverConn.LocalAddr().String()) + _, err = serverConn.WriteToUDP([]byte(serverConn.LocalAddr().String()), clientAddress) + assertNoError(err, fmt.Sprintf("failed to write server address to UDP client %s", clientAddress)) } else if len(receivedText) > 0 { log.Printf("Unknown UDP command received from %s: %v\n", clientAddress, receivedText) } @@ -718,6 +731,10 @@ func startSCTPServer(sctpPort int) { log.Printf("Sending clientip back to SCTP client %s\n", clientAddress) _, err = conn.Write([]byte(clientAddress)) assertNoError(err, fmt.Sprintf("failed to write clientip to SCTP client %s", clientAddress)) + } else if receivedText == "serveraddress" { + log.Printf("Sending server address to SCTP client %s\n", conn.LocalAddr().String()) + _, err = conn.Write([]byte(conn.LocalAddr().String())) + assertNoError(err, fmt.Sprintf("failed to write server address to SCTP client %s", clientAddress)) } else if len(receivedText) > 0 { log.Printf("Unknown SCTP command received from %s: %v\n", clientAddress, receivedText) }