-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapData.py
More file actions
93 lines (80 loc) · 2.8 KB
/
Copy pathmapData.py
File metadata and controls
93 lines (80 loc) · 2.8 KB
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
import networkx as nx
import matplotlib.pyplot as plt
#import csv
import json
import re
datastore = {'wp':[], 'sql':[], 'server':[], 'ssh':[], 'redis':[]}
G=nx.MultiDiGraph()
def mapData():
#reader = csv.reader(open('datastore.csv', 'r'))
datastore = json.load(open('datastore.json'))
#print type(datastore)
#datastore = {'wp':'', 'sql':'', 'server':'', 'ssh':'', 'redis':''}
#for row in reader:
# k, v = row
#print v
#v = v.replace("[","")
#v = v.replace("]","")
#v = v.split(",")
# datastore[k] = v
print "----Mapping----"
#print datastore
for i, j in datastore.items():
#print j+"JJJJJJJJJJJJ"
if j is not []:
for k in j:
G.add_node(i+":"+k)
'''try: # draw
#pos=nx.spring_layout(G,iterations=1)
nx.draw(G, with_labels=True)
plt.savefig("test.png")
plt.show()
except: # matplotlib not available
print "Nope"
#Call Map'''
map(datastore)
#TODO: One module to map them all
def map(datastore):
#packetData = json.load(open('packetData.json'))
info = open('info', 'r')
info = info.read()
#print type(info)
#Mapping wordpress
for i in datastore['wp']:
#print "THIS IS III"
#print i
for j in datastore['server']:
#print '-'*50
if i == j.split(':')[0]:
#print i, j.split(':')[0]
#print "Adding"
G.add_edge('wp:'+i, 'server:'+j)
for i in datastore['server']:
serverIP = str(i.split(':')[0])
serverName = str(i.split(':')[1])
for j in datastore['sql']:
sqlIP = str(j.split(':')[0])
sqlPort = str(j.split(':')[1])
#print type(serverIP), type(serverName), type(sqlIP), type(sqlPort)
if re.search('Source Port: (.)* Dest Port: '+sqlPort+' Source Address: '+serverIP+' Dest Address: '+sqlIP, info):
#print "Coming in SQL"
G.add_edge('server:'+i, 'sql:'+j)
for i in datastore['server']:
serverIP = str(i.split(':')[0])
serverName = str(i.split(':')[1])
for j in datastore['redis']:
if re.search('Source Port: (.)* Dest Port: 6379 Source Address: '+serverIP+' Dest Address: '+j, info):
G.add_edge('server:'+i, 'redis:'+j)
for i in datastore['sql']:
for j in datastore['sql']:
sqlIP1 = str(i.split(':')[0])
sqlPort1 = str(i.split(':')[1])
sqlIP2 = str(j.split(':')[0])
sqlPort2 = str(j.split(':')[1])
if re.search('Source Port: '+sqlPort1+' Dest Port'+sqlPort2, info):
G.add_edge('sql:'+i, 'sql:'+j)
nx.draw(G, with_labels=True)
plt.savefig("test.png")
plt.show()
#except:
# print "Nah"