Example #1
0
def convert_threat_actor(ta20):
    ta1x = ThreatActor(id_=convert_id20(ta20["id"]),
                       timestamp=text_type(ta20["modified"]))
    ta1x.title = ta20["name"]
    types = convert_open_vocabs_to_controlled_vocabs(ta20["labels"],
                                                     THREAT_ACTOR_LABEL_MAP)
    for t in types:
        ta1x.add_type(t)
    if "description" in ta20:
        ta1x.add_description(ta20["description"])
    if "aliases" in ta20:
        add_missing_list_property_to_description(ta1x, "aliases",
                                                 ta20["aliases"])
    if "roles" in ta20:
        add_missing_list_property_to_description(ta1x, "roles", ta20["roles"])
    if "goals" in ta20:
        for g in ta20["goals"]:
            ta1x.add_intended_effect(g)
    if "sophistication" in ta20:
        sophistications = convert_open_vocabs_to_controlled_vocabs(
            [ta20["sophistication"]], THREAT_ACTOR_SOPHISTICATION_MAP)
        for s in sophistications:
            ta1x.add_sophistication(s)
    if "resource_level" in ta20:
        add_missing_list_property_to_description(ta1x, "resource_level",
                                                 ta20["resource_level"])
    all_motivations = []
    if "primary_motivation" in ta20:
        all_motivations = [ta20["primary_motivation"]]
    if "secondary_motivation" in ta20:
        all_motivations.extend(ta20["secondary_motivation"])
    if "personal_motivation" in ta20:
        all_motivations.extend(ta20["personal_motivation"])
    motivations = convert_open_vocabs_to_controlled_vocabs(
        all_motivations, ATTACK_MOTIVATION_MAP)
    for m in motivations:
        ta1x.add_motivation(m)
    if "object_marking_refs" in ta20:
        for m_id in ta20["object_marking_refs"]:
            ms = create_marking_specification(m_id)
            if ms:
                CONTAINER.add_marking(ta1x, ms, descendants=True)
    if "granular_markings" in ta20:
        error(
            "Granular Markings present in '%s' are not supported by stix2slider",
            604, ta20["id"])
    record_id_object_mapping(ta20["id"], ta1x)
    return ta1x