コード例 #1
0
def get_tactics_and_techniques(tactic_names=None, tactic_ids=None, opts=None, function_opts=None):
    """
    Get techniques for all input tactics
    :param tactic_names:    string of tactic names separated by comma
    :param tactic_ids:      string of tactic ids separated by comma
    :param opts:            Top level configuration options
    :param function_opts:   Function configuration options.
    :return:                techniques
    """
    mitre_conn = MitreAttackConnection(opts, function_opts)

    tactics = []

    # Check ids first, as it takes priority in querying
    if tactic_ids is not None:
        t_ids = tactic_ids.split(',')

        for tid in t_ids:
            tactics_id = MitreAttackTactic.get_by_id(mitre_conn, tid)
            if tactics_id is not None:
                for tactic in tactics_id:
                    tactics.append(tactic.id)
            else:
                raise ValueError("Tactics with id {} do not exist.".format(tid))
    elif tactic_names is not None:
        # It's possible for multiple tactics to have the same name
        # And we want to make sure that all of them are processed in that case
        tactic_names = tactic_names.split(',')

        for t_name in tactic_names:
            tactics_named = MitreAttackTactic.get_by_name(mitre_conn, t_name)
            if not tactics_named:
                raise ValueError("Tactics with name {} do not exist.".format(t_name))
            else:
                for tactic in tactics_named:
                    tactics.append(tactic.id)

    ret = []
    for tactic_id in tactics:
        t_obj = MitreAttackTactic.get_by_id(mitre_conn, tactic_id)[0]  # since we search by id, its unique

        techs = t_obj.get_techniques(mitre_conn)

        # get the dict for tactic and include techniques into it
        tactic_dict = t_obj.dict_form()
        tactic_dict.update({
            "mitre_techniques": [tech.dict_form() for tech in techs]
        })

        ret.append(tactic_dict)
    return ret
コード例 #2
0
 def test_extra_spaces_doent_fail_search(self):
     assert MitreAttackTactic.get_by_id(self.mitre_attack,
                                        " TA0007") is not None
     assert MitreAttackTactic.get_by_name(self.mitre_attack,
                                          " Collection  ") is not None
コード例 #3
0
 def test_get_by_id_works(self):
     assert MitreAttackTactic.get_by_id(self.mitre_attack,
                                        "TA0007") is not None
     assert MitreAttackTactic.get_by_id(self.mitre_attack,
                                        "TA00007") is None