I am trying to connect to my HTTPS server via SOCKS4 proxy, but it seems like it is not working.
Here is my code:
headers = "GET / HTTP/1.1\r\nHost: domain.com\r\n\r\n"
import socks
import ssl
conn = socks.socksocket()
conn.set_proxy(socks.SOCKS4, host, port)
conn.connect(("domain.com", 443))
conn = ssl.create_default_context().wrap_socket(conn, server_hostname="domain.com")
conn.send(headers.encode())
After I run that code, I checked my website log and nothing happened. But if I change the connect() port to 80, it worked.
                        
You are
connect()'ing thesocksTCP connection to the HTTPS server's TLS port before creating thesslcontext. Which is fine, however theSSLSocketthatwrap_socket()returns will automatically calldo_handshake()to negotiate a TLS session only when itsconnect()method is called, which you are bypassing. So, you will need to manually calldo_handshake()afterwrap_socket()returns and before callingsend(), eg: