Exemplo n.º 1
0
 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
Exemplo n.º 2
0
 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
Exemplo n.º 3
0
 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()]))
Exemplo n.º 4
0
def replaced_objective_payload(test_objective):
    objective_data = test_objective.schema.dump(test_objective)
    test_goal = Goal(target='replaced target', value='in_progress')
    objective_data.update(
        dict(name='replaced test objective',
             description='a test objective that has been replaced',
             goals=[test_goal.schema.dump(test_goal)]))
    return objective_data
Exemplo n.º 5
0
def updated_objective_payload(test_objective, test_goal):
    objective_data = test_objective.schema.dump(test_objective)
    updated_goal = Goal(target='updated target', value='complete')
    objective_data.update(
        dict(name='an updated test objective',
             description='a test objective that has been updated',
             goals=[updated_goal.schema.dump(updated_goal)]))
    return objective_data
Exemplo n.º 6
0
def new_objective_payload():
    test_goal = Goal(target='new goal', value='in_progress')
    return {
        'id': '456',
        'name': 'new test objective',
        'description': 'a new test objective',
        'goals': [test_goal.schema.dump(test_goal)]
    }
Exemplo n.º 7
0
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')
    ))
Exemplo n.º 8
0
def test_goal():
    return Goal(target='test target', value='in_progress')
Exemplo n.º 9
0
 def test_satisfied(self):
     test_goal = Goal(target='target', value='value', count=1)
     assert test_goal.satisfied() is False
     assert test_goal.satisfied(
         all_facts=[Fact(trait='target', value='value')]) is True
Exemplo n.º 10
0
 def test_operators(self):
     test_goal1 = Goal(target='target', value=2, count=1, operator='>')
     test_goal2 = Goal(target='target', value=2, count=1, operator='<=')
     test_goal3 = Goal(target='target', value='tes', count=1, operator='in')
     test_goal4 = Goal(target='target', value='', count=3, operator='*')
     test_facta = Fact(trait='target', value=1)
     test_factb = Fact(trait='target', value=2)
     test_factc = Fact(trait='target', value='test')
     assert test_goal1.satisfied(all_facts=[test_facta]) is True
     assert test_goal2.satisfied(all_facts=[test_facta]) is False
     assert test_goal2.satisfied(all_facts=[test_facta, test_factb]) is True
     assert test_goal3.satisfied(all_facts=[test_factc]) is True
     assert test_goal4.satisfied(
         all_facts=[test_facta, test_factb, test_factc]) is True
Exemplo n.º 11
0
 def test_multi_satisfied(self):
     test_goal = Goal(target='target', value='value', count=3)
     test_fact = Fact(trait='target', value='value')
     assert test_goal.satisfied(all_facts=[test_fact]) is False
     assert test_goal.satisfied(
         all_facts=[test_fact, test_fact, test_fact]) is True