mirror of
https://github.com/vee1e/mitmproxy.git
synced 2026-09-01 18:27:18 +00:00
add DNS-over-HTTPS contentview
This commit is contained in:
parent
d2136b66a0
commit
2667ed44f5
4 changed files with 45 additions and 0 deletions
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
* Add a raw hex stream contentview.
|
||||
([#6389](https://github.com/mitmproxy/mitmproxy/pull/6389), @mhils)
|
||||
* Add a contentview for DNS-over-HTTPS.
|
||||
([#6389](https://github.com/mitmproxy/mitmproxy/pull/6389), @mhils)
|
||||
|
||||
|
||||
## 27 September 2023: mitmproxy 10.1.1
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import traceback
|
|||
|
||||
from . import auto
|
||||
from . import css
|
||||
from . import dns
|
||||
from . import graphql
|
||||
from . import grpc
|
||||
from . import hex
|
||||
|
|
@ -238,6 +239,7 @@ add(msgpack.ViewMsgPack())
|
|||
add(grpc.ViewGrpcProtobuf())
|
||||
add(mqtt.ViewMQTT())
|
||||
add(http3.ViewHttp3())
|
||||
add(dns.ViewDns())
|
||||
|
||||
__all__ = [
|
||||
"View",
|
||||
|
|
|
|||
20
mitmproxy/contentviews/dns.py
Normal file
20
mitmproxy/contentviews/dns.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
from mitmproxy.contentviews import base
|
||||
from mitmproxy.contentviews.json import format_json
|
||||
from mitmproxy.dns import Message
|
||||
|
||||
|
||||
class ViewDns(base.View):
|
||||
name = "DNS-over-HTTPS"
|
||||
|
||||
def __call__(self, data, **metadata):
|
||||
try:
|
||||
message = Message.unpack(data)
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
return "DoH", format_json(message.to_json())
|
||||
|
||||
def render_priority(
|
||||
self, data: bytes, *, content_type: str | None = None, **metadata
|
||||
) -> float:
|
||||
return float(content_type == "application/dns-message")
|
||||
21
test/mitmproxy/contentviews/test_dns.py
Normal file
21
test/mitmproxy/contentviews/test_dns.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
from . import full_eval
|
||||
from mitmproxy.contentviews import dns
|
||||
|
||||
DNS_HTTPS_RECORD_RESPONSE = bytes.fromhex(
|
||||
"00008180000100010000000107746c732d656368036465760000410001c00c004100010000003c00520001000005004b0049fe0d00"
|
||||
"452b00200020015881d41a3e2ef8f2208185dc479245d20624ddd0918a8056f2e26af47e2628000800010001000100034012707562"
|
||||
"6c69632e746c732d6563682e646576000000002904d0000000000000"
|
||||
)
|
||||
|
||||
|
||||
def test_simple():
|
||||
v = full_eval(dns.ViewDns())
|
||||
assert v(DNS_HTTPS_RECORD_RESPONSE)
|
||||
assert not v(b"foobar")
|
||||
|
||||
|
||||
def test_render_priority():
|
||||
v = dns.ViewDns()
|
||||
assert v.render_priority(b"", content_type="application/dns-message")
|
||||
assert not v.render_priority(b"", content_type="text/plain")
|
||||
assert not v.render_priority(b"")
|
||||
Loading…
Add table
Add a link
Reference in a new issue