예제 #1
0
 def populate(self, json):
   self.title = json.get('title', None)
   self.description = json.get('description', None)
   self.properties.populate(json.get('properties', None))
   self.short_description = json.get('short_description', None)
   self.identifier = json.get('identifier', None)
   self.properties.populate(json.get('properties', None))
   creator_group = json.get('creator_group', None)
   if creator_group:
     cg_instance = Group()
     cg_instance.populate(creator_group)
     self.creator_group = cg_instance
   modifier_group = json.get('modifier_group', None)
   if modifier_group:
     cg_instance = Group()
     cg_instance.populate(modifier_group)
     self.modifier = cg_instance
   created_at = json.get('created_at', None)
   if created_at:
     self.created_at = strings.stringToDateTime(created_at)
   modified_on = json.get('modified_on', None)
   if modified_on:
     self.modified_on = strings.stringToDateTime(modified_on)
   references = json.get('references', None)
   if references:
     for reference in references:
       ref = Reference()
       ref.populate(reference)
       self.references.append(ref)
예제 #2
0
 def populate(self, json):
   definition_id = json.get('definition_id', None)
   if definition_id:
     self.definition_id = definition_id
     definition = json.get('definition', None)
     if definition:
       definitin_instance = ReferenceDefinition()
       definitin_instance.populate(definition)
       self.definition = definitin_instance
   if self.definition_id and self.definition:
     if self.definition.identifier and self.definition_id != self.definition.identifier:
       raise ValueException(u'Reference definitions cannot be updated')
   self.value = json.get('value', None)
   self.identifier = json.get('identifier', None)
   self.properties.populate(json.get('properties', None))
   creator_group = json.get('creator_group', None)
   if creator_group:
     cg_instance = Group()
     cg_instance.populate(creator_group)
     self.creator_group = cg_instance
   modifier_group = json.get('modifier_group', None)
   if modifier_group:
     cg_instance = Group()
     cg_instance.populate(modifier_group)
     self.modifier = cg_instance
   created_at = json.get('created_at', None)
   if created_at:
     self.created_at = strings.stringToDateTime(created_at)
   modified_on = json.get('modified_on', None)
   if modified_on:
     self.modified_on = strings.stringToDateTime(modified_on)
예제 #3
0
  def populate(self, json):

    self.identifier = json.get('identifier', None)
    definition_id = json.get('definition_id', None)
    if definition_id:
      self.definition_id = definition_id
      definition = json.get('definition', None)
      if definition:
        definitin_instance = ObjectDefinition()
        definitin_instance.populate(definition)
        self.definition = definitin_instance
    if self.definition_id and self.definition:
      if self.definition.identifier and self.definition_id != self.definition.identifier:
        raise ValueException(u'Object definitions cannot be updated')
    if not (self.definition_id or self.definition):
      raise ValueException(u'Object definition or definition_id must be set')
    self.properties.populate(json.get('properties', Properties('0')))
    creator_group = json.get('creator_group', None)
    if creator_group:
      cg_instance = Group()
      cg_instance.populate(creator_group)
      self.creator_group = cg_instance
    modifier_group = json.get('modifier_group', None)
    if modifier_group:
      cg_instance = Group()
      cg_instance.populate(modifier_group)
      self.modifier = cg_instance
    created_at = json.get('created_at', None)
    if created_at:
      self.created_at = strings.stringToDateTime(created_at)
    modified_on = json.get('modified_on', None)
    if modified_on:
      self.modified_on = strings.stringToDateTime(modified_on)
    rel_obs = json.get('related_objects', None)
    if rel_obs:
      for rel_ob in rel_obs:
        obj_instance = RelatedObject()
        obj_instance.populate(rel_ob)
        self.related_objects.append(obj_instance)

    attribtues = json.get('attributes', None)
    if attribtues:
      for attribtue in attribtues:
        attribute = Attribute()
        attribute.populate(attribtue)
        self.attributes.append(attribute)
예제 #4
0
class EventGroupPermission(ExtendedLogingInformations):

  def __init__(self):
    ExtendedLogingInformations.__init__(self)
    self.group = None
    self.permissions = EventPermissions('0')

  def to_dict(self, complete=True, inflated=False):
    return {'identifier': self.convert_value(self.identifier),
            'permissions': self.permissions.to_dict(),
            'group': self.group.to_dict(False, False)}

  def populate(self, json):
    self.identifier = json.get('identifier', None)
    self.permissions = EventPermissions('0')
    self.permissions.populate(json.get('permissions', None))
    self.group = Group()
    self.group.populate(json.get('group', None))
예제 #5
0
 def populate(self, json):
   self.identifier = json.get('identifier', None)
   definition_id = json.get('definition_id', None)
   if definition_id:
     self.definition_id = definition_id
     definition = json.get('definition', None)
     if definition:
       definitin_instance = AttributeDefinition()
       definitin_instance.populate(definition)
       self.definition = definitin_instance
   if self.definition_id and self.definition:
     if self.definition.identifier and self.definition_id != self.definition.identifier:
       raise ValueException(u'Attribute definitions cannot be updated')
   if not (self.definition_id or self.definition):
     raise ValueException(u'Attribute definition or definition_id must be set')
   condition_id = json.get('condition_id', None)
   if not condition_id:
     condition = json.get('condition', None)
     if condition:
       condition_id = condition.get('identifier', None)
   if condition_id:
     self.condition_id = condition_id
   self.is_ioc = json.get('ioc', 0)
   self.value = json.get('value', None)
   self.properties.populate(json.get('properties', None))
   creator_group = json.get('creator_group', None)
   if creator_group:
     cg_instance = Group()
     cg_instance.populate(creator_group)
     self.creator_group = cg_instance
   modifier_group = json.get('modifier_group', None)
   if modifier_group:
     cg_instance = Group()
     cg_instance.populate(modifier_group)
     self.modifier = cg_instance
   created_at = json.get('created_at', None)
   if created_at:
     self.created_at = strings.stringToDateTime(created_at)
   modified_on = json.get('modified_on', None)
   if modified_on:
     self.modified_on = strings.stringToDateTime(modified_on)
예제 #6
0
  def populate(self, json):

    self.identifier = json.get('identifier', None)
    self.title = json.get('title', None)
    self.description = json.get('description', None)
    self.version = json.get('version', '')
    self.properties.populate(json.get('properties', Properties('0')))
    obj = self.title = json.get('object', None)
    if obj:
      obj_instance = Object()
      obj_instance.populate(obj)
      self.object = obj_instance
    comp = self.title = json.get('observable_composition', None)
    if comp:
      comp_instance = ObservableComposition()
      comp_instance.populate(comp)
      self.observable_composition = comp_instance
    rel_obs = self.title = json.get('related_observables', None)
    if rel_obs:
      for rel_ob in rel_obs:
        obj_instance = RelatedObservable()
        obj_instance.populate(rel_ob)
        self.related_observables.append(obj_instance)
    modifier_group = json.get('modifier_group', None)
    if modifier_group:
      cg_instance = Group()
      cg_instance.populate(modifier_group)
      self.modifier = cg_instance
    creator_group = json.get('creator_group', None)
    if creator_group:
      cg_instance = Group()
      cg_instance.populate(creator_group)
      self.creator_group = cg_instance
    created_at = json.get('created_at', None)
    if created_at:
      self.created_at = strings.stringToDateTime(created_at)
    modified_on = json.get('modified_on', None)
    if modified_on:
      self.modified_on = strings.stringToDateTime(modified_on)
예제 #7
0
  def populate(self, json):
    self.identifier = json.get('identifier', None)

    self.title = json.get('title', None)
    self.description = json.get('description', None)
    self.short_description = json.get('short_description', None)
    self.confidence = json.get('confidence', None)
    modifier_group = json.get('modifier_group', None)
    if modifier_group:
      cg_instance = Group()
      cg_instance.populate(modifier_group)
      self.modifier = cg_instance
    originating_group = json.get('originating_group', None)
    if originating_group:
      cg_instance = Group()
      cg_instance.populate(originating_group)
      self.originating_group = cg_instance
    creator_group = json.get('creator_group', None)
    if creator_group:
      cg_instance = Group()
      cg_instance.populate(creator_group)
      self.creator_group = cg_instance
    created_at = json.get('created_at', None)
    if created_at:
      self.created_at = strings.stringToDateTime(created_at)
    modified_on = json.get('modified_on', None)
    if modified_on:
      self.modified_on = strings.stringToDateTime(modified_on)
    self.operator = json.get('operator', 'OR')

    self.properties.populate(json.get('properties', Properties('0')))
    observables = json.get('observables', list())
    if observables:
      for observable in observables:
        obs = Observable()
        obs.populate(observable)
        self.observables.append(obs)
예제 #8
0
  def populate(self, json):

    self.identifier = json.get('identifier', None)

    self.title = json.get('title', None)
    self.description = json.get('description', None)
    self.risk = json.get('risk', 'Undefined').title()
    self.status = json.get('status', 'Draft').title()
    self.tlp = json.get('tlp', 'Amber').title()
    self.analysis = json.get('analysis', 'Unknown').title()
    self.properties.populate(json.get('properties', Properties('0')))
    published = json.get('published', False)
    if published:
      if published == '1' or published == 1:
        published = True
      elif published == '0' or published == 0:
        published = True
      self.properties.is_shareable = published

    observables = json.get('observables', list())
    if observables:
      for observable in observables:
        obs = Observable()
        obs.populate(observable)
        self.observables.append(obs)
    indicators = json.get('indicators', list())
    if indicators:
      for indicator in indicators:
        ind = Indicator()
        ind.populate(indicator)
        self.indicators.append(ind)
    modifier_group = json.get('modifier_group', None)
    if modifier_group:
      cg_instance = Group()
      cg_instance.populate(modifier_group)
      self.modifier = cg_instance
    originating_group = json.get('originating_group', None)
    if originating_group:
      cg_instance = Group()
      cg_instance.populate(originating_group)
      self.originating_group = cg_instance
    creator_group = json.get('creator_group', None)
    if creator_group:
      cg_instance = Group()
      cg_instance.populate(creator_group)
      self.creator_group = cg_instance
    created_at = json.get('created_at', None)
    if created_at:
      self.created_at = strings.stringToDateTime(created_at)
    modified_on = json.get('modified_on', None)
    if modified_on:
      self.modified_on = strings.stringToDateTime(modified_on)
    first_seen = json.get('first_seen', None)
    if first_seen:
      self.first_seen = strings.stringToDateTime(first_seen)
    last_seen = json.get('last_seen', None)
    if last_seen:
      self.last_seen = strings.stringToDateTime(last_seen)
    reports = json.get('reports', None)
    if reports:
      for report in reports:
        report_instacne = Report()
        report_instacne.populate(report)
        self.reports.append(report_instacne)
    comments = json.get('comments', None)
    if comments:
      for comment in comments:
        comment_instacne = Comment()
        comment_instacne.populate(comment)
        self.comments.append(comment_instacne)
    permissions = json.get('groups', None)
    if permissions:
      for permission in permissions:
        event_permission = EventGroupPermission()
        event_permission.populate(permission)