@@ -2,16 +2,16 @@ package strategies
2
2
3
3
import (
4
4
"fmt"
5
- "github.com/mariocandela/beelzebub/v3/parser"
6
- "github.com/mariocandela/beelzebub/v3/plugins"
7
- "github.com/mariocandela/beelzebub/v3/tracer"
8
5
"io"
9
6
"net"
10
7
"net/http"
11
8
"regexp"
12
9
"strings"
13
10
14
11
"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"
15
15
log "github.com/sirupsen/logrus"
16
16
)
17
17
@@ -67,13 +67,25 @@ func (httpStrategy HTTPStrategy) Init(beelzebubServiceConfiguration parser.Beelz
67
67
}
68
68
69
69
setResponseHeaders (responseWriter , command .Headers , command .StatusCode )
70
- fmt .Fprintf (responseWriter , responseHTTPBody )
70
+ fmt .Fprint (responseWriter , responseHTTPBody )
71
71
break
72
72
}
73
73
}
74
74
})
75
75
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
+ }
77
89
if err != nil {
78
90
log .Errorf ("Error during init HTTP Protocol: %s" , err .Error ())
79
91
return
@@ -95,7 +107,7 @@ func traceRequest(request *http.Request, tr tracer.Tracer, HoneypotDescription s
95
107
}
96
108
host , port , _ := net .SplitHostPort (request .RemoteAddr )
97
109
98
- tr . TraceEvent ( tracer.Event {
110
+ event := tracer.Event {
99
111
Msg : "HTTP New request" ,
100
112
RequestURI : request .RequestURI ,
101
113
Protocol : tracer .HTTP .String (),
@@ -111,7 +123,13 @@ func traceRequest(request *http.Request, tr tracer.Tracer, HoneypotDescription s
111
123
SourcePort : port ,
112
124
ID : uuid .New ().String (),
113
125
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 )
115
133
}
116
134
117
135
func mapHeaderToString (headers http.Header ) string {
0 commit comments