@@ -14,6 +14,7 @@ import (
14
14
15
15
"github.com/vulncheck-oss/go-exploit/c2/channel"
16
16
"github.com/vulncheck-oss/go-exploit/encryption"
17
+ "github.com/vulncheck-oss/go-exploit/random"
17
18
"github.com/vulncheck-oss/go-exploit/output"
18
19
)
19
20
@@ -41,6 +42,9 @@ type Server struct {
41
42
Certificate tls.Certificate
42
43
// Allows us to track if a connection has been received during the life of the server
43
44
Success bool
45
+ // Randomly generated during init, gives some sense of security where there is otherwise none.
46
+ // This should appear in a header with the name VC-Auth
47
+ AuthHeader string
44
48
}
45
49
46
50
// A basic singleton interface for the c2.
@@ -53,6 +57,7 @@ func GetInstance() *Server {
53
57
}
54
58
55
59
func (httpServer * Server ) Init (channel channel.Channel ) bool {
60
+ httpServer .AuthHeader = random .RandLetters (20 )
56
61
if channel .IsClient {
57
62
output .PrintFrameworkError ("Called C2HTTPServer as a client. Use lhost and lport." )
58
63
@@ -100,17 +105,30 @@ func (httpServer *Server) CreateFlags() {
100
105
}
101
106
102
107
// start the HTTP server and listen for incoming requests for `httpServer.FileName`.
103
- //
104
108
//nolint:gocognit
105
109
func (httpServer * Server ) Run (timeout int ) {
106
- http .HandleFunc ("/rx" , func (_ http.ResponseWriter , req * http.Request ) {
110
+ http .HandleFunc ("/rx" , func (writer http.ResponseWriter , req * http.Request ) {
111
+ authHeader := req .Header .Get ("VC-Auth" )
112
+ if authHeader != httpServer .AuthHeader {
113
+ writer .WriteHeader (http .StatusForbidden )
114
+ output .PrintfFrameworkDebug ("Auth header mismatch from %s: %s, should be %s" , req .RemoteAddr , req .Header .Get ("VC-Auth" ), httpServer .AuthHeader )
115
+
116
+ return
117
+ }
107
118
body , _ := io .ReadAll (req .Body )
108
119
if strings .TrimSpace (string (body )) != "" {
109
120
fmt .Printf ("\n %s: %s\n " , req .RemoteAddr , string (body ))
110
121
}
111
122
})
112
123
113
124
http .HandleFunc ("/" , func (writer http.ResponseWriter , req * http.Request ) {
125
+ authHeader := req .Header .Get ("VC-Auth" )
126
+ if authHeader != httpServer .AuthHeader {
127
+ writer .WriteHeader (http .StatusForbidden )
128
+ output .PrintfFrameworkDebug ("Auth header mismatch from %s: %s, should be %s" , req .RemoteAddr , req .Header .Get ("VC-Auth" ), httpServer .AuthHeader )
129
+
130
+ return
131
+ }
114
132
lastSeen = time .Now ()
115
133
writer .Header ().Set ("Server" , httpServer .ServerField )
116
134
@@ -166,11 +184,11 @@ func (httpServer *Server) Run(timeout int) {
166
184
//nolint
167
185
MinVersion : tls .VersionSSL30 ,
168
186
}
169
- server := http.Server {
187
+ server := http.Server {
170
188
Addr : connectionString ,
171
189
TLSConfig : tlsConfig ,
172
190
// required to disable HTTP/2 according to https://pkg.go.dev/net/http#hdr-HTTP_2
173
- TLSNextProto : make (map [string ]func (* http.Server , * tls.Conn , http.Handler ), 1 ),
191
+ TLSNextProto : make (map [string ]func (* http.Server , * tls.Conn , http.Handler ),1 ),
174
192
}
175
193
defer server .Close ()
176
194
_ = server .ListenAndServeTLS ("" , "" )
0 commit comments