import requests
import hashlib
import json
import re
class WebFingerprinter:
def __init__(self, fingerprint_db):
self.fingerprint_db = fingerprint_db
def get_response(self, url):
try:
response = requests.get(url, timeout=10, headers={'User-Agent': 'Mozilla/5.0'})
return response
except requests.exceptions.RequestException as e:
print(f"Request error: {e}")
return None
def match_fingerprints(self, response):
results = []
for fp in self.fingerprint_db:
if fp['match_type'] == 'header':
header_value = response.headers.get(fp['match_location'], '')
if fp['match_rule'] in header_value:
results.append(fp['name'])
elif fp['match_type'] == 'body':
if re.search(fp['match_rule'], response.text):
results.append(fp['name'])
elif fp['match_type'] == 'file':
file_url = response.url.rstrip('/') + fp['match_location']
file_content = requests.get(file_url, timeout=10).content
file_md5 = hashlib.md5(file_content).hexdigest()
if file_md5 == fp['match_rule']:
results.append(fp['name'])
return results
def fingerprint(self, url):
response = self.get_response(url)
if response is None:
return []
return self.match_fingerprints(response)
if __name__ == "__main__":
# 指纹数据库
fingerprint_db = [
{
"name": "用友-NC-Cloud",
"category": "nc",
"match_type": "header",
"match_location": "Server",
"match_rule": "NC-Cloud"
},
{
"name": "GitLab",
"category": "devops",
"match_type": "body",
"match_location": "<title>",
"match_rule": "GitLab"
},
{
"name": "爱快流控路由",
"category": "network",
"match_type": "file",
"match_location": "/favicon.ico",
"match_rule": "md5:123456789abcdef"
}
]
# 资产列表
assets = [
"http://nc-cloud.com",
"http://gitlab.com",
"http://ai-quick.com"
]
# 指纹识别
fingerprinter = WebFingerprinter(fingerprint_db)
for asset in assets:
results = fingerprinter.fingerprint(asset)
print(f"{asset} - Detected technologies: {results}")
这段代码报错了,报错如下,该如何修改C:\Users\Tong\AppData\Local\Programs\Python\Python312\python.exe C:\Users\Tong\Desktop\python项目\web指纹.py
Request error: HTTPConnectionPool(host='nc-cloud.com', port=80): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0x000001DC6E2D2B10>, 'Connection to nc-cloud.com timed out. (connect timeout=10)'))
http://nc-cloud.com - Detected technologies: []
Request error: HTTPConnectionPool(host='gitlab.com', port=80): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000001DC6E2D32C0>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。'))
http://gitlab.com - Detected technologies: []
Request error: HTTPSConnectionPool(host='www.starbrocoin.com', port=443): Max retries exceeded with url: / (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x000001DC6E300380>, 'Connection to www.starbrocoin.com timed out. (connect timeout=10)'))
http://ai-quick.com - Detected technologies: []
进程已结束,退出代码为 0