Class: ActiveStix::Malware

Inherits:
ApplicationRecord show all
Defined in:
app/models/active_stix/malware.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.description(malware, obj) ⇒ Object



36
37
38
# File 'app/models/active_stix/malware.rb', line 36

def self.description(malware, obj)
  malware.description = obj['description']
end

.expected_keysObject



11
12
13
14
15
16
17
# File 'app/models/active_stix/malware.rb', line 11

def self.expected_keys
  [
      'description',
      'external_references',
      'object_marking_refs'
  ]
end

.external_references(malware, obj) ⇒ Object



40
41
42
43
44
45
# File 'app/models/active_stix/malware.rb', line 40

def self.external_references(malware, obj)
  obj['external_references'].each do |er|
    external_reference = ActiveStix::ExternalReference.ingest_json(er, obj['id'])
    malware.external_references << external_reference unless ActiveStix::ReferenceItem.find_by(external_reference: external_reference, referrer: malware)
  end
end

.ingest_json(obj) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/models/active_stix/malware.rb', line 23

def self.ingest_json(obj)
  malware = find_or_create_by(stix_id: obj['id'], name: obj['name'], created_by_ref: obj['created_by_ref'])

  expected_keys.each do |expected_key|
    if obj.has_key?(expected_key)
      send(expected_key, *[malware, obj])
    end
  end

  malware.save
  malware
end

.object_marking_refs(malware, obj) ⇒ Object



47
48
49
50
51
52
53
# File 'app/models/active_stix/malware.rb', line 47

def self.object_marking_refs(malware, obj)
  obj['object_marking_refs'].each do |mr|
    # todo
    # marking_definition = ActiveStix::MarkingDefinition.create_by_id(mr)
    # malware.marking_definitions << marking_definition unless ActiveStix::ReferenceObjectMarkingMalware.find_by(stix_marking_definition_id:marking_definition.id, stix_malware_id:malware.id)
  end
end

Instance Method Details

#as_stix(classification = nil, chess = nil) ⇒ Object



55
56
57
# File 'app/models/active_stix/malware.rb', line 55

def as_stix(classification = nil, chess = nil)
  as_json
end

#convert_to_jsonObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/models/active_stix/malware.rb', line 59

def convert_to_json
  external_refs_arr = []
  external_references.each do |x|
    external_refs_arr << x.convert_to_json
  end

  marking_def_arr = []
  marking_definitions.each do |x|
    marking_def_arr << x.convert_to_json
  end

  platform_arr = []
  platforms.each do |x|
    platform_arr << x.convert_to_json
  end

  labels_arr = []
  labels.each do |x|
    labels_arr << x.open_vocabulary.convert_to_json
  end

  alias_arr = []
  attack_aliases.each do |x|
    alias_arr << x.convert_to_json
  end

  {
      :external_references => external_refs_arr,
      :object_marking_refs => marking_def_arr,
      :modified => updated_at.to_s,
      :created_by_ref => created_by_ref,
      :id => stix_id,
      :name => name,
      :created => created_at.to_s,
      :labels => labels_arr,
      :type => "malware",
      :description => description
  }
end

#typeObject



19
20
21
# File 'app/models/active_stix/malware.rb', line 19

def type
  'malware'
end