• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            elva

            HTTP Tunneling

            Introduction

            HTTP Tunneling

            HTTP is a text-based protocol to retrieve Web pages through a Web browser. Mostly, if you are on a LAN connection, you are behind a proxy server; this proxy server has one HTTP proxy running on some defined port. In your Internet Explorer's Connection option, you specify LAN settings as required. This proxy server is definitely running on a text-based protocol, and you can only get HTTP-related data from the outside network, right!! Well, there is a small loophole from which you can go through HTTP and connect to the outside world and get any data you want in binary protocol, or even your own protocol. It's through HTTPS.

            HTTPS Explanation

            In HTTPS, data is transferred from browser to server and server to browser in a secure manner. It's a binary protocol; when it goes through a proxy, the proxy doesn't understand anything. The proxy just allows a binary stream to open and lets both server and client exchange the data. Now, we can fool the proxy server and connect to any server and exchange data. The proxy server will think that we are doing some secure HTTP session.

            For HTTPS, your browser connects to a proxy server and sends a command:

            CONNECT neurospeech.com:443 HTTP/1.0 <CR><LF>
            HOST neurospeech.com:443<CR><LF>
            [... other HTTP header lines ending with <CR><LF> if required]>
            <CR><LF>    // Last Empty Line

            Then, the proxy server treats this as some HTTP Secure Session, and opens a binary stream to the required server and port as defined. If a connection is established, the proxy server returns the following response:

            HTTP/1.0 200 Connection Established<CR><LF>
            [.... other HTTP header lines ending with <CR><LF>..
            ignore all of them]
            <CR><LF>    // Last Empty Line

            Now, the browser is connected to the end server and can exchange data in both a binary and secure form.

            How to Do This

            Now, it's your program's turn to fool the proxy server and behave as Internet Explorer behaves for Secure HTTP.

            1. Connect to Proxy Server first.
            2. Issue CONNECT Host:Port HTTP/1.1<CR><LF>.
            3. Issue <CR><LF>.
            4. Wait for a line of response. If it contains HTTP/1.X 200, the connection is successful.
            5. Read further lines of response until you receive an empty line.
            6. Now, you are connected to the outside world through a proxy. Do any data exchange you want.

            Sample Source Code

            Collapse
              // You need to connect to mail.yahoo.com on port 25
            // Through a proxy on 192.0.1.1, on HTTP Proxy 4480
            // CSocketClient is Socket wrapping class
            // When you apply operator << on CString, it writes CString
            // To Socket ending with CRLF
            // When you apply operator >> on CString, it receives
            // a Line of response from socket until CRLF
            try
            {
            CString Request,Response;
            CSocketClient Client;
            Client.ConnectTo("192.0.1.1",4480);
            // Issue CONNECT Command
            Request = "CONNECT mail.yahoo.com:25 HTTP/1.0";
            Client<<Request;
            // Issue empty line
            Request = "";
            Client<<Request;
            // Receive Response From Server
            Client>>Response;
            // Ignore HTTP Version
            int n = Response.Find(' ');
            Response = Response.Mid(n+1);
            // Http Response Must be 200 only
            if(Response.Left(3)!="200")
            {
            // Connection refused from HTTP Proxy Server
            AfxMessageBox(Response);
            }
            // Read Response Lines until you receive an empty line.
            do
            {
            Client>>Response;
            if (Response.IsEmpty())
            break;
            }while (true);
            // Coooooooool.... Now connected to mail.yahoo.com:25
            // Do further SMTP Protocol here..
            }
            catch (CSocketException * pE)
            {
            pE->ReportError();
            }

            Library Source Code

            The Dns.h file contains all DNS-related source code. It uses other libraries, as SocketEx.h, SocketClient.h, and NeuroBuffer.h.

            CSocketEx

            Socket functions as a wrapper class. (CSocket is very heavy and unreliable if you don't have the exact idea of how it works.) All the functions are of the same name as CSocket. You can use this class directly.

            CSocketClient

            Derived from CSocketEx and throws proper exceptions with details of Winsock errors. It defines two operators, >> and <<, for easy sending and receiving; it also changes network to host and host to network order of bytes if required.

            CHttpProxySocketClient

            Derived from CSocketClient, you can call the SetProxySettings(ProxyServer,Port) method and set proxy settings. Then, you can connect to the desired host and port as you need. The ConnectTo method is overridden, and it automatically implements an HTTP proxy protocol and gives you a connection without any hassle.

            How to Use CHttpProxySocketClient

            Collapse
              // e.g. You need to connect to mail.yahoo.com on port 25
            // Through a proxy on 192.0.1.1, on HTTP Proxy 4480
            // CSocketClient is Socket wrapping class
            // When you apply operator << on CString, it writes CString
            // To Socket ending with CRLF
            // When you apply operator >> on CString, it receives
            // Line of response from socket until CRLF
            try
            {
            CHttpProxySocketClient Client;
            Client.SetProxySettings("192.0.1.1",1979);
            // Connect to server mail.yahoo.com on port 25
            Client.ConnectTo("mail.yahoo.com",25);
            // You now have access to mail.yahoo.com on port 25
            // If you do not call SetProxySettings, then
            // you are connected to mail.yahoo.com directly if
            // you have direct access, so always use
            // CHttpProxySocketClient and no need to do any
            // extra coding.
            }
            catch(CSocketException * pE) {
            pE->ReportError();
            }

            Note: I usually don't program in the form of .h and .cpp different files, because using them the next time somewhere else is a big problem because you must move both files here and there. So, I put all the code in my .h file only; I don't write to the .cpp file unless it's required. You need to copy only the SocketEx.h, SocketClient.h, and HttpProxySocket.h files into your project's directory, and add line:

            #include "HttpProxySocket.h"

            after your:

            #if !defined(.....

            and so forth code of your Visual Studio-generated file. If you put anything above this, you will get n number of errors.

             

            posted on 2007-05-06 16:51 葉子 閱讀(681) 評論(0)  編輯 收藏 引用 所屬分類: 網絡安全

            精品久久人人做人人爽综合| 精品无码人妻久久久久久| 国产精品无码久久综合网| 99久久精品九九亚洲精品| 久久精品18| 国内精品久久久久久99蜜桃| 91亚洲国产成人久久精品| 亚洲综合久久久| 久久精品这里热有精品| 久久精品国产99久久香蕉| 无码国内精品久久人妻| 久久成人精品| 国产成人精品久久免费动漫| 久久中文字幕无码专区| 精品久久久久久无码专区不卡 | 99久久婷婷免费国产综合精品| 久久久久亚洲AV成人网| 久久综合五月丁香久久激情| 思思久久好好热精品国产| www性久久久com| 97精品国产97久久久久久免费| 精品综合久久久久久888蜜芽| 热久久这里只有精品| 久久久久久久久波多野高潮| 久久人人爽人人爽人人片AV麻豆| 欧美午夜精品久久久久免费视| 国产日韩久久久精品影院首页| 狠狠色婷婷久久综合频道日韩| 国产精品VIDEOSSEX久久发布| 色偷偷88888欧美精品久久久| 热综合一本伊人久久精品| 热久久国产精品| 丰满少妇高潮惨叫久久久| 久久笫一福利免费导航 | AA级片免费看视频久久| 久久精品天天中文字幕人妻| 亚洲欧美久久久久9999| 欧美一级久久久久久久大| 色播久久人人爽人人爽人人片aV| 国内精品久久久久影院网站| 粉嫩小泬无遮挡久久久久久|