Skip to content

Commit 5bc9e18

Browse files
fixed
1 parent 273dc59 commit 5bc9e18

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

c2/channel/channel.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ type Session struct {
3535
LastSeen time.Time
3636
}
3737

38+
// HadSessions checks if a channel has any tracked sessions. This can be used to lookup if a C2
39+
// successfully received callbacks EVER, regardless of whether or not it is currently active.
40+
//
41+
// c, ok := c2.GetInstance(conf.C2Type)
42+
// c.Channel().HadSessions()
43+
func (c *Channel) HadSessions() bool {
44+
return len(c.Sessions) > 0
45+
}
46+
3847
// HasSessions checks if a channel has any tracked sessions. This can be used to lookup if a C2
3948
// successfully received callbacks:
4049
//

c2/factory.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,35 @@ func CreateFlags(implementation Impl) {
152152
}
153153
}
154154

155+
// HadSessions returns if the underlying channel has any sessions, regardless of their Active value.
156+
func HadSessions(implementation Impl) bool {
157+
switch implementation.Category {
158+
case SimpleShellServerCategory:
159+
return simpleshell.GetServerInstance().Channel().HadSessions()
160+
case SimpleShellClientCategory:
161+
return simpleshell.GetClientInstance().Channel().HadSessions()
162+
case SSLShellServerCategory:
163+
return sslshell.GetInstance().Channel().HadSessions()
164+
case HTTPServeFileCategory:
165+
return httpservefile.GetInstance().Channel().HadSessions()
166+
case HTTPServeShellCategory:
167+
return httpserveshell.GetInstance().Channel().HadSessions()
168+
case ExternalCategory:
169+
if implementation.Name != "" {
170+
return external.GetInstance(implementation.Name).Channel().HadSessions()
171+
}
172+
case HTTPShellServerCategory:
173+
return httpshellserver.GetInstance().Channel().HadSessions()
174+
case ShellTunnelCategory:
175+
return shelltunnel.GetInstance().Channel().HadSessions()
176+
case InvalidCategory:
177+
default:
178+
}
179+
output.PrintFrameworkError("Invalid C2 Server")
180+
181+
return false
182+
}
183+
155184
// HasSessions returns if the underlying channel has active sessions. This is useful for code that
156185
// needs to validate if callbacks have occurred and is a helper wrapper around the channel package
157186
// function of the same name.

0 commit comments

Comments
 (0)