Skip to content

dns_use_hosts_file=false, mode=reverse #7266

@drzraf

Description

@drzraf

Problem Description

dns_use_hosts_file has no effect with --mode reverse

Steps to reproduce the behavior:

  1. $ echo  127.0.0.1 example.com >> /etc/hosts
  2. $ strace -fff -e trace=openat mitmweb -p 443 --no-web-open-browser --mode reverse:https://example.com --showhost --set dns_use_hosts_file=false --set dns_name_servers=8.8.8.8 2>&1|grep etc/hosts ¹
  3. $ curl -k --resolve example.com:443:127.0.0.1 https://example.com

Actual result:

  • mitmweb opens /etc/hosts and an infinite loop occurs since mitmweb resolves example.com to 127.0.0.1 based on /etc/hosts which is not desired. /etc/hosts was modified in order to alter an client's application resolution behavior which (unlike curl's example) can't be modified/poisoned otherwise.

Expected result:

  • mitmweb must consider dns_name_servers to resolve example.com and ignore /etc/hosts as requested and returns example.com's body

¹ sudo sysctl net.ipv4.ip_unprivileged_port_start=80

System Information

Mitmproxy: 11.0.0
Python:    3.12.3
OpenSSL:   OpenSSL 3.2.2 4 Jun 2024
Platform:  Linux-6.8.0-47-generic-x86_64-with-glibc2.39

References

See also #3139

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions