How to forward HTTPS traffic from a SOCKS proxy to HTTP proxy

我的未来我决定 提交于 2019-12-04 19:34:55

6) This newly constructed CONNECT is sent to the HTTP proxy ... this proxy ... responds with:

7) This is received in our SOCKS server and is forwarded (unmodified) to the client...

This is wrong. You generate the CONNECT request in your SOCKS proxy and therefore you should keep the response to this request to yourself and not forward it to the client. What you should do:

  • If you receive the start of the SSL handshake from the client ("\x16\x03... ") you should buffer it.
  • Then you create the CONNECT request and send it to the proxy. The Host header and Proxy-Connection headers have no meaning with CONNECT so you don't need to add them.
  • Read the response from the proxy to the CONNECT request. If status code is not 200 something is wrong and you should close the connection to the client. There is no easy way to transfer the error information to the client.
  • If status code is 200 forward the buffered ClientHello from the client to the server through the proxy and from then on forward everything between client and server (through the proxy tunnel).

The correct sequence is:

  1. client connects to SOCKS proxy, authenticates as needed.

  2. client sends a SOCKS connect request to create a tunnel to www.google.com:443.

  3. SOCKS proxy connects to HTTP proxy

  4. SOCKS proxy sends an HTTP CONNECT request to create a tunnel to www.google.com:443.

  5. SOCKS proxy receives a reply from HTTP proxy.

  6. SOCKS proxy sends an appropriate SOCKS reply to client.

  7. If HTTP proxy was successful, pass unmodified data between client and HTTP proxy until one of them disconnects.

  8. close the client connection and the HTTP proxy connection.

When you chain proxies, you have to negotiate the tunnels before you can then start passing application data through them. Do not send a tunnel reply to the client until the next proxy replies with its tunnel status first.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!