Skip to content

Commit 0623821

Browse files
authored
Fix the non-C2 spun up shutdown case (scanner only) (#369)
* Fix the non-C2 spun up shutdown case (scanner only)
1 parent 01661cd commit 0623821

File tree

7 files changed

+28
-0
lines changed

7 files changed

+28
-0
lines changed

c2/httpservefile/httpservefile.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ func (httpServer *Server) Channel() *channel.Channel {
105105

106106
// Shutdown the C2 server and cleanup all the sessions.
107107
func (httpServer *Server) Shutdown() bool {
108+
// Account for non-running case
109+
if httpServer.Channel() == nil {
110+
return true
111+
}
108112
output.PrintFrameworkStatus("Shutting down the HTTP Server")
109113
if len(httpServer.Channel().Sessions) > 0 {
110114
for k := range httpServer.Channel().Sessions {

c2/httpserveshell/httpserveshell.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ func (serveShell *Server) Init(ch *channel.Channel) bool {
119119

120120
// Shutdown triggers the shutdown for all running C2s.
121121
func (serveShell *Server) Shutdown() bool {
122+
// Account for non-running case
123+
if serveShell.Channel() == nil {
124+
return true
125+
}
122126
// This is a bit confusing at first glance, but it solves the fact that this c2 doesn't directly
123127
// keep track of sessions and we can't differentiate between a timeout "done" and a signal "done".
124128
// What this means is that if a underlying shell server has sessions that we want to keep open for

c2/httpshellserver/httpshellserver.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ func (httpServer *Server) Channel() *channel.Channel {
131131

132132
// Shutdown the C2 server and cleanup all the sessions.
133133
func (httpServer *Server) Shutdown() bool {
134+
// Account for non-running case
135+
if httpServer.Channel() == nil {
136+
return true
137+
}
134138
output.PrintFrameworkStatus("Shutting down the HTTP Server")
135139
if len(httpServer.Channel().Sessions) > 0 {
136140
for k := range httpServer.Channel().Sessions {

c2/shelltunnel/shelltunnel.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ func (shellTunnel *Server) Init(channel *channel.Channel) bool {
159159
}
160160

161161
func (shellTunnel *Server) Shutdown() bool {
162+
// Account for non-running case
163+
if shellTunnel.Channel() == nil {
164+
return true
165+
}
162166
output.PrintFrameworkStatus("C2 received shutdown, killing server and client sockets for shell tunnel")
163167
if len(shellTunnel.Channel().Sessions) > 0 {
164168
for k, session := range shellTunnel.Channel().Sessions {

c2/simpleshell/simpleshellclient.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ func (shellClient *Client) CreateFlags() {
3131
}
3232

3333
func (shellClient *Client) Shutdown() bool {
34+
// Account for non-running case
35+
if shellClient.Channel() == nil {
36+
return true
37+
}
3438
ok := shellClient.Channel().RemoveSessions()
3539

3640
// we done here

c2/simpleshell/simpleshellserver.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ func (shellServer *Server) Channel() *channel.Channel {
4545

4646
// Shutdown the C2 and cleanup any active connections.
4747
func (shellServer *Server) Shutdown() bool {
48+
// Account for non-running case
49+
if shellServer.Channel() == nil {
50+
return true
51+
}
4852
output.PrintFrameworkStatus("C2 received shutdown, killing server and client sockets for shell server")
4953
if len(shellServer.Channel().Sessions) > 0 {
5054
for k, session := range shellServer.Channel().Sessions {

c2/sslshell/sslshellserver.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ func (shellServer *Server) CreateFlags() {
6666

6767
// Shutdown the C2 and close server and client connections when applicable.
6868
func (shellServer *Server) Shutdown() bool {
69+
// Account for non-running case
70+
if shellServer.Channel() == nil {
71+
return true
72+
}
6973
output.PrintFrameworkStatus("C2 received shutdown, killing server and client sockets for SSL shell server")
7074
if len(shellServer.channel.Sessions) > 0 {
7175
for k, session := range shellServer.channel.Sessions {

0 commit comments

Comments
 (0)