forked from mitmproxy/mitmproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add blockech addon * Update CHANGELOG.md * [autofix.ci] apply automated fixes * Add tests * [autofix.ci] apply automated fixes * Fix tests * Add suggested changes * [autofix.ci] apply automated fixes * rephrase changelog to be more user-centric --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Maximilian Hils <[email protected]>
- Loading branch information
1 parent
8cf0cca
commit de871df
Showing
5 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from mitmproxy import ctx | ||
from mitmproxy import dns | ||
from mitmproxy.net.dns import types | ||
|
||
|
||
class BlockECH: | ||
def load(self, loader): | ||
loader.add_option( | ||
"block_ech", | ||
bool, | ||
True, | ||
"Strip DNS HTTPS records to prevent clients from sending Encrypted ClientHello (ECH) messages", | ||
) | ||
|
||
def dns_response(self, flow: dns.DNSFlow): | ||
# TODO: parse HTTPS records and remove ech value alone. For now, | ||
# if HTTPS record is part of response, remove that record. | ||
assert flow.response | ||
if ctx.options.block_ech: | ||
flow.response.answers = [ | ||
answer for answer in flow.response.answers if answer.type != types.HTTPS | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from mitmproxy import dns | ||
from mitmproxy.addons import block_ech | ||
from mitmproxy.net.dns import types | ||
from mitmproxy.test import taddons | ||
from mitmproxy.test import tflow | ||
from mitmproxy.test import tutils | ||
|
||
|
||
class TestBlockECH: | ||
def test_simple(self): | ||
be = block_ech.BlockECH() | ||
with taddons.context(be) as tctx: | ||
answers = [ | ||
dns.ResourceRecord( | ||
"dns.google", | ||
dns.types.HTTPS, | ||
dns.classes.IN, | ||
32, | ||
b"\x08\x08\x08\x08", | ||
), | ||
dns.ResourceRecord( | ||
"dns.google", dns.types.A, dns.classes.IN, 32, b"\x08\x08\x04\x04" | ||
), | ||
] | ||
resp = tutils.tdnsresp(answers=answers) | ||
f = tflow.tdnsflow(resp=resp) | ||
|
||
tctx.configure(be, block_ech=False) | ||
be.dns_response(f) | ||
assert len(f.response.answers) == 2 | ||
|
||
tctx.configure(be, block_ech=True) | ||
be.dns_response(f) | ||
assert not any(answer.type == types.HTTPS for answer in f.response.answers) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters