Skip to content

Commit

Permalink
Register new hosts when beacons are received and not just sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgol committed Sep 23, 2022
1 parent 160486c commit 79b60eb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions server/core/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ package core
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import (
"github.com/bishopfox/sliver/server/db/models"
)

const (
// Size is arbitrary, just want to avoid weird cases where we'd block on channel sends
eventBufSize = 5
Expand All @@ -29,6 +33,7 @@ type Event struct {
Session *Session
Job *Job
Client *Client
Beacon *models.Beacon

EventType string

Expand Down
32 changes: 32 additions & 0 deletions server/core/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func StartEventAutomation() {
for event := range EventBroker.Subscribe() {
switch event.EventType {

case consts.BeaconRegisteredEvent:
if event.Beacon != nil {
hostsBeaconCallback(event.Beacon)
}
case consts.SessionOpenedEvent:
if event.Session != nil {
hostsSessionCallback(event.Session)
Expand Down Expand Up @@ -76,3 +80,31 @@ func hostsSessionCallback(session *Session) {
}
}
}

// Triggered on new beacon events, checks to see if the host is in
// the database and adds it if not.
func hostsBeaconCallback(beacon *models.Beacon) {
coreLog.Debugf("Hosts beacon callback for %v", beacon.UUID)
dbSession := db.Session()
host, err := db.HostByHostUUID(beacon.UUID.String())
coreLog.Debugf("Hosts query result: %v %v", host, err)
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
coreLog.Error(err)
return
}
if errors.Is(err, gorm.ErrRecordNotFound) {
coreLog.Infof("Beacon %v is from a new host", beacon.ID)
err := dbSession.Create(&models.Host{
HostUUID: uuid.FromStringOrNil(beacon.UUID.String()),
Hostname: beacon.Hostname,
OSVersion: beacon.OS,
Locale: beacon.Locale,
IOCs: []models.IOC{},
ExtensionData: []models.ExtensionData{},
}).Error
if err != nil {
coreLog.Error(err)
return
}
}
}
1 change: 1 addition & 0 deletions server/handlers/beacons.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func beaconRegisterHandler(implantConn *core.ImplantConnection, data []byte) *sl
core.EventBroker.Publish(core.Event{
EventType: consts.BeaconRegisteredEvent,
Data: eventData,
Beacon: beacon,
})

go auditLogBeacon(beacon, beaconReg.Register)
Expand Down

0 comments on commit 79b60eb

Please sign in to comment.