@@ -2,16 +2,16 @@ package strategies
22
33import (
44 "fmt"
5- "github.com/mariocandela/beelzebub/v3/parser"
6- "github.com/mariocandela/beelzebub/v3/plugins"
7- "github.com/mariocandela/beelzebub/v3/tracer"
85 "io"
96 "net"
107 "net/http"
118 "regexp"
129 "strings"
1310
1411 "github.com/google/uuid"
12+ "github.com/mariocandela/beelzebub/v3/parser"
13+ "github.com/mariocandela/beelzebub/v3/plugins"
14+ "github.com/mariocandela/beelzebub/v3/tracer"
1515 log "github.com/sirupsen/logrus"
1616)
1717
@@ -67,13 +67,25 @@ func (httpStrategy HTTPStrategy) Init(beelzebubServiceConfiguration parser.Beelz
6767 }
6868
6969 setResponseHeaders (responseWriter , command .Headers , command .StatusCode )
70- fmt .Fprintf (responseWriter , responseHTTPBody )
70+ fmt .Fprint (responseWriter , responseHTTPBody )
7171 break
7272 }
7373 }
7474 })
7575 go func () {
76- err := http .ListenAndServe (httpStrategy .beelzebubServiceConfiguration .Address , serverMux )
76+ var err error
77+ // Launch a TLS supporting server if we are supplied a TLS Key and Certificate.
78+ // If relative paths are supplied, they are relative to the CWD of the binary.
79+ // The can be self-signed, only the client will validate this (or not).
80+ if httpStrategy .beelzebubServiceConfiguration .TLSKeyPath != "" && httpStrategy .beelzebubServiceConfiguration .TLSCertPath != "" {
81+ err = http .ListenAndServeTLS (
82+ httpStrategy .beelzebubServiceConfiguration .Address ,
83+ httpStrategy .beelzebubServiceConfiguration .TLSCertPath ,
84+ httpStrategy .beelzebubServiceConfiguration .TLSKeyPath ,
85+ serverMux )
86+ } else {
87+ err = http .ListenAndServe (httpStrategy .beelzebubServiceConfiguration .Address , serverMux )
88+ }
7789 if err != nil {
7890 log .Errorf ("Error during init HTTP Protocol: %s" , err .Error ())
7991 return
@@ -95,7 +107,7 @@ func traceRequest(request *http.Request, tr tracer.Tracer, HoneypotDescription s
95107 }
96108 host , port , _ := net .SplitHostPort (request .RemoteAddr )
97109
98- tr . TraceEvent ( tracer.Event {
110+ event := tracer.Event {
99111 Msg : "HTTP New request" ,
100112 RequestURI : request .RequestURI ,
101113 Protocol : tracer .HTTP .String (),
@@ -111,7 +123,13 @@ func traceRequest(request *http.Request, tr tracer.Tracer, HoneypotDescription s
111123 SourcePort : port ,
112124 ID : uuid .New ().String (),
113125 Description : HoneypotDescription ,
114- })
126+ }
127+ // Capture the TLS details from the request, if provided.
128+ if request .TLS != nil {
129+ event .Msg = "HTTPS New Request"
130+ event .TLSServerName = request .TLS .ServerName
131+ }
132+ tr .TraceEvent (event )
115133}
116134
117135func mapHeaderToString (headers http.Header ) string {
0 commit comments