-
Notifications
You must be signed in to change notification settings - Fork 1
/
Azure-Sentinel-yaml-to-csv.py
69 lines (48 loc) · 1.53 KB
/
Azure-Sentinel-yaml-to-csv.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
# git clone https://github.com/Azure/Azure-Sentinel.git
# mkdir EXPORT
# mv Detections .\EXPORT\
# mv "Hunting Queries" .\EXPORT\
# mv "Exploration Queries" .\EXPORT\
# cd .\EXPORT\
# find . -type f -iname "*.y*" -exec python 1.py '{}' \;
# for time/sleep
import time
# to convert yaml
import yaml
# for command line args
import sys
#for logging
import logging
# regex
import re
# for command line args
import sys
# sys.argv[0]
with open(sys.argv[1], 'r') as f:
doc = yaml.load(f, Loader=yaml.FullLoader) # also, yaml.SafeLoader
print ("FileName: "+sys.argv[1],"\r")
#print(sys.argv[1]+","+str(doc["id"]))
OUTPUT1 = (sys.argv[1]+"FS2FS1FS2"
+str(doc.get('id', 'NULL'))+"FS2FS1FS2"
+str(doc.get('Id', 'NULL'))+"FS2FS1FS2"
+str(doc.get('name', 'NULL'))+"FS2FS1FS2"
+str(doc.get('DisplayName', 'NULL'))+"FS2FS1FS2"
+str(doc.get('description', 'NULL'))+"FS2FS1FS2"
+str(doc.get('Description', 'NULL'))+"FS2FS1FS2"
+str(doc.get('severity', 'NULL'))+"FS2FS1FS2"
+str(doc.get('tactics', 'NULL'))+"FS2FS1FS2"
# case sensitivie inconsistancy in key names
+str(doc.get('Tactics', 'NULL'))+"FS2FS1FS2"
+str(doc.get('relevantTechniques', 'NULL'))+"FS2FS1FS2"
+str(doc.get('query', 'NULL'))+"FS2FS1FS2"
)
#R1CONTENT = r1.content.decode('utf-8')
#R1CONTENT = R1CONTENT.replace('\n', ' ').replace('\r', '')
OUTPUT1 = str(OUTPUT1)
OUTPUT1 = re.sub('"' , '""', OUTPUT1)
OUTPUT1 = re.sub('FS1' , ',', OUTPUT1)
OUTPUT1 = re.sub('FS2' , '"', OUTPUT1)
OUTPUT1 = re.sub('^' , '"', OUTPUT1)
OUTPUT1 = re.sub('$' , '"\r', OUTPUT1)
print(OUTPUT1)
#time.sleep(1)