monkeyWie / proxyee

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

大佬,very 666 #103

Open liming1010 opened 3 years ago

liming1010 commented 3 years ago

能设置用户名和密码就好了

monkeyWie commented 3 years ago

你是说代理服务器的身份验证支持吗

liming1010 commented 3 years ago

是啊,就是使用代理的时候需要用户和密码,还问一下大佬,流量统计要咋做啊?

monkeyWie commented 3 years ago

流量统计要做的话,得计算出请求和响应的报文大小,用一个拦截器应该可以实现

liming1010 commented 3 years ago

厉害啊,我写个流量统计的 `public class HttpProxyFlowHandle extends ChannelTrafficShapingHandler {

String clientIP;
Long  lastWrittenBytes;
Long lastReadBytes;

public HttpProxyFlowHandle(long writeLimit, long readLimit, long checkInterval, long maxTime) {
    super(writeLimit, readLimit, checkInterval, maxTime);
}

@Override
protected void doAccounting(TrafficCounter counter) {
    lastWrittenBytes = counter.lastWrittenBytes();
    lastReadBytes = counter.lastReadBytes();
    BigDecimal b = new BigDecimal(lastWrittenBytes / 1024D / 1024D);
    Double d = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();

    System.out.println(clientIP + ":上个监控周期读取了"+lastReadBytes+"个字节,发送了"+lastWrittenBytes+"个字节"+". 累计: "+d+"M");
    super.doAccounting(counter);
}

@Override
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
    InetSocketAddress insocket = (InetSocketAddress) ctx.channel().remoteAddress();
    this.clientIP = insocket.getAddress().getHostAddress();
    super.handlerAdded(ctx);
}

}`

ch.pipeline().addLast("flow", new HttpProxyFlowHandle(1000,100,8000L, 1000L*10));

用户名和密码就不知道咋弄了

monkeyWie commented 3 years ago

用户名和密码的我有空的时候加下吧,不麻烦

liming1010 commented 3 years ago

我加了一个handle,用来验证用户名和密码,就是从request里面header获取验证信息 `public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if(msg instanceof HttpRequest){

        HttpRequest request = (HttpRequest)msg;
        HttpHeaders headers = request.headers();
        log.info("{}", headers.toString());
    }
    ctx.fireChannelRead(msg);
}`

这里面的header只有几个很少的字段,header里面的cookies,conten-type等等其他的没有 大佬

monkeyWie commented 3 years ago

代理服务器验证是有标准支持的,需要实现下这个标准

liming1010 commented 3 years ago

我改了一下,就是在返回的时候加上了: httpResponse.setStatus(HttpResponseStatus.UNAUTHORIZED); httpResponse.headers().add("WWW-authenticate","Basic realm=\"\"");

在根据IP和用户名进行判断 代码被我改的有点乱,可以提交吗 ^_^

monkeyWie commented 3 years ago

可以提交pr我看下

LamGC commented 3 years ago

能独立成模块吗,如果能独立成模块的话就不用强塞到核心代码中了,方便维护。

liming1010 commented 3 years ago

提交pr了,写了独立模块