synapse 2.186.0__py311-none-any.whl → 2.188.0__py311-none-any.whl
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.
Potentially problematic release.
This version of synapse might be problematic. Click here for more details.
- synapse/cortex.py +133 -9
- synapse/datamodel.py +20 -4
- synapse/exc.py +14 -1
- synapse/lib/ast.py +6 -4
- synapse/lib/auth.py +9 -0
- synapse/lib/hive.py +1 -1
- synapse/lib/httpapi.py +2 -1
- synapse/lib/modelrev.py +771 -11
- synapse/lib/nexus.py +6 -0
- synapse/lib/node.py +5 -3
- synapse/lib/scrape.py +18 -104
- synapse/lib/spooled.py +26 -3
- synapse/lib/storm.py +51 -28
- synapse/lib/stormlib/model.py +320 -250
- synapse/lib/stormlib/modelext.py +31 -0
- synapse/lib/stormlib/scrape.py +1 -4
- synapse/lib/stormtypes.py +53 -11
- synapse/lib/version.py +2 -2
- synapse/lib/view.py +9 -3
- synapse/models/base.py +27 -0
- synapse/models/files.py +22 -0
- synapse/models/inet.py +49 -4
- synapse/models/infotech.py +49 -22
- synapse/models/orgs.py +64 -2
- synapse/models/proj.py +1 -6
- synapse/models/risk.py +65 -0
- synapse/tests/test_cortex.py +21 -0
- synapse/tests/test_lib_agenda.py +13 -0
- synapse/tests/test_lib_auth.py +15 -0
- synapse/tests/test_lib_cell.py +2 -1
- synapse/tests/test_lib_httpapi.py +6 -0
- synapse/tests/test_lib_modelrev.py +918 -379
- synapse/tests/test_lib_nexus.py +26 -0
- synapse/tests/test_lib_scrape.py +14 -6
- synapse/tests/test_lib_spooled.py +34 -0
- synapse/tests/test_lib_storm.py +48 -0
- synapse/tests/test_lib_stormlib_model.py +0 -270
- synapse/tests/test_lib_stormlib_modelext.py +76 -1
- synapse/tests/test_lib_stormlib_scrape.py +0 -8
- synapse/tests/test_lib_stormtypes.py +12 -1
- synapse/tests/test_lib_trigger.py +8 -0
- synapse/tests/test_lib_view.py +24 -0
- synapse/tests/test_model_base.py +11 -0
- synapse/tests/test_model_files.py +19 -0
- synapse/tests/test_model_inet.py +33 -0
- synapse/tests/test_model_infotech.py +14 -11
- synapse/tests/test_model_orgs.py +39 -0
- synapse/tests/test_model_proj.py +11 -1
- synapse/tests/test_model_risk.py +32 -0
- synapse/tools/changelog.py +11 -3
- {synapse-2.186.0.dist-info → synapse-2.188.0.dist-info}/METADATA +1 -1
- {synapse-2.186.0.dist-info → synapse-2.188.0.dist-info}/RECORD +55 -58
- synapse/assets/__init__.py +0 -35
- synapse/assets/storm/migrations/model-0.2.28.storm +0 -355
- synapse/tests/test_assets.py +0 -25
- {synapse-2.186.0.dist-info → synapse-2.188.0.dist-info}/LICENSE +0 -0
- {synapse-2.186.0.dist-info → synapse-2.188.0.dist-info}/WHEEL +0 -0
- {synapse-2.186.0.dist-info → synapse-2.188.0.dist-info}/top_level.txt +0 -0
|
@@ -1,355 +0,0 @@
|
|
|
1
|
-
$layers = $lib.spooled.set()
|
|
2
|
-
$layers.adds($layridens)
|
|
3
|
-
|
|
4
|
-
$refinfoCache = ({})
|
|
5
|
-
|
|
6
|
-
function getRefInfo(formname) {
|
|
7
|
-
$cached = $refinfoCache.$formname
|
|
8
|
-
if $cached { return($cached) }
|
|
9
|
-
|
|
10
|
-
$refinfo = ([])
|
|
11
|
-
|
|
12
|
-
syn:prop:type*in=($formname, array, ndef)
|
|
13
|
-
// Don't include the form we're querying
|
|
14
|
-
-:form = $formname
|
|
15
|
-
|
|
16
|
-
$prop = $lib.model.prop($node.repr())
|
|
17
|
-
$proptype = $prop.type.name
|
|
18
|
-
|
|
19
|
-
// Don't include array types that don't have a base type of $formname or ndef
|
|
20
|
-
-$($proptype = 'array' and not ([$formname, 'ndef']).has($prop.type.opts.type))
|
|
21
|
-
|
|
22
|
-
$isarray = $lib.false
|
|
23
|
-
|
|
24
|
-
if ($proptype = 'array') {
|
|
25
|
-
$isarray = $lib.true
|
|
26
|
-
$proptype = $prop.type.opts.type
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
$refinfo.append((:form, $prop.name, $proptype, $isarray))
|
|
30
|
-
|
|
31
|
-
fini {
|
|
32
|
-
$refinfoCache.$formname = $refinfo
|
|
33
|
-
return($refinfo)
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function removeNode(n, viewiden, layriden) {
|
|
38
|
-
|
|
39
|
-
$nodeq = $lib.queue.gen("model_0_2_28:nodes")
|
|
40
|
-
$refsq = $lib.queue.gen("model_0_2_28:nodes:refs")
|
|
41
|
-
$edgeq = $lib.queue.gen("model_0_2_28:nodes:edges")
|
|
42
|
-
|
|
43
|
-
$sources = ([])
|
|
44
|
-
|
|
45
|
-
$iden = $n.iden()
|
|
46
|
-
$repr = $n.repr()
|
|
47
|
-
$form = $n.form()
|
|
48
|
-
$ndef = $n.ndef()
|
|
49
|
-
|
|
50
|
-
$lib.log.debug(`Saving invalid {$form} node info: {$repr}`)
|
|
51
|
-
|
|
52
|
-
$refinfos = $getRefInfo($form)
|
|
53
|
-
|
|
54
|
-
for $view in $lib.view.list(deporder=$lib.true) {
|
|
55
|
-
if (not $layers.has($view.layers.0.iden)) { continue }
|
|
56
|
-
|
|
57
|
-
view.exec $view.iden {
|
|
58
|
-
$edges = ([])
|
|
59
|
-
$references = ([])
|
|
60
|
-
|
|
61
|
-
// Get references and store them in queue
|
|
62
|
-
for $refinfo in $refinfos {
|
|
63
|
-
|
|
64
|
-
($formname, $propname, $proptype, $isarray) = $refinfo
|
|
65
|
-
if ($proptype = "ndef") {
|
|
66
|
-
$oldvalu = $ndef
|
|
67
|
-
} else {
|
|
68
|
-
$oldvalu = $repr
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
for $ref in $lib.model.migration.liftByPropValuNoNorm($formname, $propname, $oldvalu) {
|
|
72
|
-
yield $ref
|
|
73
|
-
|
|
74
|
-
if $isarray {
|
|
75
|
-
|
|
76
|
-
// We can't just [ :$propname-=$oldvalu ] because the norm() function gets called on the array type
|
|
77
|
-
// deep down in the AST. So, instead, we have to operate on the whole array.
|
|
78
|
-
|
|
79
|
-
$list = $lib.copy(:$propname)
|
|
80
|
-
$list.rem($oldvalu, all=$lib.true)
|
|
81
|
-
|
|
82
|
-
if $list {
|
|
83
|
-
$lib.model.migration.setNodePropValuNoNorm($node, $propname, $list)
|
|
84
|
-
} else {
|
|
85
|
-
[ -:$propname ]
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
} else {
|
|
89
|
-
try {
|
|
90
|
-
[ -:$propname ]
|
|
91
|
-
} catch ReadOnlyProp as exc {
|
|
92
|
-
// The property is readonly so we can only delete it
|
|
93
|
-
$lib.log.warning(`{$formname}:{$propname} is readonly, cannot modify. Storing node: {$node.repr()}`)
|
|
94
|
-
$removeNode($node, $view.iden, $view.layers.0.iden)
|
|
95
|
-
| delnode |
|
|
96
|
-
continue
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
$ref = ({
|
|
101
|
-
"iden": $node.iden(),
|
|
102
|
-
"refinfo": $refinfo,
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
$references.append($ref)
|
|
106
|
-
|
|
107
|
-
// Flush to the queue if the list grows too large
|
|
108
|
-
if ($references.size() > 1000) { // pragma: no cover start
|
|
109
|
-
$item = ({
|
|
110
|
-
"iden": $iden,
|
|
111
|
-
"view": $view.iden,
|
|
112
|
-
"refs": $references,
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
$refsq.put($item)
|
|
116
|
-
$references = ([])
|
|
117
|
-
} // pragma: no cover stop
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if $references {
|
|
122
|
-
$item = ({
|
|
123
|
-
"iden": $iden,
|
|
124
|
-
"view": $view.iden,
|
|
125
|
-
"refs": $references,
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
$refsq.put($item)
|
|
129
|
-
$references = ([])
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
spin |
|
|
133
|
-
|
|
134
|
-
yield $iden |
|
|
135
|
-
|
|
136
|
-
// Get sources and store them in the queue
|
|
137
|
-
// Do this before we store/delete edges.
|
|
138
|
-
{ <(seen)- meta:source
|
|
139
|
-
$sources.append($node.repr())
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// Get N1 edges and store them in the queue
|
|
143
|
-
{ for $edge in $node.edges() {
|
|
144
|
-
($verb, $dst) = $edge
|
|
145
|
-
$edges.append($edge)
|
|
146
|
-
|
|
147
|
-
[ -($verb)> { yield $dst } ]
|
|
148
|
-
|
|
149
|
-
// Flush to the queue if the list grows too large
|
|
150
|
-
if ($edges.size() > 1000) { // pragma: no cover start
|
|
151
|
-
$item = ({
|
|
152
|
-
"iden": $iden,
|
|
153
|
-
"view": $view.iden,
|
|
154
|
-
"direction": "n1",
|
|
155
|
-
"edges": $edges,
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
$edgeq.put($item)
|
|
159
|
-
$edges = ([])
|
|
160
|
-
} // pragma: no cover stop
|
|
161
|
-
}}
|
|
162
|
-
|
|
163
|
-
if $edges {
|
|
164
|
-
$item = ({
|
|
165
|
-
"iden": $iden,
|
|
166
|
-
"view": $view.iden,
|
|
167
|
-
"direction": "n1",
|
|
168
|
-
"edges": $edges,
|
|
169
|
-
})
|
|
170
|
-
|
|
171
|
-
$edgeq.put($item)
|
|
172
|
-
$edges = ([])
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// Get N2 edges and store them in the queue
|
|
176
|
-
{ for $edge in $node.edges(reverse=$lib.true) {
|
|
177
|
-
($verb, $src) = $edge
|
|
178
|
-
$edges.append($edge)
|
|
179
|
-
|
|
180
|
-
[ <($verb)- { yield $src } ]
|
|
181
|
-
|
|
182
|
-
// Flush to the queue if the list grows too large
|
|
183
|
-
if ($edges.size() > 1000) { // pragma: no cover start
|
|
184
|
-
$item = ({
|
|
185
|
-
"iden": $iden,
|
|
186
|
-
"view": $view.iden,
|
|
187
|
-
"direction": "n2",
|
|
188
|
-
"edges": $edges,
|
|
189
|
-
})
|
|
190
|
-
|
|
191
|
-
$edgeq.put($item)
|
|
192
|
-
$edges = ([])
|
|
193
|
-
} // pragma: no cover stop
|
|
194
|
-
}}
|
|
195
|
-
|
|
196
|
-
if $edges {
|
|
197
|
-
$item = ({
|
|
198
|
-
"iden": $iden,
|
|
199
|
-
"view": $view.iden,
|
|
200
|
-
"direction": "n2",
|
|
201
|
-
"edges": $edges,
|
|
202
|
-
})
|
|
203
|
-
|
|
204
|
-
$edgeq.put($item)
|
|
205
|
-
$edges = ([])
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
$item = ({
|
|
211
|
-
"iden": $iden,
|
|
212
|
-
"form": $form,
|
|
213
|
-
"repr": $repr,
|
|
214
|
-
"props": $n.props,
|
|
215
|
-
"view": $viewiden,
|
|
216
|
-
"layer": $layriden,
|
|
217
|
-
"tags": $n.tags(),
|
|
218
|
-
"data": $n.data.list(),
|
|
219
|
-
"sources": $sources,
|
|
220
|
-
})
|
|
221
|
-
|
|
222
|
-
$nodeq.put($item)
|
|
223
|
-
|
|
224
|
-
return()
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
function migrateCpeNode(oldcpe, newcpe) {
|
|
228
|
-
|
|
229
|
-
// migrate the edges, tags, node data, and extended props
|
|
230
|
-
$lib.model.migration.copyEdges($oldcpe, $newcpe)
|
|
231
|
-
$lib.model.migration.copyTags($oldcpe, $newcpe)
|
|
232
|
-
$lib.model.migration.copyData($oldcpe, $newcpe)
|
|
233
|
-
$lib.model.migration.copyExtProps($oldcpe, $newcpe)
|
|
234
|
-
|
|
235
|
-
$refinfos = $getRefInfo($oldcpe.form())
|
|
236
|
-
|
|
237
|
-
// Iterate through the views and fix up all the references
|
|
238
|
-
for $view in $lib.view.list(deporder=$lib.true) {
|
|
239
|
-
if (not $layers.has($view.layers.0.iden)) { continue }
|
|
240
|
-
|
|
241
|
-
view.exec $view.iden {
|
|
242
|
-
|
|
243
|
-
// Fix references that point to old node to now point to new node
|
|
244
|
-
for $refinfo in $refinfos {
|
|
245
|
-
($form, $prop, $proptype, $isarray) = $refinfo
|
|
246
|
-
if ($proptype = "ndef") {
|
|
247
|
-
$oldvalu = $oldcpe.ndef()
|
|
248
|
-
$newvalu = $newcpe.ndef()
|
|
249
|
-
} else {
|
|
250
|
-
$oldvalu = $oldcpe.repr()
|
|
251
|
-
$newvalu = $newcpe.repr()
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
for $n in $lib.model.migration.liftByPropValuNoNorm($form, $prop, $oldvalu) {
|
|
255
|
-
yield $n
|
|
256
|
-
|
|
257
|
-
if $isarray {
|
|
258
|
-
|
|
259
|
-
// We can't just [ :$prop-=$oldvalu :$prop+=$newvalu ] because the norm() function gets called
|
|
260
|
-
// on the array type deep down in the AST. So, instead, we have to operate on the whole array.
|
|
261
|
-
|
|
262
|
-
$list = $lib.copy(:$prop)
|
|
263
|
-
$list.rem($oldvalu, all=$lib.true)
|
|
264
|
-
|
|
265
|
-
if (not $list.has($newvalu)) {
|
|
266
|
-
$list.append($newvalu)
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
$lib.model.migration.setNodePropValuNoNorm($node, $prop, $list)
|
|
270
|
-
|
|
271
|
-
} else {
|
|
272
|
-
try {
|
|
273
|
-
[ -:$prop :$prop=$newvalu ]
|
|
274
|
-
} catch ReadOnlyProp as exc {
|
|
275
|
-
// The property is readonly so we can only delete it
|
|
276
|
-
$lib.log.warning(`{$form}:{$prop} is readonly, cannot modify. Storing node: {$node.repr()}`)
|
|
277
|
-
$removeNode($node, $view.iden, $view.layers.0.iden)
|
|
278
|
-
| delnode
|
|
279
|
-
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
return()
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
// This is a separate function because I was getting weird bugs from scoping
|
|
291
|
-
// issues. Mainly, the $view variable being overwritten because this code was
|
|
292
|
-
// scoped to the whole script.
|
|
293
|
-
function main() {
|
|
294
|
-
|
|
295
|
-
for $view in $lib.view.list(deporder=$lib.true) {
|
|
296
|
-
|
|
297
|
-
if (not $layers.has($view.layers.0.iden)) { continue }
|
|
298
|
-
|
|
299
|
-
view.exec $view.iden {
|
|
300
|
-
|
|
301
|
-
$layer = $lib.layer.get()
|
|
302
|
-
|
|
303
|
-
for $oldcpe in $layer.liftByProp(it:sec:cpe) {
|
|
304
|
-
$info = $lib.model.migration.s.itSecCpe_2_170_0_internal($oldcpe)
|
|
305
|
-
|
|
306
|
-
if ($info.status = "success") {
|
|
307
|
-
// No primary property changes, nothing to do. Node has been fully migrated.
|
|
308
|
-
if (not $info.valu) {
|
|
309
|
-
continue
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
/*
|
|
313
|
-
* At this point, we have a node that can be fixed but
|
|
314
|
-
* needs to be migrated to a new node because the primary
|
|
315
|
-
* property needs to be changed. We'll create a new
|
|
316
|
-
* (correct) node, and copy everything from the old node.
|
|
317
|
-
* Then we complete the migration by iterating through
|
|
318
|
-
* all the views to fix the references.
|
|
319
|
-
*/
|
|
320
|
-
|
|
321
|
-
$lib.log.debug(`Migrating invalid it:sec:cpe node: {$oldcpe.repr()} -> {$info.valu}`)
|
|
322
|
-
|
|
323
|
-
[ it:sec:cpe=$info.valu
|
|
324
|
-
.seen ?= $oldcpe.props.".seen"
|
|
325
|
-
]
|
|
326
|
-
|
|
327
|
-
$migrateCpeNode($oldcpe, $node)
|
|
328
|
-
|
|
329
|
-
spin |
|
|
330
|
-
|
|
331
|
-
yield $oldcpe |
|
|
332
|
-
delnode --deledges --force
|
|
333
|
-
|
|
334
|
-
} else {
|
|
335
|
-
|
|
336
|
-
// Node could not be automatically migrated. Collect
|
|
337
|
-
// critical information to eventually reconstruct this node
|
|
338
|
-
// and store it in a queue.
|
|
339
|
-
|
|
340
|
-
$removeNode($oldcpe, $view.iden, $view.layers.0.iden)
|
|
341
|
-
|
|
342
|
-
yield $oldcpe |
|
|
343
|
-
delnode --deledges --force
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
return()
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
// Pre-cache the it:sec:cpe references
|
|
353
|
-
$getRefInfo(it:sec:cpe)
|
|
354
|
-
|
|
355
|
-
$main()
|
synapse/tests/test_assets.py
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import synapse.assets as s_assets
|
|
3
|
-
|
|
4
|
-
import synapse.tests.utils as s_t_utils
|
|
5
|
-
|
|
6
|
-
class TestAssets(s_t_utils.SynTest):
|
|
7
|
-
|
|
8
|
-
def test_assets_path(self):
|
|
9
|
-
|
|
10
|
-
fp = s_assets.getAssetPath('storm', 'migrations', 'model-0.2.28.storm')
|
|
11
|
-
self.true(os.path.isfile(fp))
|
|
12
|
-
|
|
13
|
-
with self.raises(ValueError) as cm:
|
|
14
|
-
s_assets.getAssetPath('../../../../../../../etc/passwd')
|
|
15
|
-
self.isin('Path escaping', str(cm.exception))
|
|
16
|
-
|
|
17
|
-
with self.raises(ValueError) as cm:
|
|
18
|
-
s_assets.getAssetPath('newp', 'does', 'not', 'exit')
|
|
19
|
-
self.isin('Asset does not exist', str(cm.exception))
|
|
20
|
-
|
|
21
|
-
def test_assets_storm(self):
|
|
22
|
-
|
|
23
|
-
text = s_assets.getStorm('migrations', 'model-0.2.28.storm')
|
|
24
|
-
self.isinstance(text, str)
|
|
25
|
-
self.gt(len(text), 0)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|