完成了DOH的仿真功能及流量筛选
This commit is contained in:
+38
@@ -0,0 +1,38 @@
|
||||
import os
|
||||
from dns import message
|
||||
import requests
|
||||
from requests.adapters import HTTPAdapter
|
||||
from urllib3.util.ssl_ import create_urllib3_context
|
||||
import certifi
|
||||
|
||||
# 设置 TLS 密钥日志路径(绝对路径)
|
||||
keylog_path = os.path.abspath('tls_keys.log')
|
||||
os.environ['SSLKEYLOGFILE'] = keylog_path
|
||||
|
||||
# 构造 DNS 查询
|
||||
q = message.make_query('example.com', 'A')
|
||||
wire_data = q.to_wire()
|
||||
|
||||
class KeyLoggerAdapter(HTTPAdapter):
|
||||
def init_poolmanager(self, *args, **kwargs):
|
||||
context = create_urllib3_context()
|
||||
context.keylog_filename = os.environ['SSLKEYLOGFILE']
|
||||
kwargs['ssl_context'] = context
|
||||
return super().init_poolmanager(*args, **kwargs)
|
||||
|
||||
# 发送请求
|
||||
session = requests.Session()
|
||||
session.mount('https://', KeyLoggerAdapter())
|
||||
|
||||
try:
|
||||
# 使用国内可用的 DoH 服务(如阿里云)
|
||||
response = session.post(
|
||||
'https://doh.pub/dns-query',
|
||||
data=wire_data,
|
||||
headers={'Content-Type': 'application/dns-message'},
|
||||
verify=certifi.where()
|
||||
)
|
||||
print("响应状态码:", response.status_code)
|
||||
print("密钥日志已写入:", keylog_path)
|
||||
except Exception as e:
|
||||
print("请求失败:", e)
|
||||
Reference in New Issue
Block a user