1

I am running mitmproxy with below command:

mitmproxy -v --listen-host 127.0.0.1 --ssl-insecure --set console_eventlog_verbosity:debug

and executing a curl command to proceed with intercept as below:

env https_proxy=http://localhost:8080 curl --proxy-insecure -v https://www.samplereplace.com/some_name

The issue for me over here is when I try doing it for sites like www.google.com, www.facebook.com, etc. I am able to intercept it. But when I try for sites that does not exist like the one in the code, it returns the following for curl directly

* Uses proxy env variable https_proxy == 'http://localhost:8080'
*   Trying 127.0.0.1:8080...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
* allocate connect buffer!
* Establish HTTP proxy tunnel to www.samplereplace.com:443
> CONNECT www.samplereplace.com:443 HTTP/1.1
> Host: www.samplereplace.com:443
> User-Agent: curl/7.68.0
> Proxy-Connection: Keep-Alive
> 
< HTTP/1.1 200 Connection established
< 
* Proxy replied 200 to CONNECT request
* CONNECT phase completed!
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/certs/ca-certificates.crt
  CApath: /etc/ssl/certs
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* CONNECT phase completed!
* CONNECT phase completed!
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: CN=www.samplereplace.com
*  start date: Jul 12 07:43:01 2020 GMT
*  expire date: Jul 14 07:43:01 2021 GMT
*  subjectAltName: host "www.samplereplace.com" matched cert's "www.samplereplace.com"
*  issuer: CN=mitmproxy; O=mitmproxy
*  SSL certificate verify ok.
> GET /ameet HTTP/1.1
> Host: www.samplereplace.com
> User-Agent: curl/7.68.0
> Accept: */*
> 
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* old SSL session ID is stale, removing
* Mark bundle as not supporting multiuse
< HTTP/1.1 502 Bad Gateway
< Server: mitmproxy 5.1.1
< Connection: close
< Content-Length: 398
< Content-Type: text/html
< 
<html>
            <head>
                <title>502 Bad Gateway</title>
            </head>
            <body>
            <h1>502 Bad Gateway</h1>
            <p>ProtocolException(&#x27;Server connection to (\&#x27;www.samplereplace.com\&#x27;, 443) failed: Error connecting to &quot;www.samplereplace.com&quot;: [Errno -2] Name or service not known&#x27;)</p>
            </body>

and in case of events log in mitmproxy, what is shown is as below:

info: 127.0.0.1:35768: clientconnect
warn: 127.0.0.1:35820: Cannot connect to server, no server address given.
info: 127.0.0.1:35768: clientdisconnect

NOTE: If I am executing a curl command to proceed with intercept as below:

env http_proxy=http://localhost:8080 curl --proxy-insecure -v http://www.samplereplace.com/some_name

I am able to intercept it.

  • I don't see the problem here. If you request a web site that does not exist the proxy returns an HTTP 502 that is nothing unusual. If you want to redirect the request to an existing page you need to start mitmproxy with a script that rewrites the server as shown [here](https://stackoverflow.com/a/38592917/150978). – Robert Jul 15 '20 at 07:46
  • what I am trying to achieve is in case an interception is active for the website in mitmproxy it should show up in the flows section and allow me to map some response for the same (map local). However, the request does not show up in the flows section. – Ameet Pradhan Jul 15 '20 at 09:19
  • I don't think the use case that the remote server does not exist plus setting a response in the UI is covered by mitmproxy. If the addressed server does not exists you should [send a static response by mitmproxy](https://docs.mitmproxy.org/stable/addons-examples/#example-simplesend_reply_from_proxypy) and then modify that response. – Robert Jul 15 '20 at 10:42

0 Answers0