I wrote a SOCKS proxy that works with HTTP and HTTPS traffic if the chain is disconnected.
If the chain is enabled, and the host and forwarding ports belong to the filtered HTTP proxy, only HTTP traffic can flow. HTTPS traffic is not arriving and reports an SSL error.
Please note that the HTTP proxy handles HTTPS traffic when the request comes directly from the browser, and not from the SOCKS server.
As an example, if I make a request to https://www.google.com , the following will happen:
1) The client sends a SOCKS 5 greeting to tell us which auth methods are acceptable.
2) Server responds with NO_AUTH
3) The client sends a connection request (which includes the target host and destination port).
4) The server creates and connects the socket to the HTTP proxy server and responds to the client using GRANTED
5) Then, the SOCKS server receives the following request (all invisible / control characters are replaced by their character codes, so you can see what is happening):
\u0016\u0003\u0001\u0000Ñ\u0001\u0000\u0000Í\u0003\u0003áp¥@Ia¹\u0001„Ä\u0006 É;š‰‰4\u001dýà•J>Ü6¢Þ\fö\u001c%\u0000\u0000(À+À/\u0000žÌ\u0014Ì\u0013À\nÀ\tÀ\u0013À\u0014À\u0007À\u0011\u00003\u00002\u00009\u0000œ\u0000/\u00005\u0000\n\u0000\u0005\u0000\u0004\u0001\u0000\u0000|\u0000\u0000\u0000\u0013\u0000\u0011\u0000\u0000\u000ewww.google.comÿ\u0001\u0000\u0001\u0000\u0000\n\u0000\b\u0000\u0006\u0000\u0017\u0000\u0018\u0000\u0019\u0000\u000b\u0000\u0002\u0001\u0000\u0000
As you can see, it is not fully readable, but we already know where the user intends to go from the original SOCKS message (step 3) so that we can create and publish the following connection request:
CONNECT www.google.com:443 HTTP/1.1\r\nUser-Agent: MySocksServer\r\nProxy-Connection: keep-alive\r\nHost: www.google.com\r\n\r\n
6) This newly created CONNECT is sent to the HTTP proxy server to which we are attached, this proxy checks its filtering rules and responds:
HTTP/1.1 200 Connection Established\r\nVia: 1.1 HTTPserverName\r\nX-WebMarshal-RequestID: AN_ID_STRING\r\n\r\n
7) This is received on our SOCKS server and is forwarded (unmodified) to the client. In my debugging, I track sockets just before sending and see that a client socket is connected.
8) - , SOCKET_NOT_CONNECTED, , .
Socket 7 8 ? ? , . , CONNECT?
, SOCKS (.. CONNECT), - HTTP, HTTP- :
Badly formated request: \u0016\u0003\u001
Bad request received.
Failed to read request: Client closed connection. (0)
1Request took 0 ms + 23 ms idle time