-
Notifications
You must be signed in to change notification settings - Fork 5
/
fingerprint.py
87 lines (78 loc) · 3.21 KB
/
fingerprint.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
#!/usr/bin/python
# __author__ = 'jasonsheh'
# -*- coding:utf-8 -*-
import sqlite3
import re
import requests
class FingerPrint:
def __init__(self, url, protocol):
self.conn = sqlite3.connect('Rules.db')
self.cursor = self.conn.cursor()
self.target = url
self.protocol = protocol
self.headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0'}
self.result = {}
sql = 'select * from application'
self.cursor.execute(sql)
self.rules = self.cursor.fetchall()
def init(self):
if self.target.startswith('http://'):
self.target = self.target[7:]
elif self.target.startswith('https://'):
self.target = self.target[8:]
self.target = self.target.strip('/')
def scan(self):
finger_print = ''
self.init()
try:
r = requests.get(self.protocol+self.target, timeout=2, headers=self.headers)
for item in self.rules:
appname = item[1]
rules = item[2].split(', ')
# print(app, rule)
for rule in rules:
rule = rule.split(':', 1)
place = rule[0]
_rule = rule[1]
if place in ['body']:
if -1 != r.text.find(_rule):
finger_print += appname+' '
break
elif place in ['title']:
if re.search('<title>.*?'+re.escape(_rule)+'.*?</title>', r.text):
finger_print += appname+' '
break
elif place in ['header', 'server']:
header = ''
for key, value in r.headers.items():
header += key + ': ' + value + ' '
if re.search(re.escape(_rule), header, re.I):
finger_print += appname+' '
break
'''
elif place in ['fullheader', 'fullbody']:
if -1 != r.text.find(_rule):
finger_print += appname+' '
break
header = ''
for key, value in r.headers.items():
header += key + ': ' + value + ' '
if re.search(re.escape(_rule), header, re.I):
finger_print += appname+' '
break
'''
self.result[self.target] = finger_print
except requests.exceptions.ConnectionError:
self.result[self.target] = ''
except requests.exceptions.ReadTimeout:
self.result[self.target] = ''
except requests.exceptions.TooManyRedirects:
self.result[self.target] = ''
def run(self):
self.scan()
# Database().insert_finger(self.target, self.result[self.target])
return self.result[self.target]
if __name__ == '__main__':
url = input('请输入待识别域名: ')
result = FingerPrint(url=url, protocol='http://').run()
print(result)