/
nw_ip_2_filetype.py
66 lines (50 loc) · 1.96 KB
/
nw_ip_2_filetype.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
#!/usr/bin/env python
# Copyright (C) 2012 nwmaltego Developer.
# This file is part of nwmaltego - https://github.com/bostonlink/nwmaltego
# See the file 'LICENSE' for copying permission.
# Netwitness Maltego IP to filetype transform
# returns NWFiletype entities
# Author: David Bressler (@bostonlink)
import sys
import urllib2, urllib, json
from datetime import datetime, timedelta
from lib import nwmodule
# Maltego XML Header
trans_header = """<MaltegoMessage>
<MaltegoTransformResponseMessage>
<Entities>"""
# Authenticate to the NW Concentrator via HTTP basic auth
nwmodule.nw_http_auth()
# NW REST API Query amd results
ip_entity = sys.argv[1]
date_t = datetime.today()
tdelta = timedelta(days=1)
diff = date_t - tdelta
diff = "'" + diff.strftime('%Y-%b-%d %H:%M:%S') + "'-'" + date_t.strftime('%Y-%b-%d %H:%M:%S') + "'"
field_name = 'filetype'
where_clause = '(time=%s) && ip.dst=%s || ip.src=%s' % (diff, ip_entity, ip_entity)
json_data = json.loads(nwmodule.nwValue(0, 0, 25, field_name, 'application/json', where_clause))
file_list = []
print trans_header
for d in json_data['results']['fields']:
value = d['value'].decode('ascii')
# Kind of a hack but hey it works!
if value in file_list:
continue
else:
print """ <Entity Type="netwitness.NWFiletype">
<Value>%s</Value>
<AdditionalFields>
<Field Name="ip" DisplayName="IP Address">%s</Field>
<Field Name="metaid1" DisplayName="Meta id1">%s</Field>
<Field Name="metaid2" DisplayName="Meta id2">%s</Field>
<Field Name="type" DisplayName="Type">%s</Field>
<Field Name="count" DisplayName="Count">%s</Field>
</AdditionalFields>
</Entity>""" % (value, ip_entity, d['id1'], d['id2'], d['type'], d['count'])
file_list.append(value)
# Maltego transform XML footer
trans_footer = """ </Entities>
</MaltegoTransformResponseMessage>
</MaltegoMessage> """
print trans_footer