monkeyWie / proxyee

HTTP proxy server,support HTTPS&websocket.MITM impl,intercept and tamper HTTPS traffic.
MIT License
1.52k stars 567 forks source link

Proxee does not initercept anything #109

Closed Rich2020 closed 3 years ago

Rich2020 commented 3 years ago

I'm using the demo code in the README:

HttpProxyServerConfig config =  new HttpProxyServerConfig();
//enable HTTPS support
//If not enabled, HTTPS will not be intercepted, but forwarded directly to the raw packet.
config.setHandleSsl(true);
new HttpProxyServer()
    .serverConfig(config)
    .proxyInterceptInitializer(new HttpProxyInterceptInitializer() {
      @Override
      public void init(HttpProxyInterceptPipeline pipeline) {
        pipeline.addLast(new FullResponseIntercept() {

          @Override
          public boolean match(HttpRequest httpRequest, HttpResponse httpResponse, HttpProxyInterceptPipeline pipeline) {
            //Insert js when matching to Baidu homepage
            return HttpUtil.checkUrl(pipeline.getHttpRequest(), "^www.baidu.com$")
                && isHtml(httpRequest, httpResponse);
          }

          @Override
          public void handelResponse(HttpRequest httpRequest, FullHttpResponse httpResponse, HttpProxyInterceptPipeline pipeline) {
            //Print raw packet
            System.out.println(httpResponse.toString());
            System.out.println(httpResponse.content().toString(Charset.defaultCharset()));
            //Edit response header and response body
            httpResponse.headers().set("handel", "edit head");
            httpResponse.content().writeBytes("<script>alert('hello proxyee')</script>".getBytes());
          }
        });
      }
    })
    .start(9999);

I needed to modify handleResonse because the code sample does not call the super class:

super.handleResponse(httpRequest, httpResponse, pipeline);

On click of a button, I launch Proxee in a new thread (otherwise it locks the UI). I then click another button to make a request to http://www.baidu.com/. I do this using Volley and have also tried with the Apache library. I have also tried minimising my app and using the browser to navigate to the baidu homepage.

However, neither the match nor the handleResponse functions fire. There is no indication that Proxee is running or doing anything, but if I try to start Proxee again, I do get an exception java.net.BindException: Address already in use, so I know it is running.

What am I missing? Why is nothing intercepted?

monkeyWie commented 3 years ago

Did you set up a proxy when requesting the website, like this:

import org.apache.http.HttpHost;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.HttpClientBuilder;    
...
HttpHost proxy = new HttpHost("127.0.0.1", 9999, "http");
HttpClient httpClient = HttpClientBuilder.create().setProxy(proxy).build();

refer: https://stackoverflow.com/questions/4955644/apache-httpclient-4-1-proxy-settings