def test_objective(loop, test_goal): objective = Objective(id='123', name='test objective', description='a test objective', goals=[test_goal]) loop.run_until_complete( BaseService.get_service('data_svc').store(objective)) return objective
async def _verify_default_objective_exists(self): if not await self.locate('objectives', match=dict(name='default')): await self.store( Objective(id='495a9828-cab1-44dd-a0ca-66e58177d8cc', name='default', description= 'This is a default objective that runs forever.', goals=[Goal()]))
def test_goals_percent(self): test_goal1 = Goal(target='target', value='value', count=1) test_goal2 = Goal(target='target2', value='value2', count=1) test_fact = Fact(trait='target', value='value') multi = Objective(id='123', name='test', goals=[test_goal1, test_goal2]) assert multi.completed([test_fact]) is False assert multi.percentage == 50
def setup_empty_operation(event_loop, test_operation): test_operation = OperationSchema().load(test_operation) test_operation.set_start_details() test_objective = Objective(id='123', name='test objective', description='test', goals=[]) test_operation.objective = test_objective event_loop.run_until_complete( BaseService.get_service('data_svc').store(test_operation))
def test_goals_satisfied(self): test_goal1 = Goal(target='target', value='value', count=1) test_goal2 = Goal(target='target2', value='value2', count=1) test_facta = Fact(trait='target', value='value') test_factb = Fact(trait='target2', value='value2') multi = Objective(id='123', name='test', goals=[test_goal1, test_goal2]) assert multi.completed([test_facta]) is False assert multi.completed([test_facta, test_factb]) is True
def setup_rest_svc_test(loop, data_svc): BaseWorld.apply_config(name='main', config={'app.contact.http': '0.0.0.0', 'plugins': ['sandcat', 'stockpile'], 'crypt_salt': 'BLAH', 'api_key': 'ADMIN123', 'encryption_key': 'ADMIN123', 'exfil_dir': '/tmp'}) loop.run_until_complete(data_svc.store( Ability(ability_id='123', name='testA', executors=[ Executor(name='psh', platform='windows', command='curl #{app.contact.http}') ]) )) loop.run_until_complete(data_svc.store( Ability(ability_id='456', name='testB', executors=[ Executor(name='sh', platform='linux', command='whoami') ]) )) loop.run_until_complete(data_svc.store( Ability(ability_id='789', name='testC', executors=[ Executor(name='sh', platform='linux', command='hostname') ]) )) adversary = Adversary(adversary_id='123', name='test', description='test', atomic_ordering=[]) loop.run_until_complete(data_svc.store(adversary)) agent = Agent(paw='123', sleep_min=2, sleep_max=8, watchdog=0, executors=['pwsh', 'psh'], platform='windows') loop.run_until_complete(data_svc.store(agent)) loop.run_until_complete(data_svc.store( Objective(id='495a9828-cab1-44dd-a0ca-66e58177d8cc', name='default', goals=[Goal()]) )) loop.run_until_complete(data_svc.store( Planner(planner_id='123', name='test', module='test', params=dict()) )) source = Source(id='123', name='test', facts=[], adjustments=[]) loop.run_until_complete(data_svc.store(source)) loop.run_until_complete(data_svc.store( Operation(name='test', agents=[agent], adversary=adversary, id='123', source=source) )) loop.run_until_complete(data_svc.store( Obfuscator(name='plain-text', description='Does no obfuscation to any command, instead running it in plain text', module='plugins.stockpile.app.obfuscators.plain_text') ))
def setup_operations_api_test(event_loop, api_v2_client, test_operation, test_agent, test_ability, active_link, finished_link, expected_link_output): test_operation = OperationSchema().load(test_operation) test_operation.agents.append(test_agent) test_operation.set_start_details() test_link = Link.load(active_link) test_link.host = test_agent.host finished_link = Link.load(finished_link) finished_link.output = expected_link_output finished_link.host = test_agent.host test_operation.chain.append(test_link) test_operation.chain.append(finished_link) test_objective = Objective(id='123', name='test objective', description='test', goals=[]) test_operation.objective = test_objective event_loop.run_until_complete( BaseService.get_service('data_svc').store(test_operation))
def op_with_learning_and_seeded(ability, adversary, operation_agent, parse_datestring): sc = Source(id='3124', name='test', facts=[Fact(trait='domain.user.name', value='bob')]) op = Operation(id='6789', name='testC', agents=[], adversary=adversary, source=sc, use_learning_parsers=True) # patch operation to make it 'realistic' op.start = parse_datestring(OP_START_TIME) op.adversary = op.adversary() op.planner = Planner(planner_id='12345', name='test_planner', module='not.an.actual.planner', params=None) op.objective = Objective(id='6428', name='not_an_objective') t_operation_agent = operation_agent t_operation_agent.paw = '123456' op.agents = [t_operation_agent] return op