当前位置: 首页>>代码示例>>Python>>正文


Python Observables.to_obj方法代码示例

本文整理汇总了Python中cybox.core.Observables.to_obj方法的典型用法代码示例。如果您正苦于以下问题:Python Observables.to_obj方法的具体用法?Python Observables.to_obj怎么用?Python Observables.to_obj使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cybox.core.Observables的用法示例。


在下文中一共展示了Observables.to_obj方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from cybox.core import Observables [as 别名]
# 或者: from cybox.core.Observables import to_obj [as 别名]
def main():
    '''Build a CybOX Observables document and write it to stdout'''
    domain = api.create_domain_name_observable('www.example.com')
    url = api.create_url_observable('http://www.example.com')
    ipv4 = api.create_ipv4_observable('127.0.0.1')
    email = api.create_email_address_observable('[email protected]')
    file_ = api.create_file_hash_observable('foo.bar','94f93e00fd122466d68a6ae3b8c7f908')

    observables_doc = Observables([
                                    domain,
                                    ipv4,
                                    url,
                                    email,
                                    file_,
                                  ])
    observables_doc.to_obj().export(sys.stdout, 0)

    pprint(observables_doc.to_dict())
开发者ID:2xyo,项目名称:python-cybox,代码行数:20,代码来源:demo.py

示例2: STIXPackage

# 需要导入模块: from cybox.core import Observables [as 别名]
# 或者: from cybox.core.Observables import to_obj [as 别名]

#.........这里部分代码省略.........
        """
        self.related_packages.append(related_package)

    def add(self, entity):
        """Adds `entity` to a top-level collection. For example, if `entity` is
        an Indicator object, the `entity` will be added to the ``indicators``
        top-level collection.

        """
        if utils.is_cybox(entity):
            self.add_observable(entity)
            return

        tlo_adds = {
            Campaign: self.add_campaign,
            CourseOfAction: self.add_course_of_action,
            ExploitTarget: self.add_exploit_target,
            Incident: self.add_incident,
            Indicator: self.add_indicator,
            ThreatActor: self.add_threat_actor,
            TTP: self.add_ttp,
            Report: self.add_report,
            Observable: self.add_observable,
        }

        try:
            add = tlo_adds[entity.__class__]
            add(entity)
        except KeyError:
            error = "Cannot add type '{0}' to a top-level collection"
            error = error.format(type(entity))
            raise TypeError(error)

    def to_obj(self, return_obj=None, ns_info=None):
        super(STIXPackage, self).to_obj(return_obj=return_obj, ns_info=ns_info)

        if not return_obj:
            return_obj = self._binding_class()

        return_obj.id = self.id_
        return_obj.idref = self.idref
        return_obj.version = STIXPackage._version  # noqa
        return_obj.timestamp = utils.dates.serialize_value(self.timestamp)

        if self.stix_header:
            return_obj.STIX_Header = self.stix_header.to_obj(ns_info=ns_info)
        if self.campaigns:
            return_obj.Campaigns = self.campaigns.to_obj(ns_info=ns_info)
        if self.courses_of_action:
            return_obj.Courses_Of_Action = self.courses_of_action.to_obj(ns_info=ns_info)
        if self.exploit_targets:
            return_obj.Exploit_Targets = self.exploit_targets.to_obj(ns_info=ns_info)
        if self.indicators:
            return_obj.Indicators = self.indicators.to_obj(ns_info=ns_info)
        if self.observables:
            return_obj.Observables = self.observables.to_obj(ns_info=ns_info)
        if self.incidents:
            return_obj.Incidents = self.incidents.to_obj(ns_info=ns_info)
        if self.threat_actors:
            return_obj.Threat_Actors = self.threat_actors.to_obj(ns_info=ns_info)
        if self.ttps:
            return_obj.TTPs = self.ttps.to_obj(ns_info=ns_info)
        if self.related_packages:
            return_obj.Related_Packages = self.related_packages.to_obj(ns_info=ns_info)
        if self.reports:
            return_obj.Reports = self.reports.to_obj(ns_info=ns_info)
开发者ID:shinsec,项目名称:python-stix,代码行数:70,代码来源:stix_package.py

示例3: STIXPackage

# 需要导入模块: from cybox.core import Observables [as 别名]
# 或者: from cybox.core.Observables import to_obj [as 别名]

#.........这里部分代码省略.........
    
    def add_ttp(self, ttp):
        self.ttps.append(ttp)

    def add(self, entity):
        """Adds `entity` to a top-level collection. For example, if `entity` is
        an Indicator object, the `entity` will be added to the ``indicators``
        top-level collection.

        """
        if utils.is_cybox(entity):
            self.add_observable(entity)
            return

        tlo_adds = {
            Campaign: self.add_campaign,
            CourseOfAction: self.add_course_of_action,
            ExploitTarget: self.add_exploit_target,
            Incident: self.add_incident,
            Indicator: self.add_indicator,
            ThreatActor: self.add_threat_actor,
            TTP: self.add_threat_actor,
            Observable: self.add_observable,
        }

        try:
            add = tlo_adds[entity.__class__]
            add(entity)
        except KeyError:
            error = "Cannot add type '{0}' to a top-level collection"
            error = error.format(type(entity))
            raise TypeError(error)

    def to_obj(self, return_obj=None, ns_info=None):
        super(STIXPackage, self).to_obj(return_obj=return_obj, ns_info=ns_info)

        if not return_obj:
            return_obj = self._binding_class()

        return_obj.id = self.id_
        return_obj.idref = self.idref
        return_obj.version = self.version
        return_obj.timestamp = utils.dates.serialize_value(self.timestamp)

        if self.stix_header:
            return_obj.STIX_Header = self.stix_header.to_obj(ns_info=ns_info)
        if self.campaigns:
            return_obj.Campaigns = self.campaigns.to_obj(ns_info=ns_info)
        if self.courses_of_action:
            return_obj.Courses_Of_Action = self.courses_of_action.to_obj(ns_info=ns_info)
        if self.exploit_targets:
            return_obj.Exploit_Targets = self.exploit_targets.to_obj(ns_info=ns_info)
        if self.indicators:
            return_obj.Indicators = self.indicators.to_obj(ns_info=ns_info)
        if self.observables:
            return_obj.Observables = self.observables.to_obj(ns_info=ns_info)
        if self.incidents:
            return_obj.Incidents = self.incidents.to_obj(ns_info=ns_info)
        if self.threat_actors:
            return_obj.Threat_Actors = self.threat_actors.to_obj(ns_info=ns_info)
        if self.ttps:
            return_obj.TTPs = self.ttps.to_obj(ns_info=ns_info)
        if self.related_packages:
            return_obj.Related_Packages = self.related_packages.to_obj(ns_info=ns_info)
             
        return return_obj
开发者ID:andybarilla,项目名称:python-stix,代码行数:70,代码来源:stix_package.py

示例4: STIXPackage

# 需要导入模块: from cybox.core import Observables [as 别名]
# 或者: from cybox.core.Observables import to_obj [as 别名]

#.........这里部分代码省略.........
    def add_exploit_target(self, exploit_target):
        if not exploit_target:
            return
        elif isinstance(exploit_target, ExploitTarget):
            self._exploit_targets.append(exploit_target)
        else:
            raise ValueError('Cannot add %s to exploit target list' % type(exploit_target))

    @property
    def ttps(self):
        return self._ttps
    
    @ttps.setter
    def ttps(self, value):
        if not value:
            self._ttps = None
        elif isinstance(value, TTPs):
            self._ttps = value
        elif isinstance(value, list):
            for v in value:
                self.add_ttp(v)
        else:
            self.add_ttp(value)
    
    def add_ttp(self, ttp):
        if not ttp:
            return 
        if not self.ttps:
            self.ttps = TTPs()
        
        self.ttps.add_ttp(ttp)
   

    def to_obj(self, return_obj=None):
        if not return_obj:
            return_obj = self._binding_class()

        return_obj.set_id(self.id_)
        return_obj.set_idref(self.idref)
        return_obj.set_version(self.version)
        return_obj.set_timestamp(dates.serialize_value(self.timestamp))

        if self.stix_header:
            return_obj.set_STIX_Header(self.stix_header.to_obj())
        
        if self.campaigns:
            coas_obj = self._binding.CampaignsType()
            coas_obj.set_Campaign([x.to_obj() for x in self.campaigns])
            return_obj.set_Campaigns(coas_obj)
            
        if self.courses_of_action:
            coas_obj = self._binding.CoursesOfActionType()
            coas_obj.set_Course_Of_Action([x.to_obj() for x in self.courses_of_action])
            return_obj.set_Courses_Of_Action(coas_obj)
        
        if self.exploit_targets:
            et_obj = stix_common_binding.ExploitTargetsType()
            et_obj.set_Exploit_Target([x.to_obj() for x in self.exploit_targets])
            return_obj.set_Exploit_Targets(et_obj)
            
        if self.indicators:
            indicators_obj = self._binding.IndicatorsType()
            indicators_obj.set_Indicator([x.to_obj() for x in self.indicators])
            return_obj.set_Indicators(indicators_obj)

        if self.observables:
开发者ID:SYNchroACK,项目名称:crits_dependencies,代码行数:70,代码来源:stix_package.py

示例5: STIXPackage

# 需要导入模块: from cybox.core import Observables [as 别名]
# 或者: from cybox.core.Observables import to_obj [as 别名]
class STIXPackage(stix.Entity):
    '''
    classdocs
    '''

    def __init__(self, id_=None, idref_=None, stix_header=None, indicators=None, observables=None):
        '''
        Constructor
        '''
        self.id_ = id_ if id_ else stix.utils.create_id() 
        self.idref_ = idref_
        self.version = '1.0'
        self.indicators = indicators
        self.observables = observables
        self.stix_header = stix_header
    
    @property
    def stix_header(self):
        return self._stix_header
    
    @stix_header.setter
    def stix_header(self, value):
        if value and not isinstance(value, STIXHeader):
            raise ValueError('value must be instance of STIXHeader')
        
        self._stix_header = value
    
    @property
    def indicators(self):
        return self._indicators
    
    @indicators.setter
    def indicators(self, valuelist):
        self._indicators = [] # initialize
        
        if valuelist:   
            for value in valuelist:
                self.add_indicator(value)
    
    @property
    def observables(self):
        return self._observables
    
    @observables.setter
    def observables(self, value):
        if value and not isinstance(value, Observables):
            raise ValueError('value must be instance of cybox.core.Observables')
            
        self._observables = value
        
    def add_indicator(self, indicator):
        if indicator and not isinstance(indicator, Indicator):
            raise ValueError('indicator must be instance of stix.indicator.Indicator')
    
        self.indicators.append(indicator)
        
    def add_observable(self, observable):
        if not self.observables:
            self.observables = Observables(observable)
        else:
            self.observables.add(observable)
        
    def to_obj(self, return_obj=None):
        if not return_obj:
            return_obj = stix_core_binding.STIXType()
        
        return_obj.set_id(self.id_)
        return_obj.set_idref(self.idref_)
        return_obj.set_version(self.version)
        
        if self.stix_header:
            return_obj.set_STIX_Header(self.stix_header.to_obj())
        
        if self.indicators:
            indicators_obj = stix_core_binding.IndicatorsType()
            
            for indicator in self.indicators:
                indicators_obj.add_Indicator(indicator.to_obj())
            
            return_obj.set_Indicators(indicators_obj)
        
        if self.observables:
            observables_obj = self.observables.to_obj()
            return_obj.set_Observables(observables_obj)
        
        return return_obj
    
    def to_dict(self, return_dict=None):
        if not return_dict:
            return_dict = {}
        
        if self.id_:
            return_dict['id'] = self.id_
            
        return_dict['version'] = self.version
        
        if self.idref_:
            return_dict['idref'] = self.idref_
        
        if self.stix_header:
#.........这里部分代码省略.........
开发者ID:DKBlack,项目名称:python-stix,代码行数:103,代码来源:stix_package.py

示例6: STIXPackage

# 需要导入模块: from cybox.core import Observables [as 别名]
# 或者: from cybox.core.Observables import to_obj [as 别名]

#.........这里部分代码省略.........
    def add_exploit_target(self, exploit_target):
        if not exploit_target:
            return
        elif isinstance(exploit_target, ExploitTarget):
            self._exploit_targets.append(exploit_target)
        else:
            raise ValueError('Cannot add %s to exploit target list' % type(exploit_target))

    @property
    def ttps(self):
        return self._ttps
    
    @ttps.setter
    def ttps(self, value):
        if not value:
            self._ttps = TTPs()
        elif isinstance(value, TTPs):
            self._ttps = value
        elif isinstance(value, list):
            for v in value:
                self.add_ttp(v)
        else:
            self.add_ttp(value)
    
    def add_ttp(self, ttp):
        if not ttp:
            return 
        if not self.ttps:
            self.ttps = TTPs()
        
        self.ttps.append(ttp)
   

    def to_obj(self, return_obj=None, ns_info=None):
        super(STIXPackage, self).to_obj(return_obj=return_obj, ns_info=ns_info)

        if not return_obj:
            return_obj = self._binding_class()

        return_obj.id = self.id_
        return_obj.idref = self.idref
        return_obj.version = self.version
        return_obj.timestamp = dates.serialize_value(self.timestamp)

        if self.stix_header:
            return_obj.STIX_Header = self.stix_header.to_obj(ns_info=ns_info)
        
        if self.campaigns:
            coas_obj = self._binding.CampaignsType()
            coas_obj.Campaign = [x.to_obj(ns_info=ns_info) for x in self.campaigns]
            return_obj.Campaigns = coas_obj
            
        if self.courses_of_action:
            coas_obj = self._binding.CoursesOfActionType()
            coas_obj.Course_Of_Action = [x.to_obj(ns_info=ns_info) for x in self.courses_of_action]
            return_obj.Courses_Of_Action = coas_obj
        
        if self.exploit_targets:
            et_obj = stix_common_binding.ExploitTargetsType()
            et_obj.Exploit_Target = [x.to_obj(ns_info=ns_info) for x in self.exploit_targets]
            return_obj.Exploit_Targets = et_obj
            
        if self.indicators:
            indicators_obj = self._binding.IndicatorsType()
            indicators_obj.Indicator = [x.to_obj(ns_info=ns_info) for x in self.indicators]
            return_obj.Indicators = indicators_obj
开发者ID:Seevil,项目名称:python-stix,代码行数:70,代码来源:stix_package.py

示例7: Report

# 需要导入模块: from cybox.core import Observables [as 别名]
# 或者: from cybox.core.Observables import to_obj [as 别名]

#.........这里部分代码省略.........

        """
        self.related_reports.append(related_report)

    def add(self, entity):
        """Adds `entity` to a top-level collection. For example, if `entity` is
        an Indicator object, the `entity` will be added to the ``indicators``
        top-level collection.

        """
        if utils.is_cybox(entity):
            self.add_observable(entity)
            return

        tlo_adds = {
            Campaign: self.add_campaign,
            CourseOfAction: self.add_course_of_action,
            ExploitTarget: self.add_exploit_target,
            Incident: self.add_incident,
            Indicator: self.add_indicator,
            ThreatActor: self.add_threat_actor,
            TTP: self.add_threat_actor,
            Observable: self.add_observable,
        }

        try:
            add = tlo_adds[entity.__class__]
            add(entity)
        except KeyError:
            error = "Cannot add type '{0}' to a top-level collection"
            error = error.format(type(entity))
            raise TypeError(error)

    def to_obj(self, return_obj=None, ns_info=None):
        super(Report, self).to_obj(return_obj=return_obj, ns_info=ns_info)

        if not return_obj:
            return_obj = self._binding_class()

        return_obj.id = self.id_
        return_obj.idref = self.idref
        return_obj.version = self.version
        return_obj.timestamp = utils.dates.serialize_value(self.timestamp)

        if self.header:
            return_obj.Header = self.header.to_obj(ns_info=ns_info)
        if self.campaigns:
            return_obj.Campaigns = self.campaigns.to_obj(ns_info=ns_info)
        if self.courses_of_action:
            return_obj.Courses_Of_Action = self.courses_of_action.to_obj(ns_info=ns_info)
        if self.exploit_targets:
            return_obj.Exploit_Targets = self.exploit_targets.to_obj(ns_info=ns_info)
        if self.indicators:
            return_obj.Indicators = self.indicators.to_obj(ns_info=ns_info)
        if self.observables:
            return_obj.Observables = self.observables.to_obj(ns_info=ns_info)
        if self.incidents:
            return_obj.Incidents = self.incidents.to_obj(ns_info=ns_info)
        if self.threat_actors:
            return_obj.Threat_Actors = self.threat_actors.to_obj(ns_info=ns_info)
        if self.ttps:
            return_obj.TTPs = self.ttps.to_obj(ns_info=ns_info)
        if self.related_reports:
            return_obj.Related_Reports = self.related_reports.to_obj(ns_info=ns_info)
             
        return return_obj
开发者ID:thurday,项目名称:python-stix,代码行数:70,代码来源:__init__.py


注:本文中的cybox.core.Observables.to_obj方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。