Proxyee 开源项目教程
1、项目介绍
Proxyee 是一个用 Java 编写的 HTTP 代理服务器库,支持 HTTP、HTTPS 和 Websocket 协议,并且支持 MITM(中间人攻击),可以拦截和篡改 HTTP 和 HTTPS 流量。该项目的主要目的是提供一个灵活且强大的代理服务器解决方案,适用于开发、测试和安全研究等多种场景。
2、项目快速启动
环境准备
Java 8 或更高版本Maven 构建工具
快速启动步骤
克隆项目
git clone https://github.com/monkeyWie/proxyee.git
cd proxyee
构建项目
mvn clean install
运行示例代码
以下是一个简单的 HTTP 代理服务器示例代码:
import com.github.monkeywie.proxyee.server.HttpProxyServer;
public class SimpleProxyServer {
public static void main(String[] args) {
new HttpProxyServer().start(9999);
}
}
启动代理服务器
将上述代码保存为 SimpleProxyServer.java,然后运行:
javac SimpleProxyServer.java
java SimpleProxyServer
此时,代理服务器将在本地的 9999 端口启动。
3、应用案例和最佳实践
应用案例
1. 拦截和篡改 HTTPS 流量
以下是一个 MITM 攻击的示例,修改访问百度首页时的响应头和响应体:
import com.github.monkeywie.proxyee.intercept.HttpProxyInterceptInitializer;
import com.github.monkeywie.proxyee.intercept.HttpProxyInterceptPipeline;
import com.github.monkeywie.proxyee.intercept.common.FullResponseIntercept;
import com.github.monkeywie.proxyee.server.HttpProxyServer;
import com.github.monkeywie.proxyee.server.HttpProxyServerConfig;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;
public class MITMProxyServer {
public static void main(String[] args) {
HttpProxyServerConfig config = new HttpProxyServerConfig();
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) {
return HttpUtil.checkUrl(pipeline.getHttpRequest(), "^www.baidu.com$") && isHtml(httpRequest, httpResponse);
}
@Override
public void handleResponse(HttpRequest httpRequest, FullHttpResponse httpResponse, HttpProxyInterceptPipeline pipeline) {
httpResponse.headers().set("handel", "edit head");
httpResponse.content().writeBytes("".getBytes());
}
});
}
})
.start(9999);
}
}
最佳实践
证书管理:在启用 HTTPS 支持时,需要将项目中的 CA 证书(src/resources/ca.crt)导入到受信任的根证书颁发机构。自定义 CA:项目附带的根证书和私钥仅适用于本地开发和调试,正式环境中请生成自己的根证书和私钥。
4、典型生态项目
1. Netty
Proxyee 基于 Netty 框架实现,Netty 是一个高性能的异步事件驱动的网络应用框架,适用于快速开发可维护的高性能协议服务器和客户端。
2. MITMProxy
MITMProxy 是一个用于拦截和分析 HTTP 和 HTTPS 流量的工具,Proxyee 的 MITM 功能与 MITMProxy 类似,但使用 Java 实现,更适合集成到 Java 应用中。
3. Burp Suite
Burp Suite 是一个用于 Web 应用安全测试的集成平台,Proxyee 可以作为 Burp Suite 的替代方案,用于自定义的 HTTP/HTTPS 流量拦截和篡改。
通过以上模块的介绍,您可以快速了解 Proxyee 项目的基本功能和使用方法,并根据实际需求进行扩展和定制。