I have an addon which intercepts requests to a given server and replaces their content entirely. The script is a little more complex than this, but that’s the gist of it.
Example:
def request(self, flow):
if self._domain_matches(flow.request.url):
flow.response = http.HTTPResponse.make(200, “Some content that will show up in the browser”)
This works fine, as long as the server being connected to can be reached. However, if we use, for example “www.notarealdomain.test”, my request method is never activated and I get a 502 in my browser (“ProtocolException(‘Server connection to (‘www.notarealdomain.test’, 443) failed: Error connecting to “www.notarealdomain.test”: [Errno -2] Name or service not known’,)”). I’ve been experimenting with the serverconnect addon point, but can’t figure out how to spoof a happy connection. I can re-write the conn.address to something else, but this generally fails SNI checks for HTTPS connections.