monkeyWie / proxyee

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

使用官方提供的demo无法成功实现demo效果,求助 #239

Closed iwakura-lain closed 1 year ago

iwakura-lain commented 1 year ago

依赖版本为 1.7.0, 系统证书已设置image

image
@Test
public void contextLoads() {
        HttpProxyServerConfig config = new HttpProxyServerConfig();
        config.setHandleSsl(true);

        new HttpProxyServer()
                .serverConfig(config)
                .proxyInterceptInitializer(new HttpProxyInterceptInitializer() {
                    @Override
                    public void init(HttpProxyInterceptPipeline pipeline) {
                        pipeline.addLast(new HttpProxyIntercept() {
                            @Override
                            public void beforeRequest(Channel clientChannel, HttpRequest httpRequest,
                                                      HttpProxyInterceptPipeline pipeline) throws Exception {
                                //匹配到百度首页跳转到淘宝
                                if (HttpUtil.checkUrl(pipeline.getHttpRequest(), "^www.baidu.com$")) {
                                    HttpResponse hookResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
                                    hookResponse.setStatus(HttpResponseStatus.FOUND);
                                    hookResponse.headers().set(HttpHeaderNames.LOCATION, "http://www.taobao.com");
                                    clientChannel.writeAndFlush(hookResponse);
                                    HttpContent lastContent = new DefaultLastHttpContent();
                                    clientChannel.writeAndFlush(lastContent);
                                    return;
                                }
                                pipeline.beforeRequest(clientChannel, httpRequest);
                            }
                        });
                    }
                })
                .httpProxyExceptionHandle(new HttpProxyExceptionHandle() {
                    @Override
                    public void beforeCatch(Channel clientChannel, Throwable cause) throws Exception {
                        cause.printStackTrace();
                    }

                    @Override
                    public void afterCatch(Channel clientChannel, Channel proxyChannel, Throwable cause)
                            throws Exception {
                        cause.printStackTrace();
                    }
                })
                .start(9999);
    }
monkeyWie commented 1 year ago

试试 curl -k -x 127.0.0.1:9999 https://www.baidu.com

iwakura-lain commented 1 year ago

试试 curl -k -x 127.0.0.1:9999 https://www.baidu.com 感谢回复,curl terminal 无日志,idea 打印了

17:40:32.669 [nioEventLoopGroup-3-1] DEBUG io.netty.handler.logging.LoggingHandler - [id: 0x457ca6cc, L:/0:0:0:0:0:0:0:0:9999] READ: [id: 0x46359987, L:/127.0.0.1:9999 - R:/127.0.0.1:62693]
17:40:32.670 [nioEventLoopGroup-3-1] DEBUG io.netty.handler.logging.LoggingHandler - [id: 0x457ca6cc, L:/0:0:0:0:0:0:0:0:9999] READ COMPLETE
17:40:32.980 [nioEventLoopGroup-4-2] DEBUG io.netty.handler.ssl.SslHandler - [id: 0x46359987, L:/127.0.0.1:9999 - R:/127.0.0.1:62693] HANDSHAKEN: protocol:TLSv1.2 cipher suite:TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
monkeyWie commented 1 year ago

我拿你代码跑了下没问题的啊 image

iwakura-lain commented 1 year ago

加上 -I 后重定向成功了

image

但是浏览器访问实际上还是没有跳转

iwakura-lain commented 1 year ago

控制台报错

18:15:42.650 [nioEventLoopGroup-4-1] DEBUG io.netty.handler.ssl.SslHandler - [id: 0x3ebee7db, L:/127.0.0.1:9999 - R:/127.0.0.1:63443] Swallowing a harmless 'connection reset by peer / broken pipe' error that occurred while writing close_notify in response to the peer's close_notify
java.io.IOException: Connection reset by peer
monkeyWie commented 1 year ago

加这一行代码再试试:

 hookResponse.headers().set(HttpHeaderNames.CONTENT_LENGTH, 0)
iwakura-lain commented 1 year ago

也不行

monkeyWie commented 1 year ago

我这边测试是可以的啊,浏览器和curl都没问题,你加完之后curl也不行吗? image

iwakura-lain commented 1 year ago

curl 没问题,重定向了;但是浏览器访问不行。。

image
iwakura-lain commented 1 year ago

charles 能正常代理

image
monkeyWie commented 1 year ago

浏览器看起来没走代理啊

iwakura-lain commented 1 year ago

需要额外设置浏览器的代理吗?我以为是系统级的,现在使用 SwitchOmega 以后报了 npe

image
monkeyWie commented 1 year ago

是必现的吗,如果能用curl重现出来那更好

iwakura-lain commented 1 year ago

感谢大佬,是插件的问题 在使用 SwitchOmega 的情况下,浏览器访问时必现,curl 重现不了

image

如果是手动设置系统代理的话,可以正常重定向

monkeyWie commented 1 year ago

不要用https的代理协议,代理服务器只提供http协议,这样配置就行 image

iwakura-lain commented 1 year ago

懂了,感谢大佬