From e9754a511c43ccfde4ed3bfe9e609ea941cd8612 Mon Sep 17 00:00:00 2001 From: Fabian Martinez Portantier Date: Wed, 30 Mar 2016 18:48:20 +0000 Subject: [PATCH] module load now works from any place --- classes/fingerprints.py | 56 +++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/classes/fingerprints.py b/classes/fingerprints.py index 61352fa..76748de 100644 --- a/classes/fingerprints.py +++ b/classes/fingerprints.py @@ -2,36 +2,41 @@ import os import copy +import os.path + +datadir = os.path.dirname(os.path.abspath(__file__)) +datadir = datadir.rsplit('/', maxsplit=1)[0] +datadir += '/data' class Fingerprints(object): def __init__(self): - + self.data = { 'cms': { - 'md5': {'dir': 'data/cms/md5/', 'fps': []}, - 'reqex': {'dir': 'data/cms/regex/', 'fps': []}, - 'string': {'dir': 'data/cms/string/', 'fps': []}, - 'header': {'dir': 'data/cms/header/', 'fps': []} + 'md5': {'dir': datadir + '/cms/md5/', 'fps': []}, + 'reqex': {'dir': datadir + '/cms/regex/', 'fps': []}, + 'string': {'dir': datadir + '/cms/string/', 'fps': []}, + 'header': {'dir': datadir + '/cms/header/', 'fps': []} }, 'js': { - 'md5': {'dir': 'data/js/md5/', 'fps': []}, - 'reqex': {'dir': 'data/js/regex/', 'fps': []}, + 'md5': {'dir': datadir + '/js/md5/', 'fps': []}, + 'reqex': {'dir': datadir + '/js/regex/', 'fps': []}, }, 'platform': { - 'md5': {'dir': 'data/platform/md5/', 'fps': []}, - 'reqex': {'dir': 'data/platform/regex/', 'fps': []}, - 'string': {'dir': 'data/platform/string/', 'fps': []}, - 'header': {'dir': 'data/platform/header/', 'fps': []} + 'md5': {'dir': datadir + '/platform/md5/', 'fps': []}, + 'reqex': {'dir': datadir + '/platform/regex/', 'fps': []}, + 'string': {'dir': datadir + '/platform/string/', 'fps': []}, + 'header': {'dir': datadir + '/platform/header/', 'fps': []} }, 'vulnerabilities': { - 'cvedetails': {'dir': 'data/vulnerabilities/cvedetails/', 'fps': []}, + 'cvedetails': {'dir': datadir + '/vulnerabilities/cvedetails/', 'fps': []}, }, - 'translator': {'file': 'data/dictionary.json', 'dictionary': {}}, - 'error_pages': {'file': 'data/error_pages.json', 'fps': []}, - 'interesting': {'file': 'data/interesting.json', 'fps': []}, - 'subdomains': {'file': 'data/subdomains.json', 'fps': []}, - 'os': {'dir': 'data/os/', 'fps': []} + 'translator': {'file': datadir + '/dictionary.json', 'dictionary': {}}, + 'error_pages': {'file': datadir + '/error_pages.json', 'fps': []}, + 'interesting': {'file': datadir + '/interesting.json', 'fps': []}, + 'subdomains': {'file': datadir + '/subdomains.json', 'fps': []}, + 'os': {'dir': datadir + '/os/', 'fps': []} } # load fingerprints @@ -46,7 +51,7 @@ def __init__(self): def _is_json(self, filename): is_json = False if len(filename.split('.')) == 2: - name,ext = filename.split('.') + name,ext = filename.split('.') is_json = ext == 'json' return is_json @@ -58,8 +63,9 @@ def _get_name(self, filename): def _open_file(self, filename): + if not self._is_json(filename): return None - + try: with open(filename) as fh: fps = json.load(fh) @@ -68,7 +74,7 @@ def _open_file(self, filename): return None return fps - + def _load_subdomains(self): self.data['subdomains']['fps'] = self._open_file(self.data['subdomains']['file']) @@ -76,20 +82,20 @@ def _load_subdomains(self): def _load_dictionary(self): fps = self._open_file(self.data['translator']['file']) - if fps is not None: + if fps is not None: self.data['translator']['dictionary'] = fps def _load_error(self): fps = self._open_file(self.data['error_pages']['file']) - if fps is not None: + if fps is not None: self.data['error_pages']['fps'] = fps def _load_os(self): - for json_file in os.listdir(self.data['os']['dir']): + for json_file in os.listdir(self.data['os']['dir']): fps = self._open_file(self.data['os']['dir'] + '/' + json_file) - if fps is not None: + if fps is not None: self.data['os']['fps'].extend(fps) @@ -110,7 +116,7 @@ def _load(self): categories = ['cms', 'js', 'platform', 'vulnerabilities'] for category in categories: for fp_type in self.data[category]: - for json_file in os.listdir(self.data[category][fp_type]['dir']): + for json_file in os.listdir(self.data[category][fp_type]['dir']): fps = self._open_file(self.data[category][fp_type]['dir'] + '/' + json_file) for fp in fps: fp['name'] = self._get_name( json_file )