Click here to Skip to main content
6,632,253 members and growing! (21,003 online)
Email Password   helpLost your password?
General Programming » Internet / Network » Proxy / Firewall     Intermediate

HTTP Tunneling

By Alex Turc

This article describes how to open arbitrary TCP connections through proxy servers
VC6Win2K, MFC, STL, Dev
Posted:14 Jun 2000
Views:294,554
Bookmarked:94 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
83 votes for this article.
Popularity: 8.80 Rating: 4.59 out of 5
1 vote, 2.9%
1
1 vote, 2.9%
2
2 votes, 5.9%
3
8 votes, 23.5%
4
22 votes, 64.7%
5
  • Download source files - 24 Kb
  • Download demo application - 87 Kb
  • Introduction

    The application discussed in this article provides the ability to make TCP connections through a proxy server. Often computers are behind firewalls that deny many connections. But HTTP connection is usually allowed and is made through a proxy server. This article will show how arbitrary TCP connections can be made using HTTP protocol and the proxy server.

    Approach

    When an HTTP connection is made through a proxy server the client (usually the browser) sends the request to the proxy. The proxy opens the connection to the destination, sends the request, receives the response and sends it back to the client. The HTTP protocol specifies a request method called CONNECT. The CONNECT method can be used by the client to inform the proxy server that a connection to some host on some port is required. The proxy server, if allows such connections, tries to connect to the destination address specified in the request header. If it the operation fails it sends back to the client a negative HTTP response and close the connection. If the operation succeeded then send back an HTTP positive response and the connection is consider established. After that, the proxy does not care what data is transferred between client requesting the connection and the destination. It just forwards data in both ways acting as a tunnel.

    About the protocol

    We are interested in CONNECT method from the HTTP protocol. After the applications opens a connection with the proxy server it must send the connect request in the form of an HTTP request:

    CONNECT <destination_address>:<destination_port> <http_version><CR><LF>
    <header_line><CR><LF>
    <header_line><CR><LF>
    ...
    <header_line><CR><LF>
    <CR><LF>
    

    The proxy server process the request and try to make a connection to <destionation_address>:<destination_port>.

    The proxy server sends back an HTTP response in the form:

    <http_version> <code> <message><CR><LF>
    <header_line><CR><LF>
    <header_line><CR><LF>
    ...
    <header_line><CR><LF>
    <CR><LF>
    

    If it is a positive response (code=200) then after the empty line the proxy begins to acts as a tunnel and forwards data. If it is a negative response (code!=200) then connection is closed after the empty line.

    The HTTPTunneling application

    The application act as specified in a configuration file. An entry in the configuration file locks like this:

    <Source port> <Destination address> <Destination port> <Proxy address> <Proxy port>

    If the application is running and an entry in the configuration files changes, the application automatically updates itself.

    For every entry in the configuration file the application creates a port listener. This is a thread that opens a socket on <Source port> and waits for connection. When a request arrives on that port it tries to open a tunnel to the <Destination address>:< port>. If the <Proxy address> and <Proxy port> are missing, a direct connection is made. If the field are present it opens a connection to the proxy and sends a CONNECT request using the method specified above. The tunnel construction is made in a separate thread to let the port listener to accept immediatelly new connections. After the connection is established a tunnel object is constructed based on the opened sockets, sockets are marked as non-blocking and the object is passed to manager object. The thread that has created the tunnel is destroyed. Data transfer is made on a single thread. When one of the ends closes the connection the tunnel closes the other and the tunnel is marked as inactive. The manager finds the tunnel inactive and removes it from the list of active tunnels.

    By default the application generates log information in HTTPTunneling.log file. This file can be consulted to find wrong application behaviour.

    Known problems

    • If no data transfer is made the proxy could close the connection, event neither the initiator neither the destination has closed the connection.
    • Proxy authorization may be required. This can be easily solved including in the HTTP request the Proxy-Authorization field.

    History

    June 15, 2000

    • Posted.

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    About the Author

    Alex Turc


    Member

    Location: United States United States

    Other popular Internet / Network articles:

    Article Top
    You must Sign In to use this message board.
    FAQ FAQ 
     
    Noise Tolerance  Layout  Per page   
     Msgs 1 to 25 of 86 (Total in Forum: 86) (Refresh)FirstPrevNext
    General[Message Deleted] Pinmemberit.ragester22:57 2 Apr '09  
    GeneralQuestion about the method connect!! PinmemberPitoniso11:02 15 May '07  
    GeneralI've got a Modern Compiler [modified] Pinmemberqduaty5:03 11 Dec '06  
    GeneralBeginner Pinmemberparamprocessor0:11 28 Nov '06  
    GeneralHTTP protocol Pinmemberrenato tome17:05 1 Nov '06  
    GeneralRe: HTTP protocol Pinmemberrenato tome16:18 12 Feb '07  
    QuestionC# Implementation?? Pinmembergvanto4:52 22 Aug '06  
    QuestionRedircting data from one tcp port to another PinmemberPankajs_comp21:40 31 May '06  
    GeneralSQL via Proxy Pinmemberevilnoodle23:29 22 Mar '06  
    GeneralI have a question about proxy ISA2000 ? Pinmembercatclaw200016:40 16 Jan '06  
    Generaltunnelling for VNC Pinmembergeorgenew5:34 4 Aug '05  
    AnswerRe: tunnelling for VNC PinmemberPankaj Sahasrabudhe2:12 28 May '08  
    GeneralWebsense _HELP PinsussANON-10:47 4 Mar '05  
    GeneralAutorisation - how PinsusscnkKlau13:12 16 Feb '05  
    Generalconaito VoIP ActiveX SDK PinsussAttila Szappan4:06 13 Dec '04  
    GeneralRe: conaito VoIP ActiveX SDK Pinmemberbrian scott5:39 10 Apr '06  
    GeneralRe: conaito VoIP ActiveX SDK Pinmemberandyjones120:16 10 Jun '09  
    GeneralCan tunnel solve nat/port forwarding problems? PinsussAnonymous20:07 26 Nov '04  
    GeneralAny way to reduce .exe file size? PinmemberJList16:55 8 Aug '04  
    GeneralMemory leak problem PinmemberLe Hong Anh20:11 6 Jun '04  
    Generalvoip ocx , voip activex , voip lib Pinsusshasnat ahmad1:37 2 Jan '04  
    GeneralConnect to SMTP Pinmembertaualex2:30 4 Nov '03  
    GeneralFree Firewall With Source Code Pinmemberxiamy6:52 3 Nov '03  
    GeneralRe: Free Firewall With Source Code PinmemberEd K5:20 11 Feb '04  
    GeneralRe: Free Firewall With Source Code Pinmemberjproffer6:50 20 Jun '04  

    General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    PermaLink | Privacy | Terms of Use
    Last Updated: 14 Jun 2000
    Editor: Chris Maunder
    Copyright 2000 by Alex Turc
    Everything else Copyright © CodeProject, 1999-2009
    Web21 | Advertise on the Code Project