From 1f59685530c4559b420f241be0b252299067b5bb Mon Sep 17 00:00:00 2001 From: Mario Candela Date: Sat, 1 Mar 2025 12:31:34 +0100 Subject: [PATCH] Feat: Improve HTTP Headers serializer json log #172 (#173) * Changed Event struct, field headers from string to map[string][]string * Add integration test for http Headers --- integration_test/integration_test.go | 3 +++ protocols/strategies/http.go | 14 +------------- tracer/tracer.go | 2 +- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/integration_test/integration_test.go b/integration_test/integration_test.go index 89053bf..0fcc8b5 100644 --- a/integration_test/integration_test.go +++ b/integration_test/integration_test.go @@ -67,8 +67,11 @@ func (suite *IntegrationTestSuite) TestInvokeHTTPHoneypot() { response, err := resty.New().R(). Get(suite.httpHoneypotHost + "/index.php") + response.Header().Del("Date") + suite.Require().NoError(err) suite.Equal(http.StatusOK, response.StatusCode()) + suite.Equal(http.Header{"Content-Length": []string{"15"}, "Content-Type": []string{"text/html"}, "Server": []string{"Apache/2.4.53 (Debian)"}, "X-Powered-By": []string{"PHP/7.4.29"}}, response.Header()) suite.Equal("mocked response", string(response.Body())) response, err = resty.New().R(). diff --git a/protocols/strategies/http.go b/protocols/strategies/http.go index fdb80e7..006ed44 100644 --- a/protocols/strategies/http.go +++ b/protocols/strategies/http.go @@ -117,7 +117,7 @@ func traceRequest(request *http.Request, tr tracer.Tracer, HoneypotDescription s HostHTTPRequest: request.Host, UserAgent: request.UserAgent(), Cookies: mapCookiesToString(request.Cookies()), - Headers: mapHeaderToString(request.Header), + Headers: request.Header, Status: tracer.Stateless.String(), RemoteAddr: request.RemoteAddr, SourceIp: host, @@ -133,18 +133,6 @@ func traceRequest(request *http.Request, tr tracer.Tracer, HoneypotDescription s tr.TraceEvent(event) } -func mapHeaderToString(headers http.Header) string { - headersString := "" - - for key := range headers { - for _, values := range headers[key] { - headersString += fmt.Sprintf("[Key: %s, values: %s],", key, values) - } - } - - return headersString -} - func mapCookiesToString(cookies []*http.Cookie) string { cookiesString := "" diff --git a/tracer/tracer.go b/tracer/tracer.go index ff79490..9b72bdf 100644 --- a/tracer/tracer.go +++ b/tracer/tracer.go @@ -27,7 +27,7 @@ type Event struct { User string Password string Client string - Headers string + Headers map[string][]string Cookies string UserAgent string HostHTTPRequest string