Click here to Skip to main content
Click here to Skip to main content

HTTP Tunneling

By , 14 Jun 2000
 
  • 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
    United States United States
    Member
    No Biography provided

    Sign Up to vote   Poor Excellent
    Add a reason or comment to your vote: x
    Votes of 3 or less require a comment

    Comments and Discussions

     
    You must Sign In to use this message board.
    Search this forum  
        Spacing  Noise  Layout  Per page   
    GeneralMy vote of 4memberanderbill8 Nov '10 - 16:14 
    Good, Does it support NTLM? such as a free http tunneling SDK provider by www.networktunnel.net.
    General[Message Deleted]memberit.ragester2 Apr '09 - 21:57 
    [Message Deleted]
    GeneralQuestion about the method connect!!memberPitoniso15 May '07 - 10:02 
    As I can make for that in you see of using the method CONNECT use the one POST method... it is that the CONNECT this forbidden one in my NET.... Thank you
     
    The Your-Freedom program do that!! Any Idea!!
     
    www.your-freedom.net
     
    Cool | :cool:
    GeneralI've got a Modern Compiler [modified]memberqduaty11 Dec '06 - 4:03 
    In particular VC2005 and gcc 3.4. Both say it's not C++. Question to the author: can you tell me what assumptions were you made? Such projects are not too numerous; I think it's worth porting it to modern development environments. From the other hand, the demo application fails [edit: when new connection is requested] with Firefox and Opera (typical C++ memory access issues), so it's necessary to do some bugfixes.
     

    -- modified at 10:08 Monday 11th December, 2006
    GeneralBeginnermemberparamprocessor27 Nov '06 - 23:11 
    Hey,
     
    I'm new to networking. I not able to find what this program does. Here my proxy does not allow to check yahoo mails. Can I do that with this program?
     
    Thanks
     
    Param

    GeneralHTTP protocolmemberrenato tome1 Nov '06 - 16:05 
    Does my TCP data can passed thru the proxy even if its not a HTTP protocol?, some proxy may allow only HTTP protocol, and some may allow only at the specified packet source port.
     
    tugak@bigfoot.com

    GeneralRe: HTTP protocolmemberrenato tome12 Feb '07 - 15:18 
    i have an application server daemon that runs in CentOS, i put specific threads there that listen in port 80 (http), port 443(https), port 34992(tcp raw), 34886(rtcp), all request coming out of this port(80,443) are transformed into TCP raw data then port forward to my TCP raw port. i've use the http tunneling on the client side as i watch the logs at the server and i didnt see any request passed thru. i really dont know the configuration of my firewall, but im sure my firewall is blocking those packets.
     
    tugak@bigfoot.com

    QuestionC# Implementation??membergvanto22 Aug '06 - 3:52 
    Anyone know of a C# implementation of this code?
     
    Any help would be much appreciated!
     
    Thanks,
    Gerry
     
    Cheer Up Your Day Big Grin | :-D
    AnswerRe: C# Implementation??member i0016 Apr '13 - 14:13 
    I want the same ... such a shame...

    QuestionRedircting data from one tcp port to anothermemberPankajs_comp31 May '06 - 20:40 
    Hello friends,
     
    I am developing an application in which i want to transfer data from one TCP port to another TCP port. Data is coming on one TCP port from different computer and I want to transfer that data to another computer which conneted with internet.
     
    Can anybody please tell me how to do this and if this is possible or not.
     
    Pankaj Sahasrabudhe.
     
    Pankaj Sahasrabudhe
    GeneralSQL via Proxymemberevilnoodle22 Mar '06 - 22:29 
    Hi,
     
    Can I tunnel an ODBC connection through a proxy?
    If so, how?

    QuestionI have a question about proxy ISA2000 ?membercatclaw200016 Jan '06 - 15:40 
    I connect web via ISA2000, but I recieve error code:407.
    ISA2000 need authorization(NTLM).
    What shall I do?
     
    Thanks a lot!
     
    -- modified at 21:45 Monday 16th January, 2006
    Generaltunnelling for VNCmembergeorgenew4 Aug '05 - 4:34 
    Hi
     
    I have just found this website after a few searches and was wondering if anyone would be kind enough to help with a query.
     
    Has anybody tried this with VNC? we use a ISA proxy server to access the internet which blocks all but http traffic.. VNC uses port 5800/5900
     
    When not behind a firewall etc, you can connect to the pc as http://IPADDRESS:5800
     
    so would i be able to use this program to remote control a pc at home?
     
    Thanks
     
    George
    AnswerRe: tunnelling for VNCmemberPankaj Sahasrabudhe28 May '08 - 1:12 
    To control your home pc with VNC you need to have static ip for home pc. Because VNC makes TCP connection with its client and server, your server must be running on fixed ip so that VNC client can reach to it over the internet. If you can set up static ip in home you can easily control it from anywhere you want.
    GeneralRe: tunnelling for VNCmemberanderbill8 Nov '10 - 16:17 
    I found super network tunnel can do it or you seach google http tunnel for another solution.
    GeneralWebsense _HELPsussANON-13 Mar '05 - 23:47 
    Iam trying to get past websense but having no luck so i downloaded this program but i have had no experience with this before and no idea how to get by the proxy, i dont know any ports or anything like that for the netowrk and i am not the administrator, can somebody help me.
    GeneralAutorisation - howsusscnkKlau16 Feb '05 - 12:12 
    you say somewhere "Proxy authorization may be required. This can be easily solved including in the HTTP request the Proxy-Authorization field". I am wondering how exactly because in my case would be very important.
    Can't you modify the program so that in the log file can be specified the username and password?
     
    thanks a lot!
     
    Hi..
    Generalconaito VoIP ActiveX SDKsussAttila Szappan13 Dec '04 - 3:06 
    conaito VoIP ActiveX library for developers of VoIP audio applications, such as voice chat, conference, VoIP, providing real-time low latency multi-client audio streaming over UDP/IP networks. Includes efficient components for sound recording, playback, encoding, decoding, mixing, resampling, reading, and writing wave files, mixer volume controls access. Provides UDP/IP server and client components for peer-to-peer, multi-user, and broadcast audio communications. Really easy to use! Working with Firewall and NAT! conaito VoIP SDK is the best way to add voice conference and text conference into your application and web pages. conaito VoIP SDK includes voip activex, voip ocx, voip com, voip dll, voip lib and voip cab, so you can use the one you like the most
    GeneralRe: conaito VoIP ActiveX SDKmemberbrian scott10 Apr '06 - 4:39 
    er ... is this an advert?Confused | :confused:
     
    brian
    GeneralRe: conaito VoIP ActiveX SDKmemberandyjones129 Jun '09 - 23:16 
    Hi iam also running a voip software and its very good. I am using VOIPSIPSDK softwares for my office softphones. They are not free but worth it. Highly recomended.
    QuestionCan tunnel solve nat/port forwarding problems?sussAnonymous26 Nov '04 - 19:07 
    is it possible to tunnel tcp traffic in other ports thru port 80?
    QuestionAny way to reduce .exe file size?memberJList8 Aug '04 - 15:55 
    The demo exe is 188k. How come it's so big given that the source code is not that complicated. Is there any unnecessary libraries that are being linked?
    GeneralMemory leak problemmemberLe Hong Anh6 Jun '04 - 19:11 
    if it serve many connection at a time, program is broken down,any body know why ?
    Generalvoip ocx , voip activex , voip libsusshasnat ahmad2 Jan '04 - 0:37 
    cool voip ocx, voip activex, voip lib controls, visit www.vaxvoip.com , controls really work behind the NAT and fire walls.

    GeneralConnect to SMTPmembertaualex4 Nov '03 - 1:30 
    Hi!
     
    Alex, can you spare a few minutes and give an example/idea, how can I tunnel a SMTP connection (port 25) to send an email through a proxy? And how to to add an authentication for a proxy?
     
    Thanks a lot!
     
    Kind regards... Tau.

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Permalink | Advertise | Privacy | Mobile
    Web03 | 2.6.130516.1 | Last Updated 15 Jun 2000
    Article Copyright 2000 by Alex Turc
    Everything else Copyright © CodeProject, 1999-2013
    Terms of Use
    Layout: fixed | fluid