misp 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +52 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +118 -0
- data/Rakefile +6 -0
- data/lib/misp.rb +30 -0
- data/lib/misp/attribute.rb +128 -0
- data/lib/misp/base.rb +156 -0
- data/lib/misp/configuration.rb +28 -0
- data/lib/misp/event.rb +180 -0
- data/lib/misp/feed.rb +110 -0
- data/lib/misp/galaxy.rb +59 -0
- data/lib/misp/galaxy_cluster.rb +49 -0
- data/lib/misp/org.rb +25 -0
- data/lib/misp/orgc.rb +25 -0
- data/lib/misp/server.rb +37 -0
- data/lib/misp/sharing_group.rb +84 -0
- data/lib/misp/sharing_group_org.rb +34 -0
- data/lib/misp/sharing_group_server.rb +33 -0
- data/lib/misp/tag.rb +70 -0
- data/lib/misp/version.rb +5 -0
- data/misp.gemspec +33 -0
- metadata +151 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MISP
|
4
|
+
class Configuration
|
5
|
+
# @return [URI]
|
6
|
+
attr_accessor :api_endpoint
|
7
|
+
|
8
|
+
# @return [String]
|
9
|
+
attr_accessor :api_key
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@api_endpoint = ENV["MISP_API_ENDPOINT"]
|
13
|
+
@api_key = ENV["MISP_API_KEY"]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.configuration
|
18
|
+
@configuration ||= Configuration.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.configuration=(config)
|
22
|
+
@configuration = config
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.configure
|
26
|
+
yield configuration
|
27
|
+
end
|
28
|
+
end
|
data/lib/misp/event.rb
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MISP
|
4
|
+
class Event < Base
|
5
|
+
attr_reader :id
|
6
|
+
attr_accessor :orgc_id
|
7
|
+
attr_accessor :org_id
|
8
|
+
attr_accessor :date
|
9
|
+
attr_accessor :threat_level_id
|
10
|
+
attr_accessor :info
|
11
|
+
attr_accessor :published
|
12
|
+
attr_reader :uuid
|
13
|
+
attr_accessor :attribute_count
|
14
|
+
attr_accessor :analysis
|
15
|
+
attr_accessor :timestamp
|
16
|
+
attr_accessor :distribution
|
17
|
+
attr_accessor :proposal_email_lock
|
18
|
+
attr_accessor :locked
|
19
|
+
attr_accessor :publish_timestamp
|
20
|
+
attr_accessor :sharing_group_id
|
21
|
+
attr_accessor :disable_correlation
|
22
|
+
attr_accessor :event_creator_email
|
23
|
+
|
24
|
+
attr_accessor :org
|
25
|
+
attr_accessor :orgc
|
26
|
+
|
27
|
+
attr_accessor :sharing_groups
|
28
|
+
attr_accessor :attributes
|
29
|
+
attr_accessor :shadow_attributes
|
30
|
+
attr_accessor :related_events
|
31
|
+
attr_accessor :galaxies
|
32
|
+
attr_accessor :tags
|
33
|
+
|
34
|
+
def initialize(**attrs)
|
35
|
+
attrs = normalize_attributes(attrs)
|
36
|
+
|
37
|
+
@id = attrs.dig(:id)
|
38
|
+
@orgc_id = attrs.dig(:orgc_id)
|
39
|
+
@org_id = attrs.dig(:org_id)
|
40
|
+
@date = attrs.dig(:date)
|
41
|
+
@threat_level_id = attrs.dig(:threat_level_id)
|
42
|
+
@info = attrs.dig(:info)
|
43
|
+
@published = attrs.dig(:published) || false
|
44
|
+
@uuid = attrs.dig(:uuid)
|
45
|
+
@attribute_count = attrs.dig(:attribute_count)
|
46
|
+
@analysis = attrs.dig(:analysis)
|
47
|
+
@timestamp = attrs.dig(:timestamp)
|
48
|
+
@distribution = attrs.dig(:distribution)
|
49
|
+
@proposal_email_lock = attrs.dig(:proposal_email_lock)
|
50
|
+
@locked = attrs.dig(:locked) || false
|
51
|
+
@publish_timestamp = attrs.dig(:publish_timestamp)
|
52
|
+
@sharing_group_id = attrs.dig(:sharing_group_id)
|
53
|
+
@disable_correlation = attrs.dig(:disable_correlation)
|
54
|
+
@event_creator_email = attrs.dig(:event_creator_email)
|
55
|
+
|
56
|
+
@org = build_attribute(item: attrs.dig(:Org), klass: Org)
|
57
|
+
@orgc = build_attribute(item: attrs.dig(:Orgc), klass: Orgc)
|
58
|
+
|
59
|
+
@sharing_groups = build_plural_attribute(items: attrs.dig(:SharingGroup), klass: SharingGroup)
|
60
|
+
@attributes = build_plural_attribute(items: attrs.dig(:Attribute), klass: Attribute)
|
61
|
+
@shadow_attributes = build_plural_attribute(items: attrs.dig(:ShadowAttribute), klass: Attribute )
|
62
|
+
@related_events = build_plural_attribute(items: attrs.dig(:RelatedEvent), klass: Attribute)
|
63
|
+
@galaxies = build_plural_attribute(items: attrs.dig(:Galaxy), klass: Galaxy)
|
64
|
+
@tags = build_plural_attribute(items: attrs.dig(:Tag), klass: Tag)
|
65
|
+
end
|
66
|
+
|
67
|
+
def to_h
|
68
|
+
compact(
|
69
|
+
id: id,
|
70
|
+
orgc_id: orgc_id,
|
71
|
+
org_id: org_id,
|
72
|
+
date: date,
|
73
|
+
threat_level_id: threat_level_id,
|
74
|
+
info: info,
|
75
|
+
published: published,
|
76
|
+
uuid: uuid,
|
77
|
+
attribute_count: attribute_count,
|
78
|
+
analysis: analysis,
|
79
|
+
timestamp: timestamp,
|
80
|
+
distribution: distribution,
|
81
|
+
proposal_email_lock: proposal_email_lock,
|
82
|
+
locked: locked,
|
83
|
+
publish_timestamp: publish_timestamp,
|
84
|
+
sharing_group_id: sharing_group_id,
|
85
|
+
disable_correlation: disable_correlation,
|
86
|
+
event_creator_email: event_creator_email,
|
87
|
+
Org: org.to_h,
|
88
|
+
Orgc: orgc.to_h,
|
89
|
+
SharingGroup: sharing_groups.map(&:to_h),
|
90
|
+
Attribute: attributes.map(&:to_h),
|
91
|
+
ShadowAttribute: shadow_attributes.map(&:to_h),
|
92
|
+
RelatedEvent: related_events.map(&:to_h),
|
93
|
+
Galaxy: galaxies.map(&:to_h),
|
94
|
+
Tag: tags.map(&:to_h)
|
95
|
+
)
|
96
|
+
end
|
97
|
+
|
98
|
+
def get(id)
|
99
|
+
_get("/events/#{id}") { |event| Event.new symbolize_keys(event) }
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.get(id)
|
103
|
+
new.get id
|
104
|
+
end
|
105
|
+
|
106
|
+
def create(**attrs)
|
107
|
+
payload = to_h.merge(attrs)
|
108
|
+
_post("/events/add", wrap(payload)) { |event| Event.new symbolize_keys(event) }
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.create(**attrs)
|
112
|
+
new.create attrs
|
113
|
+
end
|
114
|
+
|
115
|
+
def delete
|
116
|
+
_delete("/events/#{id}") { |json| json }
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.delete(id)
|
120
|
+
new(id: id).delete
|
121
|
+
end
|
122
|
+
|
123
|
+
def list
|
124
|
+
_get("/events/index") do |events|
|
125
|
+
events.map do |event|
|
126
|
+
Event.new symbolize_keys(event)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def self.list
|
132
|
+
new.list
|
133
|
+
end
|
134
|
+
|
135
|
+
def update(**attrs)
|
136
|
+
payload = to_h.merge(attrs)
|
137
|
+
payload[:timestamp] = nil
|
138
|
+
_post("/events/#{id}", wrap(payload)) { |event| Event.new symbolize_keys(event) }
|
139
|
+
end
|
140
|
+
|
141
|
+
def self.update(id, **attrs)
|
142
|
+
new(id: id).update attrs
|
143
|
+
end
|
144
|
+
|
145
|
+
def search(**params)
|
146
|
+
base = {
|
147
|
+
returnFormat: "json",
|
148
|
+
limit: "100",
|
149
|
+
page: "0"
|
150
|
+
}
|
151
|
+
|
152
|
+
_post("/events/restSearch", base.merge(params)) do |json|
|
153
|
+
events = json.dig("response") || []
|
154
|
+
events.map { |event| Event.new symbolize_keys(event) }
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def self.search(**params)
|
159
|
+
new.search params
|
160
|
+
end
|
161
|
+
|
162
|
+
def add_attribute(attribute)
|
163
|
+
attribute = Attribute.new(symbolize_keys(attribute)) unless attribute.is_a?(Attribute)
|
164
|
+
attributes << attribute
|
165
|
+
self
|
166
|
+
end
|
167
|
+
|
168
|
+
def add_tag(tag)
|
169
|
+
tag = Tag.new(symbolize_keys(tag)) unless tag.is_a?(MISP::Tag)
|
170
|
+
tags << tag
|
171
|
+
self
|
172
|
+
end
|
173
|
+
|
174
|
+
private
|
175
|
+
|
176
|
+
def compact(hash)
|
177
|
+
hash.compact.reject { |_k, v| (v.is_a?(Hash) || v.is_a?(Array)) && v.empty? }
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
data/lib/misp/feed.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MISP
|
4
|
+
class Feed < Base
|
5
|
+
attr_reader :id
|
6
|
+
attr_reader :name
|
7
|
+
attr_reader :provider
|
8
|
+
attr_reader :url
|
9
|
+
attr_reader :rules
|
10
|
+
attr_reader :enabled
|
11
|
+
attr_reader :distribution
|
12
|
+
attr_reader :sharing_group_id
|
13
|
+
attr_reader :tag_id
|
14
|
+
attr_reader :default
|
15
|
+
attr_reader :source_format
|
16
|
+
attr_reader :fixed_event
|
17
|
+
attr_reader :delta_merge
|
18
|
+
attr_reader :event_id
|
19
|
+
attr_reader :publish
|
20
|
+
attr_reader :override_ids
|
21
|
+
attr_reader :settings
|
22
|
+
attr_reader :input_source
|
23
|
+
attr_reader :delete_local_file
|
24
|
+
attr_reader :lookup_visible
|
25
|
+
attr_reader :headers
|
26
|
+
attr_reader :caching_enabled
|
27
|
+
|
28
|
+
def initialize(**attributes)
|
29
|
+
attributes = normalize_attributes(attributes)
|
30
|
+
|
31
|
+
@id = attributes.dig(:id)
|
32
|
+
@name = attributes.dig(:name) || "feed name"
|
33
|
+
@provider = attributes.dig(:provider) || "my provider"
|
34
|
+
@url = attributes.dig(:url) || "http://example.com"
|
35
|
+
@rules = attributes.dig(:rules) || ""
|
36
|
+
@enabled = attributes.dig(:enabled)
|
37
|
+
@distribution = attributes.dig(:distribution)
|
38
|
+
@sharing_group_id = attributes.dig(:sharing_group_id)
|
39
|
+
@tag_id = attributes.dig(:tag_id) || "0"
|
40
|
+
@default = attributes.dig(:default) || true
|
41
|
+
@source_format = attributes.dig(:source_format) || "misp"
|
42
|
+
@fixed_event = attributes.dig(:fixed_event) || true
|
43
|
+
@delta_merge = attributes.dig(:delta_merge) || false
|
44
|
+
@event_id = attributes.dig(:event_id) || "0"
|
45
|
+
@publish = attributes.dig(:publish) || true
|
46
|
+
@override_ids = attributes.dig(:override_ids) || false
|
47
|
+
@settings = attributes.dig(:settings) || ""
|
48
|
+
@input_source = attributes.dig(:input_source) || "network"
|
49
|
+
@delete_local_file = attributes.dig(:delete_local_file) || false
|
50
|
+
@lookup_visible = attributes.dig(:lookup_visible) || true
|
51
|
+
@headers = attributes.dig(:headers) || ""
|
52
|
+
@caching_enabled = attributes.dig(:caching_enabled) || true
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_h
|
56
|
+
{
|
57
|
+
id: id,
|
58
|
+
name: name,
|
59
|
+
provider: provider,
|
60
|
+
url: url,
|
61
|
+
rules: rules,
|
62
|
+
enabled: enabled,
|
63
|
+
distribution: distribution,
|
64
|
+
sharing_group_id: sharing_group_id,
|
65
|
+
tag_id: tag_id,
|
66
|
+
default: default,
|
67
|
+
source_format: source_format,
|
68
|
+
fixed_event: fixed_event,
|
69
|
+
delta_merge: delta_merge,
|
70
|
+
event_id: event_id,
|
71
|
+
publish: publish,
|
72
|
+
override_ids: override_ids,
|
73
|
+
settings: settings,
|
74
|
+
input_source: input_source,
|
75
|
+
delete_local_file: delete_local_file,
|
76
|
+
lookup_visible: lookup_visible,
|
77
|
+
headers: headers,
|
78
|
+
caching_enabled: caching_enabled,
|
79
|
+
}.compact
|
80
|
+
end
|
81
|
+
|
82
|
+
def list
|
83
|
+
_get("/feeds/index") do |feeds|
|
84
|
+
feeds.map do |feed|
|
85
|
+
Feed.new symbolize_keys(feed)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.list
|
91
|
+
new.list
|
92
|
+
end
|
93
|
+
|
94
|
+
def get
|
95
|
+
_get("/feeds/view/#{id}") { |feed| Feed.new symbolize_keys(feed) }
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.get(id)
|
99
|
+
new(id: id).get
|
100
|
+
end
|
101
|
+
|
102
|
+
def create(**attributes)
|
103
|
+
_post("/feeds/add", wrap(attributes)) { |feed| Feed.new symbolize_keys(feed) }
|
104
|
+
end
|
105
|
+
|
106
|
+
def self.create(attributes)
|
107
|
+
new.create attributes
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
data/lib/misp/galaxy.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MISP
|
4
|
+
class Galaxy < Base
|
5
|
+
attr_reader :id
|
6
|
+
attr_reader :uuid
|
7
|
+
attr_reader :name
|
8
|
+
attr_reader :type
|
9
|
+
attr_reader :description
|
10
|
+
attr_reader :version
|
11
|
+
|
12
|
+
attr_reader :galaxy_clusters
|
13
|
+
|
14
|
+
def initialize(**attributes)
|
15
|
+
attributes = normalize_attributes(attributes)
|
16
|
+
|
17
|
+
@id = attributes.dig(:id)
|
18
|
+
@uuid = attributes.dig(:uuid)
|
19
|
+
@name = attributes.dig(:name)
|
20
|
+
@type = attributes.dig(:type)
|
21
|
+
@description = attributes.dig(:description)
|
22
|
+
@version = attributes.dig(:version)
|
23
|
+
|
24
|
+
@galaxy_clusters = build_plural_attribute(items: attributes.dig(:GalaxyCluster), klass: GalaxyCluster)
|
25
|
+
end
|
26
|
+
|
27
|
+
def to_h
|
28
|
+
{
|
29
|
+
id: id,
|
30
|
+
uuid: uuid,
|
31
|
+
name: name,
|
32
|
+
type: type,
|
33
|
+
description: description,
|
34
|
+
version: version,
|
35
|
+
GalaxyCluster: galaxy_clusters.map(&:to_h)
|
36
|
+
}.compact
|
37
|
+
end
|
38
|
+
|
39
|
+
def list
|
40
|
+
_get("/galaxies/") do |galaxies|
|
41
|
+
galaxies.map do |galaxy|
|
42
|
+
Galaxy.new symbolize_keys(galaxy)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.list
|
48
|
+
new.list
|
49
|
+
end
|
50
|
+
|
51
|
+
def get
|
52
|
+
_get("/galaxies/view/#{id}") { |galaxy| Galaxy.new symbolize_keys(galaxy) }
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.get(id)
|
56
|
+
new(id: id).get
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MISP
|
4
|
+
class GalaxyCluster < Base
|
5
|
+
attr_reader :id
|
6
|
+
attr_reader :uuid
|
7
|
+
attr_reader :type
|
8
|
+
attr_reader :value
|
9
|
+
attr_reader :tag_name
|
10
|
+
attr_reader :description
|
11
|
+
attr_reader :galaxy_id
|
12
|
+
attr_reader :source
|
13
|
+
attr_reader :authors
|
14
|
+
attr_reader :tag_id
|
15
|
+
attr_reader :meta
|
16
|
+
|
17
|
+
def initialize(**attributes)
|
18
|
+
attributes = normalize_attributes(attributes)
|
19
|
+
|
20
|
+
@id = attributes.dig(:id)
|
21
|
+
@uuid = attributes.dig(:uuid)
|
22
|
+
@type = attributes.dig(:type)
|
23
|
+
@value = attributes.dig(:value)
|
24
|
+
@tag_name = attributes.dig(:tag_name)
|
25
|
+
@description = attributes.dig(:description)
|
26
|
+
@galaxy_id = attributes.dig(:galaxy_id)
|
27
|
+
@source = attributes.dig(:source)
|
28
|
+
@authors = attributes.dig(:authors)
|
29
|
+
@tag_id = attributes.dig(:tag_id)
|
30
|
+
@meta = attributes.dig(:meta)
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_h
|
34
|
+
{
|
35
|
+
id: id,
|
36
|
+
uuid: uuid,
|
37
|
+
type: type,
|
38
|
+
value: value,
|
39
|
+
tag_name: tag_name,
|
40
|
+
description: description,
|
41
|
+
galaxy_id: galaxy_id,
|
42
|
+
source: source,
|
43
|
+
authors: authors,
|
44
|
+
tag_id: tag_id,
|
45
|
+
meta: meta,
|
46
|
+
}.compact
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/misp/org.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MISP
|
4
|
+
class Org < Base
|
5
|
+
attr_reader :id
|
6
|
+
attr_reader :name
|
7
|
+
attr_reader :uuid
|
8
|
+
|
9
|
+
def initialize(**attributes)
|
10
|
+
attributes = normalize_attributes(attributes)
|
11
|
+
|
12
|
+
@id = attributes.dig(:id)
|
13
|
+
@name = attributes.dig(:name)
|
14
|
+
@uuid = attributes.dig(:uuid)
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_h
|
18
|
+
{
|
19
|
+
id: id,
|
20
|
+
name: name,
|
21
|
+
uuid: uuid,
|
22
|
+
}.compact
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|