forked from Nazicc/WebMap
-
Notifications
You must be signed in to change notification settings - Fork 11
/
ndiff.py
129 lines (106 loc) · 3.44 KB
/
ndiff.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
from django.shortcuts import render
from django.http import HttpResponse
import xmltodict, json, html, os, hashlib, re, urllib.parse, base64
from collections import OrderedDict
from nmapreport.functions import *
def ndiff(request, f1, f2):
f = {}
if token_check(request.GET['token']) is not True:
return HttpResponse(json.dumps({'error':'invalid token'}, indent=4), content_type="application/json")
f['f1'] = get_ports_details(f1)
f['f2'] = get_ports_details(f2)
r = get_diff(f['f1'],f['f2'])
return HttpResponse(json.dumps(r, indent=4), content_type="application/json")
def check_cve_id(cveid, cveobj):
for f1cvei in cveobj:
for cvei in f1cvei:
if cveid == cvei['id']:
return True
return False
def get_diff(f1,f2):
r = {'hosts':{}, 'ports':{}, 'cve':{}}
# ports f1 > f2
for host in f1['hosts']:
if host in f2['hosts']:
r['hosts'][host] = '='
else:
r['hosts'][host] = '>'
for i in f1['hosts'][host]['ports']:
if host not in r['ports']:
r['ports'][host] = {}
if i['port'] not in r['ports'][host]:
# r['ports'][host][i['port']] = {}
r['ports'][host][i['port']] = {
'port': '>',
'name': '>',
'state': '>',
'product': '>',
'extrainfo': '>',
'diff': {}
}
if host in f2['hosts']:
for f2p in f2['hosts'][host]['ports']:
if i['port'] == f2p['port']:
r['ports'][host][i['port']]['port'] = '='
if i['name'] == f2p['name']:
r['ports'][host][i['port']]['name'] = '='
if i['state'] == f2p['state']:
r['ports'][host][i['port']]['state'] = '='
if i['product'] == f2p['product']:
r['ports'][host][i['port']]['product'] = '='
if i['extrainfo'] == f2p['extrainfo']:
r['ports'][host][i['port']]['extrainfo'] = '='
r['ports'][host][i['port']]['diff']['f1'] = i
# ports f1 < f2
for host in f2['hosts']:
if host in f1['hosts']:
r['hosts'][host] = '='
else:
r['hosts'][host] = '<'
for i in f2['hosts'][host]['ports']:
if host not in r['ports']:
r['ports'][host] = {}
if i['port'] not in r['ports'][host]:
#r['ports'][host][i['port']] = {}
r['ports'][host][i['port']] = {
'port': '<',
'name': '<',
'state': '<',
'product': '<',
'extrainfo': '<',
'diff': {}
}
if host in f1['hosts']:
for f1p in f1['hosts'][host]['ports']:
if i['port'] == f1p['port']:
r['ports'][host][i['port']]['port'] = '='
if i['name'] == f1p['name']:
r['ports'][host][i['port']]['name'] = '='
if i['state'] == f1p['state']:
r['ports'][host][i['port']]['state'] = '='
if i['product'] == f1p['product']:
r['ports'][host][i['port']]['product'] = '='
if i['extrainfo'] == f1p['extrainfo']:
r['ports'][host][i['port']]['extrainfo'] = '='
r['ports'][host][i['port']]['diff']['f2'] = i
for host in f1['hosts']:
if host not in r['cve']:
r['cve'][host] = {}
for f1cvei in f1['hosts'][host]['CVE']:
for cvei in f1cvei:
if host in f2['hosts']:
if check_cve_id(cvei['id'], f2['hosts'][host]['CVE']) is not False:
r['cve'][host][cvei['id']] = '='
else:
r['cve'][host][cvei['id']] = '>'
for host in f2['hosts']:
if host not in r['cve']:
r['cve'][host] = {}
for f2cvei in f2['hosts'][host]['CVE']:
for cvei in f2cvei:
if host in f1['hosts']:
if check_cve_id(cvei['id'], f1['hosts'][host]['CVE']) is not False:
r['cve'][host][cvei['id']] = '='
else:
r['cve'][host][cvei['id']] = '<'
return r