1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

raw socket HTTP proxy with SSL

Discussion in 'C, C++, C#' started by gnote, Apr 30, 2011.

  1. gnote

    gnote Registered Member

    Joined:
    Mar 10, 2009
    Messages:
    80
    Likes Received:
    6
    Occupation:
    Programmer
    Location:
    USA
    its funny i have socks 4/5 coded up no problem but im having trouble with http

    i got basic http proxy setup but when i try https requests i get unsupported method and protocol. can anyone clue me into the right process for the http ssl protocol? do i connect to the proxy using secure socket first, or do i connect with standard security, and then switch to secure after connected like with socks? neither way is working, but if someone who knows what they are doing could give me a clue i could prevent wasting time.
     
  2. gnote

    gnote Registered Member

    Joined:
    Mar 10, 2009
    Messages:
    80
    Likes Received:
    6
    Occupation:
    Programmer
    Location:
    USA
  3. Senotaru

    Senotaru Registered Member

    Joined:
    Jan 17, 2011
    Messages:
    67
    Likes Received:
    11
    Hey there. Here's some code to point you in the right direction.

    Code:
                String hostIp = Dns.GetHostEntry(hostname).AddressList[0].ToString();
                TcpClient client = new TcpClient(hostIp, 443);
                SslStream sslStream = new SslStream(client.GetStream(), false, new RemoteCertificateValidationCallback(ValidateCertificate), null);
                String returned = "";
    
    
                try
                {
                    sslStream.AuthenticateAsClient(hostname);
                }
                catch (Exception ex) { client.Close(); return ex.Message; }
    
                byte[] postBytes = Encoding.UTF8.GetBytes(headers + container.GetCookieString(hostname) + "\r\nConnection:Close\r\n\r\n");
                sslStream.Write(postBytes);
                sslStream.Flush();
    
                returned = readSslStream(sslStream);
                client.Close();
    The decode method:
    Code:
                byte[] downloadedData = new byte[2048];
                StringBuilder returned = new StringBuilder();
                int bytes = -1;
    
                do
                {
                    bytes = sslStream.Read(downloadedData, 0, downloadedData.Length);
                    Decoder decoder = Encoding.UTF8.GetDecoder();
                    char[] chars = new char[decoder.GetCharCount(downloadedData, 0, bytes)];
                    decoder.GetChars(downloadedData, 0, bytes, chars, 0);
                    returned.Append(chars);
                    if (returned.ToString().IndexOf("<EOF>") != -1) break;
                } while (bytes != 0);
    
                return returned.ToString();
    
     
    Last edited: May 2, 2011
  4. MakeLoot

    MakeLoot Registered Member

    Joined:
    Dec 14, 2010
    Messages:
    52
    Likes Received:
    2
    Funny, it's Seno
     
  5. ~divinci

    ~divinci Registered Member

    Joined:
    Sep 23, 2009
    Messages:
    51
    Likes Received:
    11
    Occupation:
    Infastructure Reverse Engineer
    Location:
    Liverpool UK
    Love your read loop :) can i try and improve it tomorrow?