From 5e10c744c81dfcfcd1cdb7287bfe681598570133 Mon Sep 17 00:00:00 2001 From: Josh Rendek Date: Fri, 15 Nov 2024 09:42:15 -0500 Subject: [PATCH] add catch all handler for k8s --- kubernetes/handlers.go | 6 ++++++ kubernetes/k8s.go | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/kubernetes/handlers.go b/kubernetes/handlers.go index 30e63ae..512080a 100644 --- a/kubernetes/handlers.go +++ b/kubernetes/handlers.go @@ -69,6 +69,12 @@ func (h *honeypot) apiHandler(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(response) } +func (h *honeypot) catchAllHandler(w http.ResponseWriter, r *http.Request) { + body := make([]byte, r.ContentLength) + _, _ = r.Body.Read(body) + h.logger.Info().Str("path", r.URL.Path).Str("method", r.Method).Bytes("body", body).Msg("Request received") +} + // Handler for /api/v1 func (h *honeypot) apiV1Handler(w http.ResponseWriter, r *http.Request) { response := map[string]interface{}{ diff --git a/kubernetes/k8s.go b/kubernetes/k8s.go index 230774b..c4d0c45 100644 --- a/kubernetes/k8s.go +++ b/kubernetes/k8s.go @@ -62,6 +62,10 @@ func (h *honeypot) Start() { // Handle /api/v1/namespaces/{namespace}/pods router.HandleFunc("/api/v1/namespaces/{namespace}/pods", h.podsHandler).Methods("GET", "POST") + // add a catch all route and log the request and body + router.PathPrefix("/").HandlerFunc(h.catchAllHandler).Methods("GET", "POST") + + // Generate the TLS certificate cert, err := generateSelfSignedCert()