(self, **kwargs)
| 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') |
no test coverage detected