def _fix_value(self, value): from stix.campaign import Campaign if isinstance(value, Campaign) and value.id_: return RelatedCampaignRef(CampaignRef(idref=value.id_)) else: return super(RelatedCampaignRefs, self)._fix_value(value)
def main(): # Build Campaign instances camp1 = Campaign(title='Campaign 1') camp2 = Campaign(title='Campaign 2') # Build a CampaignRef object, setting the `idref` to the `id_` value of # our `camp2` Campaign object. campaign_ref = CampaignRef(idref=camp2.id_) # Build an Indicator object. i = Indicator() # Add CampaignRef object pointing to `camp2`. i.add_related_campaign(campaign_ref) # Add Campaign object, which gets promoted into an instance of # CampaignRef type internally. Only the `idref` is set. i.add_related_campaign(camp1) # Build our STIX Package and attach our Indicator and Campaign objects. package = STIXPackage() package.add_indicator(i) package.add_campaign(camp1) package.add_campaign(camp2) # Print! print package.to_xml()
def _fix_value(self, value): from stix.campaign import Campaign if isinstance(value, Campaign) and value.id_: return RelatedCampaignRef(CampaignRef(idref=value.id_)) msg = "Cannot insert object of type '%s' into '%s'" msg = msg % (type(value), self.__class__.__name__) raise TypeError(msg)
# Related Threat Actor (by id) ta = ThreatActor(title='Albino Rhino') attrib_ta = Attribution() attrib_ta.append(ThreatActor(idref=ta.id_)) campaign.attribution.append(attrib_ta) # Related Campaign (basic; by id) campaign2 = Campaign(title='Another Campaign') cassoc_campaign = CAssociatedCampaigns() cassoc_campaign.append(RelatedCampaign(Campaign(idref=campaign2.id_))) campaign.associated_campaigns = cassoc_campaign # Related Other Objects to Campaign (by id) campaign3 = Campaign(title='Another Another Campaign') tassoc_campaign = TAssociatedCampaigns() tassoc_campaign.append(RelatedCampaign(Campaign(idref=campaign3.id_))) ta.associated_campaigns = tassoc_campaign r = RelatedCampaignRef(CampaignRef(idref=campaign3.id_)) indicator.add_related_campaign(r) # Generate STIX Package stix_package = STIXPackage() stix_package.add_campaign(campaign) stix_package.add_ttp(ttp) stix_package.add_incident(incident) stix_package.add_indicator(indicator) stix_package.add_threat_actor(ta) stix_package.add_campaign(campaign2) print(stix_package.to_xml().decode())