Volver al ranking

monkeyWie/proxyee

Java

HTTP proxy server,support HTTPS&websocket.MITM impl,intercept and tamper HTTPS traffic.

httphttpsjavamitmmitmproxynettyproxyproxy-server
Crecimiento de estrellas
Estrellas
1.6k
Forks
577
Crecimiento semanal
Issues
110
5001k1.5k
sept 2017ago 2020ago 2023jul 2026
ArtefactosMavengit clone https://github.com/monkeyWie/proxyee.git
README

Proxyee

maven license

English | 中文


Introduction

Proxyee is a JAVA written HTTP proxy server library that supports HTTP, HTTPS, Websocket protocols, and supports MITM (Man-in-the-middle), which can capture and tamper with HTTP, HTTPS packet.

Usage

<dependency>
    <groupId>com.github.monkeywie</groupId>
    <artifactId>proxyee</artifactId>
    <version>1.7.7</version>
</dependency>

Demo

  • Normal HTTP proxy
new HttpProxyServer().start(9999);
  • MITM HTTP proxy

The following is a demonstration of a MITM attack that modifies the response header and response body when visiting the Baidu homepage, as shown in the figure below:

20200724152245

Code:

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 handleResponse(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);

Note: When https support is enabled, you need to install the CA certificate (src/resources/ca.crt) to a trusted root certificate authority.

More demo code can be found in the test package.

HTTPS support

The CA certificate (src/resources/ca.crt) from the project needs to be imported to a trusted root certificate authority. You can use the CertDownIntercept interceptor to enable the web certificate download feature, visit http://serverIP:serverPort to access.

Note 1: If the certificate installation on Android phones pops up the password stored in your credentials, just enter the lock screen password.

Note 2: Android 7 and above, the system no longer trusts user-installed certificates, you need to root and use the cat ca.crt > $(openssl x509 -inform PEM -subject_hash_old -in ca.crt | head -1).0 command generates the d1488b25.0 file, and then moves the file to the /system/etc/security/cacerts/ And give 644 access.

Note 3: In Android 7 and above, even if you add the certificate to the system certificate, this certificate does not work in chrome. The reason is that chrome will only trust certificates with validity less than 27 months from 2018 (https://www.entrustdatacard.com/blog/2018/february/chrome-requires-ct-after-april-2018). So you need to generate the certificate file yourself.

Custom CA

Since the root certificate and private key attached to the project are public, they are only suitable for local development and debugging, please generate your own root certificate and private key when using in the official environment, otherwise there will be risks.

  • running the main method of thecom.github.monkeywie.proxyee.crt.CertUtil class

  • use openssl

openssl genrsa -out ca.key 2048
openssl pkcs8 -topk8 -nocrypt -inform PEM -outform DER -in ca.key -out ca_private.der
openssl req -sha256 -new -x509 -days 365 -key ca.key -out ca.crt \
    -subj "/C=CN/ST=GD/L=SZ/O=lee/OU=study/CN=testRoot"

Copy ca.crt and ca_private.der to the project src/resources/ after generation, or implement the HttpProxyCACertFactory interface to custom load the root certificate and private key.

Rules for MITM

If you only want to perform MITM attacks on certain domains, you can use the HttpProxyServerConfig.setMitmMatcher method to set the matching rule, for example:

HttpProxyServerConfig config = new HttpProxyServerConfig();
config.setHandleSsl(true);
// only MITM on www.baidu.com
config.setMitmMatcher(new DomainHttpProxyMitmMatcher(Arrays.asList("www.baidu.com")));

Now the built-in DomainHttpProxyMitmMatcher is an exact match for the request domain. If you have other requirements, you can implement the HttpProxyMitmMatcher interface to customize the matching rules.

Authentication

Currently only basic authentication are supported.

  • Basic
// curl -i -x 127.0.0.1:9999 -U admin:123456 http://www.baidu.com
HttpProxyServerConfig config = new HttpProxyServerConfig();
        config.setAuthenticationProvider(new BasicHttpProxyAuthenticationProvider() {
            @Override
            protected BasicHttpToken authenticate(String usr, String pwd) {
                if ("admin".equals(usr) && "123456".equals(pwd)) {
                    return new BasicHttpToken(usr, pwd);
                }
                return null;
            }
        });
new HttpProxyServer()
        .serverConfig(config)
        .start(9999);
  • Custom

Customize authentication by implementing the HttpProxyAuthenticationProvider interface.

Authentication context

After the authorization, the token returned from the verification pass can be obtained in the pipeline.

HttpToken token = HttpAuthContext.getToken(clientChannel);

Pre-proxy support

Pre-proxy can be set,support http,socks4,socks5 protocol.

new HttpProxyServer()
    .proxyConfig(new ProxyConfig(ProxyType.SOCKS5, "127.0.0.1", 1085))
    .start(9999);

If you like this project, please consider donating to support the development of this project, thank you!

Flow

SSL handshake SSL握手

HTTP communication

HTTP通讯

How it works

Thanks

intellij-idea

Repositorios relacionados
hoppscotch/hoppscotch

Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia

TypeScriptnpmMIT Licenseapiapi-client
hoppscotch.io
79.8k6k
caddyserver/caddy

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

GoGo ModulesApache License 2.0goweb-server
caddyserver.com
74.2k4.8k
ngosang/trackerslist

Updated list of public BitTorrent trackers

GNU General Public License v2.0trackersbittorrent-trackers
ngosang.github.io/trackerslist/
54.6k6.6k
psf/requests

A simple, yet elegant, HTTP library.

PythonPyPIApache License 2.0pythonhttp
requests.readthedocs.io/en/latest/
54.1k10k
mitmproxy/mitmproxy

An interactive TLS-capable intercepting HTTP proxy for penetration testers and software developers.

PythonPyPIMIT Licensepythonsecurity
mitmproxy.org
44.4k4.6k
MHSanaei/3x-ui

Xray panel supporting multi-protocol multi-user expire day & traffic & IP limit (Vmess, Vless, Trojan, ShadowSocks, Wireguard, Hysteria, Tunnel, Mixed, HTTP, Tun, MTProto)

GoGo ModulesGNU General Public License v3.0trojanvless
docs.sanaei.dev
43.4k8.3k
curl/curl

A command line tool and library for transferring data with URL syntax, supporting DICT, FILE, FTP, FTPS, GOPHER, GOPHERS, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, MQTT, MQTTS, POP3, POP3S, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, TELNET, TFTP, WS and WSS. libcurl offers a myriad of powerful features

COtherhttphttps
curl.se
42.4k7.3k
apache/dubbo

The java implementation of Apache Dubbo. An RPC and microservice framework.

JavaMavenApache License 2.0dubbodistributed-systems
dubbo.apache.org
41.5k26.4k
aria2/aria2

aria2 is a lightweight multi-protocol & multi-source, cross platform download utility operated in command-line. It supports HTTP/HTTPS, FTP, SFTP, BitTorrent and Metalink.

C++GNU General Public License v2.0cpp11http
aria2.github.io
41.5k3.9k
httpie/cli

🥧 HTTPie CLI — modern, user-friendly command-line HTTP client for the API era. JSON support, colors, sessions, downloads, plugins & more.

PythonPyPIBSD 3-Clause "New" or "Revised" Licensehttpcli
httpie.io
38.3k4k
ehang-io/nps

一款轻量级、高性能、功能强大的内网穿透代理服务器。支持tcp、udp、socks5、http等几乎所有流量转发,可用来访问内网网站、本地支付接口调试、ssh访问、远程桌面,内网dns解析、内网socks5代理等等……,并带有功能强大的web管理端。a lightweight, high-performance, powerful intranet penetration proxy server, with a powerful web management terminal.

GoGo ModulesGNU General Public License v3.0sockstcp
ehang.io/nps/documents
34.1k6.1k
nginx/nginx

The official NGINX Open Source repository.

CBSD 2-Clause "Simplified" Licensecontent-cacheload-balancer
nginx.org
31.2k8.1k