Search code examples
c#socketshttpsproxysocks

How I can open https pages via socks on c#?


I'm using c# and I built socks5 client which uses socks5 server to get web pages. But these pages only on 80 port (HTTP). I wanna open pages which on 443 port (HTTPS). e.g.: https://google.com . If I'll just connect via socks5 on 443 -> google server rejects me. How can I do that?

PS: my client works via sockets, maybe I should use another way?

And sorry for my english.


Solution

  • Big thanks to @jdweng. The solution is:

    we can use TcpClient or Sockets (doesn't matter) for connect to our socks server. e.g.:

    create TcpClient using our socksIp/socksPort
    get NetworkStream from our TcpClient.GetStream();
    
    or use sockets
    
    ________
    THEN:
    ________
    send 0x05,0x01,0x00
    receive 0x05, 0x00
    send 0x05, 0x01, 0x00, 0x03, 0x0f, 0x77, 0x77, 0x77, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65 <- it's for www.example.com:443
    receive 0x05, 0x00, 0x00, 0x01, etc
    if we used sockets -> create NetworkStream from our socket
    create SslStream from our NetworkStream
    in SslStream - authenticate as client with www.example.com
    send our request like a "GET / HTTP/1.1\r\nHost: www.example.com\r\nConnection: close\r\n\r\n"
    receive while not eof
    close stream/socket etc
    

    Profit :)