我需要能够查看通过托管本地 VPN 服务器的 VpnService 建立的 HTTPS 连接的路径(和标头)。这可能吗?
例如,当访问https://google.com/somedir/somejsfile.js时,我需要能够看到整个路径(例如 google.com/somedir/somejsfile.js)而不是 SNI(google. com)。在对最终用户安全的情况下,这是否有可能?
我已经成功地处理了 HTTP 请求并成功地看到了 HTTP 请求,但是,现在大多数流量都是通过 HTTPS 的,所以我需要一种方法来以某种方式通过 HTTPS 来查看请求标头。
以下代码显示了我如何建立 VpnService,并分别读取/写入传入/传出数据包。
private void runVPN() throws Exception {
this.mVPNInterface = establishVPN();
this.mVPNOutputStream = new FileOutputStream(mVPNInterface.getFileDescriptor());
FileInputStream in = new FileInputStream(mVPNInterface.getFileDescriptor());
int size = 0;
while (size != -1 && IsRunning) {
while ((size = in.read(mPacket)) > 0 && IsRunning) {
if (mDnsProxy.Stopped || mTcpProxyServer.Stopped) {
in.close();
throw new Exception("LocalServer stopped.");
}
onIPPacketReceived(mIPHeader, size);
}
Thread.sleep(100);
}
in.close();
disconnectVPN();
}
void onIPPacketReceived(IPHeader ipHeader, int size) throws IOException {
switch (ipHeader.getProtocol()) {
case IPHeader.TCP:
TCPHeader tcpHeader = mTCPHeader;
tcpHeader.mOffset = ipHeader.getHeaderLength();
if (tcpHeader.getSourcePort() == mTcpProxyServer.Port) {
NatSession session = NatSessionManager.getSession(tcpHeader.getDestinationPort());
if (session != null) {
ipHeader.setSourceIP(ipHeader.getDestinationIP());
tcpHeader.setSourcePort(session.RemotePort);
ipHeader.setDestinationIP(LOCAL_IP);
Utility.ComputeTCPChecksum(ipHeader, tcpHeader);
mVPNOutputStream.write(ipHeader.mData, ipHeader.mOffset, size);
mReceivedBytes += size;
/*
mVPNOutputStream.write(ipHeader.mData, ipHeader.mOffset, size);
mReceivedBytes += size;*/
} else {
Log.d(TAG, "NoSession: " + ipHeader.toString() + " " + tcpHeader.toString());
}
} else {
int portKey = tcpHeader.getSourcePort();
NatSession session = NatSessionManager.getSession(portKey);
if (session == null || session.RemoteIP != ipHeader.getDestinationIP() || session.RemotePort
!= tcpHeader.getDestinationPort()) {
session = NatSessionManager.createSession(portKey, ipHeader.getDestinationIP(), tcpHeader
.getDestinationPort());
}
session.LastNanoTime = System.nanoTime();
session.PacketSent++;
int tcpDataSize = ipHeader.getDataLength() - tcpHeader.getHeaderLength();
if (session.PacketSent == 2 && tcpDataSize == 0) {
return;
}
if (session.BytesSent == 0 && tcpDataSize > 10) {
int dataOffset = tcpHeader.mOffset + tcpHeader.getHeaderLength();
HttpRequestHeaderParser.parseHttpRequestHeader(session, tcpHeader.mData, dataOffset,
tcpDataSize);
// Log.d(TAG, "NatSession: " + session);
// Log.d(TAG, "Host: " + session.RemoteHost);
// Log.d(TAG, "Request: " + session.Method + " " + session.RequestUrl);
}
ipHeader.setSourceIP(ipHeader.getDestinationIP());
ipHeader.setDestinationIP(LOCAL_IP);
tcpHeader.setDestinationPort(mTcpProxyServer.Port);
Utility.ComputeTCPChecksum(ipHeader, tcpHeader);
mVPNOutputStream.write(ipHeader.mData, ipHeader.mOffset, size);
session.BytesSent += tcpDataSize;
mSentBytes += size;
}
break;
case IPHeader.UDP:
UDPHeader udpHeader = mUDPHeader;
udpHeader.mOffset = ipHeader.getHeaderLength();
if (ipHeader.getSourceIP() == LOCAL_IP && udpHeader.getDestinationPort() == 53) {
mDNSBuffer.clear();
mDNSBuffer.limit(udpHeader.getTotalLength() - 8);
DnsPacket dnsPacket = DnsPacket.fromBytes(mDNSBuffer);
if (dnsPacket != null && dnsPacket.Header.QuestionCount > 0) {
mDnsProxy.onDnsRequestReceived(ipHeader, udpHeader, dnsPacket);
}
}
break;
}
}
非常感谢有关此问题的任何帮助或指导。
先感谢您。