Giter VIP home page Giter VIP logo

proxyee's Introduction

HTTP代理服务器

支持HTTP、HTTPS、WebSocket,HTTPS采用动态签发SSL证书,可以拦截http、https的报文并进行处理。
例如:http(s)协议抓包,http(s)动态替换请求内容或响应内容等等。

HTTPS支持

需要导入项目中的CA证书(src/resources/ca.crt)至受信任的根证书颁发机构。
可以使用CertDownIntercept拦截器,开启网页下载证书功能,访问http://serverIP:serverPort即可进入。
注:安卓手机上安装证书若弹出键入凭据存储的密码,输入锁屏密码即可。

二级代理

可设置二级代理服务器,支持http,socks4,socks5。

启动

//new HttpProxyServer().start(9999);

new HttpProxyServer()
//        .proxyConfig(new ProxyConfig(ProxyType.SOCKS5, "127.0.0.1", 1085))  //使用socks5二级代理
    .proxyInterceptInitializer(new HttpProxyInterceptInitializer() {
      @Override
      public void init(HttpProxyInterceptPipeline pipeline) {
        pipeline.addLast(new CertDownIntercept());  //处理证书下载
        pipeline.addLast(new HttpProxyIntercept() {
          @Override
          public void beforeRequest(Channel clientChannel, HttpRequest httpRequest,
              HttpProxyInterceptPipeline pipeline) throws Exception {
            //替换UA,伪装成手机浏览器
            /*httpRequest.headers().set(HttpHeaderNames.USER_AGENT,
                "Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1");*/
            //转到下一个拦截器处理
            pipeline.beforeRequest(clientChannel, httpRequest);
          }

          @Override
          public void afterResponse(Channel clientChannel, Channel proxyChannel,
              HttpResponse httpResponse, HttpProxyInterceptPipeline pipeline) throws Exception {

            //拦截响应,添加一个响应头
            httpResponse.headers().add("intercept", "test");
            //转到下一个拦截器处理
            pipeline.afterResponse(clientChannel, proxyChannel, httpResponse);
          }
        });
      }
    })
    .httpProxyExceptionHandle(new HttpProxyExceptionHandle() {
      @Override
      public void beforeCatch(Channel clientChannel, Throwable cause) throws Exception {
        System.out.println("111111111111111");
        cause.printStackTrace();
      }

      @Override
      public void afterCatch(Channel clientChannel, Channel proxyChannel, Throwable cause) throws Exception {
        System.out.println("22222222222222");
        cause.printStackTrace();
      }
    })
    .start(9999);
    
    //使用FullResponseIntercept修改响应体
    new HttpProxyServer()
      .proxyInterceptInitializer(new HttpProxyInterceptInitializer() {
        @Override
        public void init(HttpProxyInterceptPipeline pipeline) {
          pipeline.addLast(new FullResponseIntercept() {
  
            @Override
            public boolean match(HttpRequest httpRequest, HttpResponse httpResponse, HttpProxyInterceptPipeline pipeline) {
              return true;
            }
  
            @Override
            public void handelResponse(HttpRequest httpRequest, FullHttpResponse httpResponse, HttpProxyInterceptPipeline pipeline) {
              //打印原始响应信息
              System.out.println(httpResponse.toString());
              System.out.println(httpResponse.content().toString(Charset.defaultCharset()));
              //修改响应头和响应体
              int index = ByteUtil.findText(httpResponse.content(), "<head>");
              ByteUtil.insertText(httpResponse.content(), index, "<script>alert(1)</script>");
              httpResponse.headers().set("handel", "edit head");
              if (httpResponse.headers().contains(HttpHeaderNames.CONTENT_LENGTH)) {
                httpResponse.headers().set(HttpHeaderNames.CONTENT_LENGTH, httpResponse.content().readableBytes());
              }
            }
          });
        }
      })
      .start(9999);

流程

SSL握手

SSL握手

HTTP通讯

HTTP通讯

proxyee's People

Contributors

monkeywie avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.