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


Python Observables.to_dict方法代码示例

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


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

示例1: test_round_trip

# 需要导入模块: from cybox.core import Observables [as 别名]
# 或者: from cybox.core.Observables import to_dict [as 别名]
    def test_round_trip(self):
        a = Address("[email protected]", Address.CAT_EMAIL)
        a2 = Address("[email protected]", Address.CAT_EMAIL)

        ms = MeasureSource()
        ms.class_ = "System"
        ms.source_type = "Analysis"
        ms.description = StructuredText("A Description")

        o = Observables([a, a2])
        o.observable_package_source = ms

        o2 = round_trip(o, output=True)
        self.assertEqual(o.to_dict(), o2.to_dict())
开发者ID:luisgf,项目名称:watsondt,代码行数:16,代码来源:observable_test.py

示例2: main

# 需要导入模块: from cybox.core import Observables [as 别名]
# 或者: from cybox.core.Observables import to_dict [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

示例3: STIXPackage

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

#.........这里部分代码省略.........
            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:
            return_obj.set_Observables(self.observables.to_obj())

        if self.incidents:
            incidents_obj = self._binding.IncidentsType()
            incidents_obj.set_Incident([x.to_obj() for x in self.incidents])
            return_obj.set_Incidents(incidents_obj)
        if self.threat_actors:
            threat_actors_obj = self._binding.ThreatActorsType()
            threat_actors_obj.set_Threat_Actor([x.to_obj() for x in self.threat_actors])
            return_obj.set_Threat_Actors(threat_actors_obj)
        
        if self.ttps:
            return_obj.set_TTPs(self.ttps.to_obj())
           
        if self.related_packages:
            return_obj.set_Related_Packages(self.related_packages.to_obj())
             
        return return_obj

    def to_dict(self):
        d = {}
        if self.id_:
            d['id'] = self.id_
        if self.idref:
            d['idref'] = self.idref
        if self.version:
            d['version'] = self.version
        if self.idref:
            d['idref'] = self.idref
        if self.timestamp:
            d['timestamp'] = dates.serialize_value(self.timestamp)
        if self.stix_header:
            d['stix_header'] = self.stix_header.to_dict()
        if self.campaigns:
            d['campaigns'] = [x.to_dict() for x in self.campaigns]
        if self.courses_of_action:
            d['courses_of_action'] = [x.to_dict() for x in self.courses_of_action]
        if self.exploit_targets:
            d['exploit_targets'] = [x.to_dict() for x in self.exploit_targets]
        if self.indicators:
            d['indicators'] = [x.to_dict() for x in self.indicators]
        if self.observables:
            d['observables'] = self.observables.to_dict()
        if self.incidents:
            d['incidents'] = [x.to_dict() for x in self.incidents]
        if self.threat_actors:
            d['threat_actors'] = [x.to_dict() for x in self.threat_actors]
        if self.ttps:
            d['ttps'] = self.ttps.to_dict()
        if self.related_packages:
            d['related_packages'] = self.related_packages.to_dict()
开发者ID:SYNchroACK,项目名称:crits_dependencies,代码行数:69,代码来源:stix_package.py

示例4: STIXPackage

# 需要导入模块: from cybox.core import Observables [as 别名]
# 或者: from cybox.core.Observables import to_dict [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

示例5: STIXPackage

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

#.........这里部分代码省略.........
            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

        if self.observables:
            return_obj.Observables = self.observables.to_obj(ns_info=ns_info)

        if self.incidents:
            incidents_obj = self._binding.IncidentsType()
            incidents_obj.Incident = [x.to_obj(ns_info=ns_info) for x in self.incidents]
            return_obj.Incidents = incidents_obj
        if self.threat_actors:
            threat_actors_obj = self._binding.ThreatActorsType()
            threat_actors_obj.Threat_Actor = [x.to_obj(ns_info=ns_info) for x in self.threat_actors]
            return_obj.Threat_Actors = threat_actors_obj
        
        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

    def to_dict(self):
        d = {}
        if self.id_:
            d['id'] = self.id_
        if self.idref:
            d['idref'] = self.idref
        if self.version:
            d['version'] = self.version
        if self.idref:
            d['idref'] = self.idref
        if self.timestamp:
            d['timestamp'] = dates.serialize_value(self.timestamp)
        if self.stix_header:
            d['stix_header'] = self.stix_header.to_dict()
        if self.campaigns:
            d['campaigns'] = [x.to_dict() for x in self.campaigns]
        if self.courses_of_action:
            d['courses_of_action'] = [x.to_dict() for x in self.courses_of_action]
        if self.exploit_targets:
            d['exploit_targets'] = [x.to_dict() for x in self.exploit_targets]
        if self.indicators:
            d['indicators'] = [x.to_dict() for x in self.indicators]
        if self.observables:
            d['observables'] = self.observables.to_dict()
        if self.incidents:
            d['incidents'] = [x.to_dict() for x in self.incidents]
        if self.threat_actors:
            d['threat_actors'] = [x.to_dict() for x in self.threat_actors]
        if self.ttps:
            d['ttps'] = self.ttps.to_dict()
        if self.related_packages:
            d['related_packages'] = self.related_packages.to_dict()
开发者ID:Seevil,项目名称:python-stix,代码行数:69,代码来源:stix_package.py


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