forked from iann0036/iam-dataset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscratch.js
69 lines (57 loc) · 2.52 KB
/
scratch.js
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
// add dependants
var mapdata = await fetch('https://raw.githubusercontent.com/iann0036/iam-dataset/main/map.json');
map = await mapdata.json();
var iamdefdata = await fetch('https://raw.githubusercontent.com/iann0036/iam-dataset/main/js/iam_definition.json');
iamdef = await iamdefdata.json();
for (var iamdefitem of iamdef) {
iamdefitem.prefix
for (var priv of iamdefitem.privileges) {
priv.privilege
for (var restype of priv.resource_types) {
if (restype['dependent_actions'].length > 0) {
for (var depaction of restype['dependent_actions']) {
//console.log(depaction + " - " + iamdefitem.prefix + ":" + priv.privilege);
for (var iammappingkey of Object.keys(map['sdk_method_iam_mappings'])) {
if (map['sdk_method_iam_mappings'][iammappingkey][0]['action'] == (iamdefitem.prefix + ":" + priv.privilege)) {
map['sdk_method_iam_mappings'][iammappingkey].unshift({
'action': depaction,
'documented_dependant_action': true
});
}
}
}
}
}
}
}
// find dependency chains
var mapdata = await fetch('https://raw.githubusercontent.com/iann0036/iam-dataset/main/map.json');
map = await mapdata.json();
var iamdefdata = await fetch('https://raw.githubusercontent.com/iann0036/iam-dataset/main/js/iam_definition.json');
iamdef = await iamdefdata.json();
var chains = [];
for (var j=0; j<20; j++) {
for (var iamdefitem of iamdef) {
for (var priv of iamdefitem.privileges) {
for (var restype of priv.resource_types) {
if (restype['dependent_actions'].length > 0) {
for (var depaction of restype['dependent_actions']) {
var chainslength = chains.length;
for (var i=0; i<chainslength; i++) {
if (chains[i][0] == depaction) {
chains[i].unshift(iamdefitem.prefix + ":" + priv.privilege);
}
}
chains.push([iamdefitem.prefix + ":" + priv.privilege, depaction]);
}
}
}
}
}
}
chains = chains.filter(x => x.length > 2);
let set = new Set(chains.map(JSON.stringify));
let arr2 = Array.from(set).map(JSON.parse);
for (var el of arr2) {
console.log(el.join(","));
}