Skip to content

Commit

Permalink
fix: fail to check command output from agent, agent then gets marked …
Browse files Browse the repository at this point in the history
…as unresponsive incorrectly
  • Loading branch information
jm33-m0 committed Sep 29, 2022
1 parent a1a6268 commit 14553b6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 4 additions & 4 deletions core/lib/cc/agentHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func processAgentData(data *emp3r0r_data.MsgTunData) {

// time spent on this cmd
cmd_id := payloadSplit[len(payloadSplit)-1]
// cache this cmd response
CmdResultsMutex.Lock()
CmdResults[cmd_id] = out
CmdResultsMutex.Unlock()
start_time, err := time.Parse("2006-01-02 15:04:05.999999999 -0700 MST", CmdTime[cmd_id])
if err != nil {
CliPrintWarning("Parsing timestamp '%s': %v", CmdTime[cmd_id], err)
Expand Down Expand Up @@ -191,8 +195,4 @@ func processAgentData(data *emp3r0r_data.MsgTunData) {
color.HiMagentaString(cmd),
color.HiWhiteString(out))

// cache this cmd response
CmdResultsMutex.Lock()
CmdResults[cmd_id] = out
CmdResultsMutex.Unlock()
}
5 changes: 4 additions & 1 deletion core/lib/cc/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,13 @@ func wait_for_cmd_response(cmd, cmd_id string, agent *emp3r0r_data.AgentSystemIn
now := time.Now()
for ctrl.Ctx.Err() == nil {
if _, exists := CmdResults[cmd_id]; exists {
CmdResultsMutex.Lock()
delete(CmdResults, cmd_id)
CmdResultsMutex.Unlock()
return
}
wait_time := time.Since(now)
if wait_time > 20*time.Second {
if wait_time > 1*time.Minute {
CliPrintError("Executing %s on %s: unresponsive for %v, removing agent from list",
strconv.Quote(cmd),
strconv.Quote(agent.Name),
Expand Down

0 comments on commit 14553b6

Please sign in to comment.