-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex_creation.py
139 lines (90 loc) · 3.91 KB
/
index_creation.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
129
130
131
132
133
134
135
136
137
import os
import json
import db_classes as orm
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
import psycopg2
psql_connection_url = 'postgresql+psycopg2://csephase2:csephase@@localhost/darpa_tc3'
filename = '/mnt/8tb/csenrc/representation_learning_codes/index_file.json'
index_map = dict()
psql_engine = create_engine(psql_connection_url)
Session = sessionmaker(bind=psql_engine)
session = Session()
mapping_code = {"EVENT":1,
"HOST":2,
"PRINCIPAL":3,
"SUBJECT":4,
"FILE":5,
"UNNAMED_PIPE":6,
"MEMORY":7,
"NETFLOW":8,
"SRC_SINK":9,
"PACKET_SOCKET":10,
"PROVENANCE_TAG":11,
"REGISTRY_KEY":12}
event_uuid_list = session.query(orm.Event.uuid).all()
for event_uuid in event_uuid_list:
index_map[event_uuid[0]] = mapping_code["EVENT"]
event_uuid_list.clear()
print("Event indexing complete")
host_uuid_list = session.query(orm.Host.uuid).all()
for host_uuid in host_uuid_list:
index_map[host_uuid[0]] = mapping_code["HOST"]
host_uuid_list.clear()
print("Host indexing complete")
principal_uuid_list = session.query(orm.Principal.uuid).all()
for principal_uuid in principal_uuid_list:
index_map[principal_uuid[0]] = mapping_code["PRINCIPAL"]
principal_uuid_list.clear()
print("Principal indexing complete")
subject_uuid_list = session.query(orm.Subject.uuid).all()
for subject_uuid in subject_uuid_list:
index_map[subject_uuid[0]] = mapping_code["SUBJECT"]
subject_uuid_list.clear()
print("Subject indexing complete")
file_uuid_list = session.query(orm.FileObject.uuid).all()
for file_uuid in file_uuid_list:
index_map[file_uuid[0]] = mapping_code["FILE"]
file_uuid_list.clear()
print("File indexing complete")
unnamed_pipe_uuid_list = session.query(orm.UnnamedPipeObject.uuid).all()
for unnamed_pipe_uuid in unnamed_pipe_uuid_list:
index_map[unnamed_pipe_uuid[0]] = mapping_code["UNNAMED_PIPE"]
unnamed_pipe_uuid_list.clear()
print("Unnamed pipe indexing complete")
memory_object_uuid_list = session.query(orm.MemoryObject.uuid).all()
for memory_object_uuid in memory_object_uuid_list:
index_map[memory_object_uuid[0]] = mapping_code["MEMORY"]
memory_object_uuid_list.clear()
print("Memory object indexing complete")
netflow_object_uuid_list = session.query(orm.NetFlowObject.uuid).all()
for netflow_object_uuid in netflow_object_uuid_list:
index_map[netflow_object_uuid[0]] = mapping_code["NETFLOW"]
netflow_object_uuid_list.clear()
print("Netflow object indexing complete")
src_sink_object_uuid_list = session.query(orm.SrcSinkObject.uuid).all()
for src_sink_object_uuid in src_sink_object_uuid_list:
index_map[src_sink_object_uuid[0]] = mapping_code["SRC_SINK"]
src_sink_object_uuid_list.clear()
print("SrcSink object indexing complete")
packet_socket_object_uuid_list = session.query(orm.PacketSocketObject.uuid).all()
for packet_socket_object_uuid in packet_socket_object_uuid_list:
index_map[packet_socket_object_uuid[0]] = mapping_code["PACKET_SOCKET"]
packet_socket_object_uuid_list.clear()
print("Packet socket object indexing complete")
provenance_tag_node_uuid_list = session.query(orm.ProvenanceTagNode.tag_id).all()
for provenance_tag_node_uuid in provenance_tag_node_uuid_list:
index_map[provenance_tag_node_uuid[0]] = mapping_code["PROVENANCE_TAG"]
provenance_tag_node_uuid_list.clear()
print("Provenance tag node indexing complete")
registry_key_uuid_list = session.query(orm.RegistryKeyObject.uuid).all()
for registry_key_uuid in registry_key_uuid_list:
index_map[registry_key_uuid[0]] = mapping_code["REGISTRY_KEY"]
registry_key_uuid_list.clear()
print("Registry key indexing complete")
session.close()
print("Length of index map: ", len(index_map))
with open(filename, 'w') as outfile:
json.dump(index_map, outfile)
outfile.close()
print("Index file creation complete")