From f94d50613662eb8b67429942000ed078d0ecd601 Mon Sep 17 00:00:00 2001 From: Ronald Date: Fri, 2 Jan 2015 19:52:21 +0000 Subject: [PATCH] bugfix issue46 --- libnmap/objects/os.py | 9 ++++++ libnmap/test/files/test_osclass.xml | 46 +++++++++++++++++++++++++++++ libnmap/test/test_fp.py | 18 +++++++++-- 3 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 libnmap/test/files/test_osclass.xml diff --git a/libnmap/objects/os.py b/libnmap/objects/os.py index 9e52fcc..cc795a7 100644 --- a/libnmap/objects/os.py +++ b/libnmap/objects/os.py @@ -335,6 +335,15 @@ def osmatches(self, min_accuracy=0): return _osmatches + @property + def osclasses(self, min_accuracy=0): + osc_array = [] + for _osm in self.osmatches: + for _osc in _osm.osclasses: + if _osc.accuracy >= min_accuracy: + osc_array.append(_osc) + return osc_array + @property def fingerprint(self): return "\r\n".join(self.__fingerprints) diff --git a/libnmap/test/files/test_osclass.xml b/libnmap/test/files/test_osclass.xml new file mode 100644 index 0000000..bcfd9c6 --- /dev/null +++ b/libnmap/test/files/test_osclass.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +cpe:/o:linux:linux_kernel:3 + + + + + + + + + + + + + \ No newline at end of file diff --git a/libnmap/test/test_fp.py b/libnmap/test/test_fp.py index 8c6dd0b..ec30bcb 100644 --- a/libnmap/test/test_fp.py +++ b/libnmap/test/test_fp.py @@ -17,7 +17,9 @@ def setUp(self): self.flist = self.flist_full self.flist_os = {'nv6': {'file': "%s/%s" % (fdir, 'files/full_sudo6.xml'), 'os': 0}, 'fullscan': { 'file': "%s/%s" % (fdir, 'files/fullscan.xml'), 'os': 0}, - 'nv5': { 'file': "%s/%s" % (fdir, 'files/os_scan5.xml'), 'os': 0}} + 'nv5': { 'file': "%s/%s" % (fdir, 'files/os_scan5.xml'), 'os': 0} + } + self.fos_class_probabilities = "{0}/{1}".format(fdir, "files/test_osclass.xml") def test_fp(self): for file_e in self.flist_full: @@ -123,10 +125,22 @@ def test_cpeservice(self): s = h1.services[0] self.assertEqual(s.cpelist[0].cpestring, cpelist[0]) self.assertEqual(s.cpelist[1].cpestring, cpelist[1]) + + def test_os_class_probabilities(self): + p = NmapParser.parse_fromfile(self.fos_class_probabilities) + h = p.hosts.pop() + osc = h.os_class_probabilities().pop() + self.assertEqual(osc.type, "general purpose") + self.assertEqual(osc.vendor, "Linux") + self.assertEqual(osc.osfamily, "Linux") + self.assertEqual(osc.osgen, "3.X") + self.assertEqual(osc.accuracy, 100) + + #cpe:/o:linux:linux_kernel:3 if __name__ == '__main__': test_suite = ['test_fp', 'test_fpv6', 'test_osmatches_new', 'test_osclasses_new', - 'test_fpv5', 'test_osmatches_old', 'test_cpeservice'] + 'test_fpv5', 'test_osmatches_old', 'test_cpeservice', 'test_os_class_probabilities'] suite = unittest.TestSuite(map(TestNmapFP, test_suite)) test_result = unittest.TextTestRunner(verbosity=2).run(suite)