async def select_cleanup_links(self, operation, agent): """ For a given operation, select all cleanup links :param operation: :param agent: :return: None """ link_status = await self._default_link_status(operation) if (not agent.trusted) and (not operation.allow_untrusted): self.log.debug('Agent %s untrusted: no cleanup-link created' % agent.paw) return links = [] for link in [l for l in operation.chain if l.paw == agent.paw]: ability = (await self.get_service('data_svc').locate( 'abilities', match=dict(unique=link.ability.unique)))[0] if ability.cleanup and link.status >= 0: links.append( Link(operation=operation.name, command=ability.cleanup, paw=agent.paw, cleanup=1, ability=ability, score=0, jitter=0, status=link_status)) return reversed(await self._trim_links(operation, links, agent))
async def select_links(self, operation, agent, phase): """ For an operation, phase and agent combination, determine which (potential) links can be executed :param operation: :param agent: :param phase: :return: a list of links """ if (not agent.trusted) and (not operation.allow_untrusted): self.log.debug('Agent %s untrusted: no link created' % agent.paw) return [] phase_abilities = [ i for p, v in operation.adversary.phases.items() if p <= phase for i in v ] link_status = await self._default_link_status(operation) links = [] for a in await agent.capabilities(phase_abilities): links.append( Link(operation=operation.name, command=a.test, paw=agent.paw, score=0, ability=a, status=link_status, jitter=self.jitter(operation.jitter))) ability_requirements = { ab.unique: ab.requirements for ab in phase_abilities } links[:] = await self._trim_links(operation, links, agent, ability_requirements) return await self._sort_links(links)
async def _generate_new_links(self, operation, agent, abilities, link_status): links = [] for a in await agent.capabilities(abilities): links.append( Link(operation=operation.id, command=a.test, paw=agent.paw, score=0, ability=a, status=link_status, jitter=self.jitter(operation.jitter)) ) self.log.debug('Generated %s links for %s' % (len(links), agent.paw)) return links
async def _generate_cleanup_links(self, operation, agent, link_status): links = [] for link in [l for l in operation.chain if l.paw == agent.paw]: ability = (await self.get_service('data_svc').locate('abilities', match=dict(unique=link.ability.unique)))[0] if ability.cleanup and link.status >= 0: links.append(Link(operation=operation.id, command=ability.cleanup, paw=agent.paw, cleanup=1, ability=ability, score=0, jitter=0, status=link_status)) return links
def setUp(self): self.command = 'd2hvYW1p' dummy_ability = Ability(ability_id=None, tactic=None, technique_id=None, technique=None, name=None, test=None, description=None, cleanup=None, executor='sh', platform=None, payload=None, parsers=None, requirements=None, privilege=None) self.dummy_agent = Agent(paw='123', platform='linux', executors=['sh']) self.dummy_link = Link(operation=None, command=self.command, paw='123', ability=dummy_ability)
async def apply_potential_link(self, l): link = Link.from_json(l) operation = (await self.get_service('data_svc').locate( 'operations', match=dict(id=link.operation)))[0] await operation.apply(link)