forked from threatgrid/ctim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.cljc
245 lines (213 loc) · 8.23 KB
/
context.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
(ns ctim.schemas.sighting.context
(:require [ctim.schemas.vocabularies :as v]
[ctim.schemas.common :as c]
#?(:clj [flanders.core :as f :refer [def-enum-type def-map-type def-eq]]
:cljs [flanders.core :as f :refer-macros [def-enum-type def-map-type def-eq]])))
(def base-event-entries
(concat
(f/required-entries
(f/entry :time c/ObservedTime)
(f/entry :process_id f/any-int)
(f/entry :process_name c/ShortString))
(f/optional-entries
(f/entry :process_guid f/any-int)
(f/entry :process_username c/ShortString))))
(def process-create-type-identifier "ProcessCreateEvent")
(def-eq ProcessCreateTypeIdentifier process-create-type-identifier)
(def-map-type ProcessCreateType
(concat
base-event-entries
(f/required-entries
(f/entry :type ProcessCreateTypeIdentifier))
(f/optional-entries
(f/entry :process_args c/MedString)
(f/entry :process_hash c/MedString)
(f/entry :process_size f/any-int)
(f/entry :process_disposition c/ShortString)
(f/entry :parent_creation_time c/Time)
(f/entry :parent_process_id f/any-int)
(f/entry :parent_process_guid f/any-int)
(f/entry :parent_process_name c/ShortString)
(f/entry :parent_process_args c/MedString)
(f/entry :parent_process_username c/ShortString)
(f/entry :parent_process_hash c/MedString)
(f/entry :parent_process_size f/any-int)
(f/entry :parent_process_disposition c/ShortString))))
(def library-load-type-identifier "LibraryLoadEvent")
(def-eq LibraryLoadTypeIdentifier library-load-type-identifier)
(def-map-type LibraryLoadType
(concat
base-event-entries
(f/required-entries
(f/entry :type LibraryLoadTypeIdentifier)
(f/entry :dll_library_name c/ShortString)
(f/entry :dll_library_path c/MedString))))
(def file-event-entries
(concat
base-event-entries
(f/required-entries
(f/entry :file_name c/ShortString)
(f/entry :file_path c/MedString))))
(def file-create-type-identifier "FileCreateEvent")
(def-eq FileCreateTypeIdentifier file-create-type-identifier)
(def-map-type FileCreateType
(concat
file-event-entries
(f/required-entries
(f/entry :type FileCreateTypeIdentifier))
(f/optional-entries
(f/entry :failed (f/bool :default false)))))
(def file-delete-type-identifier "FileDeleteEvent")
(def-eq FileDeleteTypeIdentifier file-delete-type-identifier)
(def-map-type FileDeleteType
(concat
file-event-entries
(f/required-entries
(f/entry :type FileDeleteTypeIdentifier))
(f/optional-entries
(f/entry :failed (f/bool :default false)))))
(def file-modify-type-identifier "FileModifyEvent")
(def-eq FileModifyTypeIdentifier file-modify-type-identifier)
(def-map-type FileModifyType
(concat
file-event-entries
(f/required-entries
(f/entry :type FileModifyTypeIdentifier))
(f/optional-entries
(f/entry :failed (f/bool :default false)))))
(def file-move-type-identifier "FileMoveEvent")
(def-eq FileMoveTypeIdentifier file-move-type-identifier)
(def-map-type FileMoveType
(concat
file-event-entries
(f/required-entries
(f/entry :type FileMoveTypeIdentifier)
(f/entry :old_name c/ShortString)
(f/entry :new_name c/ShortString))))
(def traffic-direction #{"incoming" "outgoing"})
(def-enum-type TrafficDirection
traffic-direction)
(def-map-type Traffic
(concat
(f/required-entries
(f/entry :protocol f/any-int
:description
"The IP [protocol id](https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml)")
(f/entry :source_ip f/any-str)
(f/entry :destination_ip f/any-str)
(f/entry :source_port f/any-int)
(f/entry :destination_port f/any-int)
(f/entry :direction TrafficDirection))
(f/optional-entries
(f/entry :destination_host_name f/any-str)
(f/entry :source_subnet f/any-str)
(f/entry :destination_subnet f/any-str))))
(def netflow-type-identifier "NetflowEvent")
(def-eq NetflowTypeIdentifier netflow-type-identifier)
(def-map-type NetflowType
(concat
base-event-entries
(f/required-entries
(f/entry :type NetflowTypeIdentifier)
(f/entry :traffic Traffic))
(f/optional-entries
(f/entry :process_path c/ShortString)
(f/entry :process_args c/ShortString)
(f/entry :process_hash c/ShortString)
(f/entry :process_account_type c/ShortString)
(f/entry :process_account c/ShortString)
(f/entry :parent_process_id f/any-int)
(f/entry :parent_process_name c/ShortString)
(f/entry :parent_process_path c/ShortString)
(f/entry :parent_process_args c/ShortString)
(f/entry :parent_process_hash c/ShortString)
(f/entry :parent_process_account c/ShortString)
(f/entry :parent_process_account_type c/ShortString)
(f/entry :flow_time c/Time)
(f/entry :byte_count_out f/any-int)
(f/entry :byte_count_in f/any-int))))
(def http-type-identifier "HTTPEvent")
(def-eq HTTPTypeIdentifier http-type-identifier)
(def http-methods #{"GET" "HEAD" "POST" "PUT" "CONNECT" "OPTIONS"
"TRACE" "PATCH"})
(def-enum-type HTTPMethod
http-methods)
(def-map-type HTTPType
(concat
base-event-entries
(f/required-entries
(f/entry :type HTTPTypeIdentifier)
(f/entry :host c/ShortString)
(f/entry :method HTTPMethod)
(f/entry :traffic Traffic))
(f/optional-entries
(f/entry :url_port f/any-int)
(f/entry :process_guid f/any-int)
(f/entry :process_username c/ShortString)
(f/entry :query c/LongString)
(f/entry :encrypted f/any-bool))))
(def registry-event-entries
(concat
base-event-entries
(f/required-entries
(f/entry :registry_key c/ShortString))))
(def registry-create-type-identifier "RegistryCreateEvent")
(def-eq RegistryCreateTypeIdentifier registry-create-type-identifier)
(def-map-type RegistryCreateType
(concat
registry-event-entries
(f/required-entries
(f/entry :type RegistryCreateTypeIdentifier))))
(def registry-set-type-identifier "RegistrySetEvent")
(def-eq RegistrySetTypeIdentifier registry-set-type-identifier)
(def-map-type RegistrySetType
(concat
registry-event-entries
(f/required-entries
(f/entry :type RegistrySetTypeIdentifier)
(f/entry :registry_value c/MedString)
(f/entry :registry_data c/LongString))
(f/optional-entries
(f/entry :registry_data_length f/any-int))))
(def registry-delete-type-identifier "RegistryDeleteEvent")
(def-eq RegistryDeleteTypeIdentifier registry-delete-type-identifier)
(def-map-type RegistryDeleteType
(concat
registry-event-entries
(f/required-entries
(f/entry :type RegistryDeleteTypeIdentifier)
(f/entry :registry_value c/MedString))))
(def registry-rename-type-identifier "RegistryRenameEvent")
(def-eq RegistryRenameTypeIdentifier registry-rename-type-identifier)
(def-map-type RegistryRenameType
(concat
registry-event-entries
(f/required-entries
(f/entry :type RegistryRenameTypeIdentifier)
(f/entry :registry_old_key c/ShortString))))
(def-map-type Context
(f/optional-entries
(f/entry :process_create_events (f/seq-of ProcessCreateType)
:description "a list of `ProcessCreate`")
(f/entry :library_load_events (f/seq-of LibraryLoadType)
:description "a list of `LibraryLoadType`")
(f/entry :file_create_events (f/seq-of FileCreateType)
:description "a list of `FileCreateType`")
(f/entry :file_delete_events (f/seq-of FileDeleteType)
:description "a list of `FileDeleteType`")
(f/entry :file_modify_events (f/seq-of FileModifyType)
:description "a list of `FileModifyType`")
(f/entry :file_move_events (f/seq-of FileMoveType)
:description "a list of `FileMoveType`")
(f/entry :netflow_events (f/seq-of NetflowType)
:description "a list of `NetflowType`")
(f/entry :http_events (f/seq-of HTTPType)
:description "a list of `HTTPType`")
(f/entry :registry_create_events (f/seq-of RegistryCreateType)
:description "a list of `RegistryCreateType`")
(f/entry :registry_set_events (f/seq-of RegistrySetType)
:description "a list of `RegistrySetType`")
(f/entry :registry_delete_events (f/seq-of RegistryDeleteType)
:description "a list of `RegistryDeleteType`")
(f/entry :registry_rename_events (f/seq-of RegistryRenameType)
:description "a list of `RegistryRenameType`")))