Skip to content
Draft
9 changes: 9 additions & 0 deletions c2/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ type Session struct {
LastSeen time.Time
}

// HadSessions checks if a channel has any tracked sessions. This can be used to lookup if a C2
// successfully received callbacks EVER, regardless of whether or not it is currently active.
//
// c, ok := c2.GetInstance(conf.C2Type)
// c.Channel().HadSessions()
func (c *Channel) HadSessions() bool {
return len(c.Sessions) > 0
}

// HasSessions checks if a channel has any tracked sessions. This can be used to lookup if a C2
// successfully received callbacks:
//
Expand Down
29 changes: 29 additions & 0 deletions c2/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,35 @@ func CreateFlags(implementation Impl) {
}
}

// HadSessions returns if the underlying channel has any sessions, regardless of their Active value.
func HadSessions(implementation Impl) bool {
switch implementation.Category {
case SimpleShellServerCategory:
return simpleshell.GetServerInstance().Channel().HadSessions()
case SimpleShellClientCategory:
return simpleshell.GetClientInstance().Channel().HadSessions()
case SSLShellServerCategory:
return sslshell.GetInstance().Channel().HadSessions()
case HTTPServeFileCategory:
return httpservefile.GetInstance().Channel().HadSessions()
case HTTPServeShellCategory:
return httpserveshell.GetInstance().Channel().HadSessions()
case ExternalCategory:
if implementation.Name != "" {
return external.GetInstance(implementation.Name).Channel().HadSessions()
}
case HTTPShellServerCategory:
return httpshellserver.GetInstance().Channel().HadSessions()
case ShellTunnelCategory:
return shelltunnel.GetInstance().Channel().HadSessions()
case InvalidCategory:
default:
}
output.PrintFrameworkError("Invalid C2 Server")

return false
}

// HasSessions returns if the underlying channel has active sessions. This is useful for code that
// needs to validate if callbacks have occurred and is a helper wrapper around the channel package
// function of the same name.
Expand Down