-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbuildattck.py
128 lines (115 loc) · 4.96 KB
/
buildattck.py
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
import json
import csv
finobj = []
# Get this at https://github.com/mitre/cti/blob/master/enterprise-attack/enterprise-attack.json
#with open("enterprise-attack.json") as f:
# data = json.load(f)
# for i in data["objects"]:
# if i["type"] == "attack-pattern":
# if "external_references" in i:
# for id in i["external_references"]:
# if "external_id" in id and "description" in i:
# finobj.append(
# {"name": i["name"], "description": i["description"], "tag": id["external_id"], "url": id["url"]})
################## collecting tactics ##################
# Get this at https://attack.mitre.org/docs/enterprise-attack-v16.1/enterprise-attack-v16.1-tactics.xlsx
# Then save as csv the first sheet
with open("enterprise-attack-v16.1-tactics.csv", mode="r") as f:
data = csv.reader(f, delimiter=',')
for row in data:
id = row[0]
name = row[2]
desc = row[3]
url = row[4]
if id == "ID": # skipping header
continue
finobj.append({"name": name, "description": desc, "tag":id, "url":url})
################## collecting techniques ##################
# Get this at https://attack.mitre.org/docs/enterprise-attack-v16.1/enterprise-attack-v16.1-techniques.xlsx
# Then save as csv the first sheet
with open("enterprise-attack-v16.1-techniques.csv", mode="r") as f:
data = csv.reader(f, delimiter=',')
for row in data:
id = row[0]
name = row[2]
desc = row[3]
url = row[4]
if id == "ID": # skipping header
continue
finobj.append({"name": name, "description": desc, "tag":id, "url":url})
################## collecting software ##################
# Get this at https://attack.mitre.org/docs/enterprise-attack-v16.1/enterprise-attack-v16.1-software.xlsx
# Then save as csv the first sheet
with open("enterprise-attack-v16.1-software.csv", mode="r") as f:
data = csv.reader(f, delimiter=',')
for row in data:
id = row[0]
name = row[2]
desc = row[3]
url = row[4]
if id == "ID": # skipping header
continue
finobj.append({"name": name, "description": desc, "tag":id, "url":url})
################## collecting groups ##################
# Get this at https://attack.mitre.org/docs/enterprise-attack-v16.1/enterprise-attack-v16.1-groups.xlsx
# Then save as csv the first sheet
with open("enterprise-attack-v16.1-groups.csv", mode="r") as f:
data = csv.reader(f, delimiter=',')
for row in data:
id = row[0]
name = row[2]
desc = row[3]
url = row[4]
if id == "ID": # skipping header
continue
finobj.append({"name": name, "description": desc, "tag":id, "url":url})
################## collecting campaigns ##################
# Get this at https://attack.mitre.org/docs/enterprise-attack-v16.1/enterprise-attack-v16.1-campaigns.xlsx
# Then save as csv the first sheet
with open("enterprise-attack-v16.1-campaigns.csv", mode="r") as f:
data = csv.reader(f, delimiter=',')
for row in data:
id = row[0]
name = row[2]
desc = row[3]
url = row[4]
if id == "ID": # skipping header
continue
finobj.append({"name": name, "description": desc, "tag":id, "url":url})
################## collecting datasources ##################
# Get this at https://attack.mitre.org/docs/enterprise-attack-v16.1/enterprise-attack-v16.1-datasources.xlsx
# Then save as csv the first sheet
with open("enterprise-attack-v16.1-datasources.csv", mode="r") as f:
data = csv.reader(f, delimiter=',')
for row in data:
id = row[1]
name = row[0]
desc = row[3]
url = row[10]
if id == "" or id == "ID": # skipping header and empty datasource
continue
finobj.append({"name": name, "description": desc, "tag":id, "url":url})
################## collecting mitigations ##################
# Get this at https://attack.mitre.org/docs/enterprise-attack-v16.1/enterprise-attack-v16.1-mitigations.xlsx
# Then save as csv the first sheet
with open("enterprise-attack-v16.1-mitigations.csv", mode="r") as f:
data = csv.reader(f, delimiter=',')
for row in data:
id = row[0]
name = row[2]
desc = row[3]
url = row[4]
if id == "ID": # skipping header
continue
finobj.append({"name": name, "description": desc, "tag":id, "url":url})
# Get this at https://d3fend.mitre.org/ontologies/d3fend.csv
with open("d3fend.csv") as file:
spamreader = csv.reader(file, delimiter=',')
for row in spamreader:
id = row[0]
name= row[2] if row[2] != '' else row[3] if row[3] != '' else row[4]
desc = row[5]
finobj.append({"name": name, "description": desc, "tag":id, "url":"https://d3fend.mitre.org/"})
finobj.sort(key=lambda x: x["tag"])
with open("./src/techniques.json", 'w') as nf:
nf.write(json.dumps(finobj, indent=4))