agnhost: added server address for conntrack cleanup entries

This commit is contained in:
yashsingh74
2025-05-23 14:36:42 +05:30
parent b35c5c0a30
commit c8f1a65301
3 changed files with 19 additions and 1 deletions

View File

@@ -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,

View File

@@ -1 +1 @@
2.55
2.56

View File

@@ -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 <msg>": Returns the given <msg>
- "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)
}