File: fingerprints.py

package info (click to toggle)
wig 0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,028 kB
  • sloc: python: 1,520; sh: 37; makefile: 5
file content (124 lines) | stat: -rw-r--r-- 3,556 bytes parent folder | download | duplicates (4)
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
import json
import copy
import os
import os.path


class Fingerprints(object):

	def __init__(self, data_dir='data'):
		# get the absolute location of this file
		datadir = os.path.dirname(os.path.abspath(__file__))

		# remove the 'classes' dir and add the 'data_dir'
		datadir = os.path.join(datadir.rsplit('/', maxsplit=1)[0], data_dir)

		self.data = {
			'cms': {
				'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': datadir + '/js/md5/',			'fps': []},
				'reqex':		{'dir': datadir + '/js/regex/',			'fps': []},
			},
			'platform': {
				'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':  datadir + '/vulnerabilities/cvedetails/', '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
		self._load_subdomains()
		self._load_dictionary()
		self._load_interesting()
		self._load_error()
		self._load_os()
		self._load()


	def _is_json(self, filename):
		is_json = False
		if len(filename.split('.')) == 2:
			name,ext = filename.split('.')
			is_json = ext == 'json'

		return is_json


	def _get_name(self, filename):
		name,ext = filename.split('.')
		return self.data['translator']['dictionary'][name]['name']


	def _open_file(self, filename):

		if not self._is_json(filename): return None

		try:
			with open(filename) as fh:
				fps = json.load(fh)
		except Exception as e:
			print('Error loading file: %s' % (filename))
			return None

		return fps


	def _load_subdomains(self):
		self.data['subdomains']['fps'] = self._open_file(self.data['subdomains']['file'])


	def _load_dictionary(self):
		fps = self._open_file(self.data['translator']['file'])
		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:
			self.data['error_pages']['fps'] = fps


	def _load_os(self):
		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:
				self.data['os']['fps'].extend(fps)


	def _load_interesting(self):
		fps = self._open_file(self.data['interesting']['file'])

		for fp in fps:
			if 'ext' in fp:
				for ext in fp['ext']:
					fp_copy = copy.deepcopy(fp)
					fp_copy['url'] += '.' + ext
					self.data['interesting']['fps'].append(fp_copy)
			else:
				self.data['interesting']['fps'].append(fp)


	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']):
					fps = self._open_file(self.data[category][fp_type]['dir'] + '/' + json_file)
					for fp in fps:
						fp['name'] = self._get_name( json_file )
						self.data[category][fp_type]['fps'].append( fp )