MCPcopy
hub / github.com/apache/caldera / handle_heartbeat

Method handle_heartbeat

app/service/contact_svc.py:58–93  ·  view source on GitHub ↗
(self, **kwargs)

Source from the content-addressed store, hash-verified

56
57 @report
58 async def handle_heartbeat(self, **kwargs):
59 results = kwargs.pop('results', [])
60 old_paw = kwargs.get('paw')
61 if old_paw:
62 kwargs['paw'] = await self._sanitize_paw(old_paw)
63 for agent in await self.get_service('data_svc').locate('agents', dict(paw=kwargs.get('paw', None))):
64 await agent.heartbeat_modification(**kwargs)
65 self.log.debug('Incoming %s beacon from %s' % (agent.contact, agent.paw))
66 for result in results:
67 self.log.debug('Received result for link %s from agent %s via contact %s' % (result['id'], agent.paw,
68 agent.contact))
69 await self._save(Result(**result))
70 operation = await self.get_service('app_svc').find_op_with_link(result['id'])
71 access = operation.access if operation else self.Access.RED
72 await self.get_service('event_svc').fire_event(exchange='link', queue='completed', agent=agent.display,
73 pid=result['pid'], link_id=result['id'],
74 access=access.value)
75 if results:
76 return agent, []
77 return agent, await self._get_instructions(agent)
78 agent = await self.get_service('data_svc').store(
79 Agent.load(dict(sleep_min=self.get_config(name='agents', prop='sleep_min'),
80 sleep_max=self.get_config(name='agents', prop='sleep_max'),
81 watchdog=self.get_config(name='agents', prop='watchdog'),
82 **kwargs))
83 )
84 await self._add_agent_to_operation(agent)
85 self.log.debug('First time %s beacon from %s' % (agent.contact, agent.paw))
86 data_svc = self.get_service('data_svc')
87 await agent.bootstrap(data_svc)
88 if agent.deadman_enabled:
89 self.log.debug("Agent %s can accept deadman abilities. Will return any available deadman abilities." %
90 agent.paw)
91 await agent.deadman(data_svc)
92 await self.get_service('event_svc').fire_event(exchange='agent', queue='added', agent=agent.display)
93 return agent, await self._get_instructions(agent)
94
95 async def build_filename(self):
96 return self.get_config(name='agents', prop='implant_name')

Callers 9

operation_loopMethod · 0.45
acceptMethod · 0.45
_accept_beaconMethod · 0.45
handle_beaconsMethod · 0.45
_beaconMethod · 0.45
handle_beaconsMethod · 0.45
_get_beacon_responseMethod · 0.45
runMethod · 0.45

Calls 15

_sanitize_pawMethod · 0.95
_saveMethod · 0.95
_get_instructionsMethod · 0.95
ResultClass · 0.90
get_serviceMethod · 0.80
bootstrapMethod · 0.80
deadmanMethod · 0.80
locateMethod · 0.45
find_op_with_linkMethod · 0.45
fire_eventMethod · 0.45

Tested by

no test coverage detected