Added "list stale" and "remove stale" agents commands to list/remove

agents past their max checkins.
1.6
Harmj0y 2015-08-11 21:59:19 -04:00
parent 39d4684e00
commit 6b11aba29d
2 changed files with 45 additions and 2 deletions

View File

@ -2,6 +2,7 @@
--------- ---------
-Merged in Lost Agent Detection -Merged in Lost Agent Detection
-"agents> remove X" now removes agents that checked in > X minutes ago -"agents> remove X" now removes agents that checked in > X minutes ago
-"agents> list stale" and "agents> remove stale" now list/remove stale agents past their max checkins
8/10/2015 8/10/2015
--------- ---------

View File

@ -628,7 +628,28 @@ class AgentsMenu(cmd.Cmd):
agents = self.mainMenu.agents.get_agents() agents = self.mainMenu.agents.get_agents()
if line.strip() != "": if line.strip().lower() == "stale":
displayAgents = []
for agent in agents:
sessionID = self.mainMenu.agents.get_agent_id(agent[3])
# max check in -> delay + delay*jitter
intervalMax = agent[4] + agent[4] * agent[5]
# get the agent last check in time
agentTime = time.mktime(time.strptime(agent[16],"%Y-%m-%d %H:%M:%S"))
if agentTime < time.mktime(time.localtime()) - intervalMax:
# if the last checkin time exceeds the limit, remove it
displayAgents.append(agent)
messages.display_agents(displayAgents)
elif line.strip() != "":
# if we're listing an agents active in the last X minutes # if we're listing an agents active in the last X minutes
try: try:
minutes = int(line.strip()) minutes = int(line.strip())
@ -913,7 +934,27 @@ class AgentsMenu(cmd.Cmd):
self.mainMenu.agents.remove_agent('%') self.mainMenu.agents.remove_agent('%')
except KeyboardInterrupt as e: print "" except KeyboardInterrupt as e: print ""
if name.isdigit(): elif name.lower() == "stale":
# remove 'stale' agents that have missed their checkin intervals
agents = self.mainMenu.agents.get_agents()
for agent in agents:
sessionID = self.mainMenu.agents.get_agent_id(agent[3])
# max check in -> delay + delay*jitter
intervalMax = agent[4] + agent[4] * agent[5]
# get the agent last check in time
agentTime = time.mktime(time.strptime(agent[16],"%Y-%m-%d %H:%M:%S"))
if agentTime < time.mktime(time.localtime()) - intervalMax:
# if the last checkin time exceeds the limit, remove it
self.mainMenu.agents.remove_agent(sessionID)
elif name.isdigit():
# if we're removing agents that checked in longer than X minutes ago # if we're removing agents that checked in longer than X minutes ago
agents = self.mainMenu.agents.get_agents() agents = self.mainMenu.agents.get_agents()
@ -936,6 +977,7 @@ class AgentsMenu(cmd.Cmd):
print helpers.color("[!] Please enter the minute window for agent checkin.") print helpers.color("[!] Please enter the minute window for agent checkin.")
else: else:
print "agent name!"
# extract the sessionID and clear the agent tasking # extract the sessionID and clear the agent tasking
sessionID = self.mainMenu.agents.get_agent_id(name) sessionID = self.mainMenu.agents.get_agent_id(name)