File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2020 ([ #7933 ] ( https://github.com/mitmproxy/mitmproxy/pull/7933 ) , @caiquejjx , @mhils )
2121- Fix various issues in infer_content_encoding
2222 ([ #7928 ] ( https://github.com/mitmproxy/mitmproxy/pull/7928 ) , @xu-cheng )
23+ - Add example addon to spoof DNS responses.
24+ ([ #7973 ] ( https://github.com/mitmproxy/mitmproxy/pull/7973 ) , @mhils )
2325- Gracefully handle decoding of raw binary payloads that previously caused
2426 "Raw cannot decode" or "failed to parse as JSON" errors
2527 ([ #7940 ] ( https://github.com/mitmproxy/mitmproxy/pull/7940 ) , @AdityaPatadiya )
Original file line number Diff line number Diff line change 1+ """
2+ Spoof DNS responses.
3+
4+ In this example, we fiddle with IPv6 (AAAA) records:
5+ - For example.com, `::1` is returned.
6+ (domain is hosted on localhost)
7+ - For example.org, an NXDOMAIN error is returned.
8+ (domain does not exist)
9+ - For all other domains, return a non-error response without any records.
10+ (domain exists, but has no IPv6 configured)
11+ """
12+
13+ import ipaddress
14+ import logging
15+
16+ from mitmproxy import dns
17+
18+
19+ def dns_request (flow : dns .DNSFlow ) -> None :
20+ q = flow .request .question
21+ if q and q .type == dns .types .AAAA :
22+ logging .info (f"Spoofing IPv6 records for { q .name } ..." )
23+ if q .name == "example.com" :
24+ flow .response = flow .request .succeed (
25+ [
26+ dns .ResourceRecord (
27+ name = "example.com" ,
28+ type = dns .types .AAAA ,
29+ class_ = dns .classes .IN ,
30+ ttl = dns .ResourceRecord .DEFAULT_TTL ,
31+ data = ipaddress .ip_address ("::1" ).packed ,
32+ )
33+ ]
34+ )
35+ elif q .name == "example.org" :
36+ flow .response = flow .request .fail (dns .response_codes .NXDOMAIN )
37+ else :
38+ flow .response = flow .request .succeed ([])
You can’t perform that action at this time.
0 commit comments