noVNC/utils
Joel Martin f2538f337d wsproxy, wstelnet: wrap command, WS telnet client.
wswrapper:

    Getting the wswrapper.c LD_PRELOAD model working has turned out to
    involve too many dark corners of the glibc/POSIX file descriptor
    space. I realized that 95% of what I want can be accomplished by
    adding a "wrap command" mode to wsproxy.

    The code is still there for now, but consider it experimental at
    best. Minor fix to dup2 and add dup and dup3 logging.

wsproxy Wrap Command:

    In wsproxy wrap command mode, a command line is specified instead
    of a target address and port. wsproxy then uses a much simpler
    LD_PRELOAD library, rebind.so, to move intercept any bind() system
    calls made by the program. If the bind() call is for the wsproxy
    listen port number then the real bind() system call is issued for
    an alternate (free high) port on loopback/localhost.  wsproxy then
    forwards from the listen address/port to the moved port.

    The --wrap-mode argument takes three options that determine the
    behavior of wsproxy when the wrapped command returns an exit code
    (exit or daemonizing): ignore, exit, respawn.

    For example, this runs vncserver on turns port 5901 into
    a WebSockets port (rebind.so must be built first):

        ./utils/wsproxy.py --wrap-mode=ignore 5901 -- vncserver :1

    The vncserver command backgrounds itself so the wrap mode is set
    to "ignore" so that wsproxy keeps running even after it receives
    an exit code from vncserver.

wstelnet:

    To demonstrate the wrap command mode, I added WebSockets telnet
    client.

    For example, this runs telnetd (krb5-telnetd) on turns port 2023
    into a WebSockets port (using "respawn" mode since telnetd exits
    after each connection closes):

        sudo ./utils/wsproxy.py --wrap-mode=respawn 2023 -- telnetd -debug 2023

    Then the utils/wstelnet.html page can be used to connect to the
    telnetd server on port 2023. The telnet client includes VT100.js
    (from http://code.google.com/p/sshconsole) which handles the
    terminal emulation and rendering.

rebind:

    The rebind LD_PRELOAD library is used by wsproxy in wrap command
    mode to intercept bind() system calls and move the port to
    a different port on loopback/localhost. The rebind.so library can
    be built by running make in the utils directory.

    The rebind library can be used separately from wsproxy by setting
    the REBIND_OLD_PORT and REBIND_NEW_PORT environment variables
    prior to executing a command. For example:

        export export REBIND_PORT_OLD="23"
        export export REBIND_PORT_NEW="65023"
        LD_PRELOAD=./rebind.so telnetd -debug 23

    Alternately, the rebind script does the same thing:

        rebind 23 65023 telnetd -debug 23

Other changes/notes:

- wsproxy no longer daemonizes by default. Remove -f/--foreground
  option and add -D/--deamon option.

- When wsproxy is used to wrap a command in "respawn" mode, the
  command will not be respawn more often than 3 times within 10
  seconds.

- Move getKeysym routine out of Canvas object so that it can be called
  directly.
2011-01-12 13:15:11 -06:00
..
Makefile wsproxy, wstelnet: wrap command, WS telnet client. 2011-01-12 13:15:11 -06:00
README.md wsproxy, wstelnet: wrap command, WS telnet client. 2011-01-12 13:15:11 -06:00
VT100.js wsproxy, wstelnet: wrap command, WS telnet client. 2011-01-12 13:15:11 -06:00
include wsproxy, wstelnet: wrap command, WS telnet client. 2011-01-12 13:15:11 -06:00
launch.sh wsproxy, wstelnet: wrap command, WS telnet client. 2011-01-12 13:15:11 -06:00
md5.c Remove left over record code. Squelch compile warnings 2010-11-06 10:53:32 -05:00
md5.h Update C proxy to WS protocol version 76. 2010-06-30 20:39:41 -05:00
md5_test.c Update C proxy to WS protocol version 76. 2010-06-30 20:39:41 -05:00
rebind wsproxy, wstelnet: wrap command, WS telnet client. 2011-01-12 13:15:11 -06:00
rebind.c wsproxy, wstelnet: wrap command, WS telnet client. 2011-01-12 13:15:11 -06:00
web.py set socket option SO_REUSEADDR to prevent "Address already in use" error 2010-12-21 23:31:46 +08:00
websocket.c wsproxy: warn when no cert. C sock close cleanup. 2011-01-04 13:14:46 -06:00
websocket.h Add --key option for separate cert and key file. 2010-11-06 10:55:09 -05:00
websocket.py wsproxy, wstelnet: wrap command, WS telnet client. 2011-01-12 13:15:11 -06:00
wsecho.html wswrapper: add dup2, fix select w/ NULL timeout. 2011-01-08 21:46:36 -06:00
wsecho.py wsproxy, wstelnet: wrap command, WS telnet client. 2011-01-12 13:15:11 -06:00
wsproxy.c wsproxy, wstelnet: wrap command, WS telnet client. 2011-01-12 13:15:11 -06:00
wsproxy.js wsproxy.js: Fix multi-frame decoding. 2010-11-07 22:28:08 -06:00
wsproxy.py wsproxy, wstelnet: wrap command, WS telnet client. 2011-01-12 13:15:11 -06:00
wstelnet.html wsproxy, wstelnet: wrap command, WS telnet client. 2011-01-12 13:15:11 -06:00
wstelnet.js wsproxy, wstelnet: wrap command, WS telnet client. 2011-01-12 13:15:11 -06:00
wstest.html wswrapper: add dup2, fix select w/ NULL timeout. 2011-01-08 21:46:36 -06:00
wstest.py wsproxy, wstelnet: wrap command, WS telnet client. 2011-01-12 13:15:11 -06:00
wswrap wswrapper: fix preload path and interpose port. 2010-12-16 14:04:16 -06:00
wswrapper.c wsproxy, wstelnet: wrap command, WS telnet client. 2011-01-12 13:15:11 -06:00
wswrapper.h wsproxy, wstelnet: wrap command, WS telnet client. 2011-01-12 13:15:11 -06:00

README.md

WebSockets Proxy

wsproxy

At the most basic level, wsproxy just translates WebSockets traffic to normal socket traffic. wsproxy accepts the WebSockets handshake, parses it, and then begins forwarding traffic between the client and the target in both directions. WebSockets payload data is UTF-8 encoded so in order to transport binary data it must use an encoding that can be encapsulated within UTF-8. wsproxy uses base64 to encode all traffic to and from the client. Also, WebSockets traffic starts with '\0' (0) and ends with '\xff' (255). Some buffering is done in case the data from the client is not a full WebSockets frame (i.e. does not end in 255).

Additional wsproxy features

These are not necessary for the basic operation.

  • Daemonizing: When the -D option is specified, wsproxy runs in the background as a daemon process.

  • SSL (the wss:// WebSockets URI): This is detected automatically by wsproxy by sniffing the first byte sent from the client and then wrapping the socket if the data starts with '\x16' or '\x80' (indicating SSL).

  • Flash security policy: wsproxy detects flash security policy requests (again by sniffing the first packet) and answers with an appropriate flash security policy response (and then closes the port). This means no separate flash security policy server is needed for supporting the flash WebSockets fallback emulator.

  • Session recording: This feature that allows recording of the traffic sent and received from the client to a file using the --record option.

  • Mini-webserver: wsproxy can detect and respond to normal web requests on the same port as the WebSockets proxy and Flash security policy. This functionality is activate with the --web DIR option where DIR is the root of the web directory to serve.

  • Wrap a program: see the "Wrap a Program" section below.

Implementations of wsproxy

There are three implementations of wsproxy: python, C, and Node (node.js). wswrapper is only implemented in C.

Here is the feature support matrix for the the wsproxy implementations:

Program Language Multiprocess Daemonize SSL/wss Flash Policy Server Session Record Web Server Program Wrap
wsproxy.py python yes yes yes 1 yes yes yes yes
wsproxy C yes yes yes yes no no no
wsproxy.js Node (node.js) yes no no no no no no
  • Note 1: to use SSL/wss with python 2.5 or older, see the following section on Building the Python ssl module.

Wrap a Program

In addition to proxying from a source address to a target address (which may be on a different system), wsproxy has the ability to launch a program on the local system and proxy WebSockets traffic to a normal TCP port owned/bound by the program.

The is accomplished with a small LD_PRELOAD library (rebind.so) which intercepts bind() system calls by the program. The specified port is moved to a new localhost/loopback free high port. wsproxy then proxies WebSockets traffic directed to the original port to the new (moved) port of the program.

The program wrap mode is invoked by replacing the target with -- followed by the program command line to wrap.

`./utils/wsproxy.py 2023 -- PROGRAM ARGS`

The --wrap-mode option can be used to indicate what action to take when the wrapped program exits or daemonizes.

Here is an example of using wsproxy to wrap the vncserver command (which backgrounds itself):

`./utils/wsproxy.py 5901 --wrap-mode=ignore -- vncserver -geometry 1024x768 :1`

Here is an example of wrapping telnetd (from krb5-telnetd).telnetd exits after the connection closes so the wrap mode is set to respawn the command:

`sudo ./utils/wsproxy.py 2023 --wrap-mode=respawn -- telnetd -debug 2023`

The utils/wstelnet.html page demonstrates a simple WebSockets based telnet client.

Building the Python ssl module (for python 2.5 and older)

  • Install the build dependencies. On Ubuntu use this command:

    sudo aptitude install python-dev bluetooth-dev

  • Download, build the ssl module and symlink to it:

    cd noVNC/utils

    wget http://pypi.python.org/packages/source/s/ssl/ssl-1.15.tar.gz

    tar xvzf ssl-1.15.tar.gz

    cd ssl-1.15

    make

    cd ../

    ln -sf ssl-1.15/build/lib.linux-*/ssl ssl