forked from DataSoft/Honeyd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_assoc.py
executable file
·74 lines (57 loc) · 1.57 KB
/
generate_assoc.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
#!/usr/local/bin/python
import os
import sys
import re
import string
def get_xprobe(filename):
file = open(filename, "r")
m = re.compile("\s*$")
m2 = re.compile("#.*")
for line in file:
line = m2.sub("", line)
line = m.sub("", line)
if not len(line):
continue
res = re.search('OS_ID\s*=\s*"(.*)"', line)
if not res:
continue
xprobe.append(res.group(1))
file.close()
def find_match(fingerprint):
tokens = string.split(fingerprint, " ")
bestname = None
maxcount = 0
for name in xprobe:
count = 0
for token in tokens:
if len(token) <= 1 and not re.match("[0-9]", token):
continue
if token == "Release" or token == "Kernel" or token == "Server":
continue
if name.find(token) != -1:
if len(token) >= 5:
count += 1
count += 1
if count > maxcount:
maxcount = count
bestname = name
if maxcount > 1 and bestname:
print "%s;%s" % (fingerprint, bestname)
else:
print "#%s;" % fingerprint
def make_configuration(filename):
file = open(filename, "r")
r = re.compile('\s*$')
m = re.compile("^Fingerprint ([^#]*)$")
for line in file:
line = r.sub("", line)
res = m.match(line)
if not res:
continue
fname = res.group(1)
find_match(fname)
file.close()
# Main
xprobe = []
get_xprobe("xprobe2.conf")
make_configuration("nmap-os-db")