-
Notifications
You must be signed in to change notification settings - Fork 17
/
TrustVisualizer.py
executable file
·86 lines (70 loc) · 3.29 KB
/
TrustVisualizer.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
#!/usr/bin/python
##############################################################################
# Author: @harmj0y
#
# Based on: https://github.com/sixdub/DomainTrustExplorer by @sixdub
#
# Description: Usesnetworkx library to transform PowerView's updated
# Get-DomainTrustMapping functionality output to graphml
#
# License: BSD 3-clause
##############################################################################
import networkx as nx
import sys, csv
if __name__ == '__main__':
if (len(sys.argv) != 2):
print "usage: ./TrustVisualizer.py <trust_file.csv>"
exit()
graph = nx.DiGraph()
intputFile = sys.argv[1]
with open(intputFile, 'rb') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
for row in reader:
# if we have the header row, skip
if row[0] == 'SourceName':
continue
# csv format:
# SourceName,TargetName,TrustType,TrustAttributes,TrustDirection,WhenCreated,WhenChanged
ecolor = ''
sourceName = row[0].strip()
targetName = row[1].strip()
trustType = row[2].strip()
trustAttributes = row[3].strip()
trustDirection = row[4].strip()
# if the source and destination domains are the same, skip
if (sourceName == targetName):
continue
if (trustType == 'MIT'):
# black label for MIT trusts
ecolor ='#000000'
else:
if "WITHIN_FOREST" in trustAttributes:
# green label for intra-forest trusts
ecolor = '#009900'
elif (trustAttributes == "FOREST_TRANSITIVE"):
# blue label for inter-forest trusts
ecolor = '#0000CC'
elif ((trustAttributes == "") or (trustAttributes == "TREAT_AS_EXTERNAL") or (trustAttributes == "FILTER_SIDS")):
# red label for external trusts
ecolor = '#FF0000'
else:
# violet label for unknown
print "[-] Unrecognized trust attributes between %s and %s : %s" % (sourceName, targetName, trustAttributes)
ecolor = '#EE82EE'
# add the domain nodes to the internal graph
graph.add_node(sourceName, label=sourceName)
graph.add_node(targetName, label=targetName)
# add the edges to the graph
if "Bidirectional" in trustDirection:
graph.add_edge(sourceName, targetName, color=ecolor)
graph.add_edge(targetName, sourceName, color=ecolor)
elif "Outbound" in trustDirection:
graph.add_edge(targetName, sourceName, color=ecolor)
elif "Inbound" in trustDirection:
graph.add_edge(sourceName, targetName, color=ecolor)
else:
print "[-] Unrecognized relationship direction between %s and %s : %s" % (sourceName, targetName, trustDirection)
outputFile = intputFile + ".graphml"
nx.write_graphml(graph, outputFile)
print "\n[+] Graphml writte to '%s'" % (outputFile)
print "\n[*] Note: green = within forest, red = external, blue = forest to forest, black = MIT, violet = unrecognized\n"