Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions c2/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ 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 {
// Currently sessions are only added to the session structure and then their states are modified.
// This will only work as long as the sessions are never actually removed from the map, which for
// now isn't an issue but if we ever switch to a history vs active tracking systtem then this will
// not be sufficient.
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