-
Notifications
You must be signed in to change notification settings - Fork 0
/
xtimeline
executable file
·64 lines (57 loc) · 1.79 KB
/
xtimeline
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
#!/usr/bin/python3
import sys, os
import time
import json
from datetime import datetime, timedelta
from tapyr.api import Tapir, Node
session = Tapir()
def chunks(l, n):
for i in range(0, len(l), n):
yield l[i:i + n]
# .....#XXX write to file directly rather than stdout?
if len(sys.argv) == 3 or len(sys.argv) == 4:
if len(sys.argv) == 4 and sys.argv[3] != '-':
file = open(sys.argv[3], 'w')
else:
file = sys.stdout
timeline = session.timeline(sys.argv[1] + "-00:00", sys.argv[2] + "-00:00")
file.write("time;attribute;path;data\n")
timelinechunks = chunks(timeline, 10000)
for timelinechunk in timelinechunks:
nodes_id = []
for timeobject in timelinechunk:
nodes_id += (timeobject["id"],)
try:
nodes = session.nodes_by_id(nodes_id, path = True)
except :
print("error getting nodes retrying")
nodes = session.nodes_by_id(nodes_id, path = True)
for i in range(0, len(nodes)):
timeobject = timelinechunk[i]
node = nodes[i]
time = timeobject["time"]
time_attribute = timeobject["attribute_name"]
data = ""
try :
data += str(node.evtx.event.eventdata)
except:
pass
try:
data += str(node.registry)
except:
pass
file.write('"' + time + '";"' + time_attribute + '";"' + node.path + '";"' + data + '"\n')
file.close()
else:
usage = "Usage: " + sys.argv[0] + " after before [file]"
now = datetime.now()
last_two_week = now - timedelta(days=14)
now = now.strftime("%Y-%m-%dT%H:%M:%S")
last_two_week = last_two_week.strftime("%Y-%m-%dT%H:%M:%S")
example = """
Display a timeline.
Date after and before must follow rfc3339
Examples (last two weeks):
./timeline """ + last_two_week + ' ' + now + ' [file]'
print(usage)
print(example)