Giter VIP home page Giter VIP logo

ocproxy's Introduction

ocproxy

ocproxy is a user-level SOCKS and port forwarding proxy for OpenConnect based on lwIP. When using ocproxy, OpenConnect only handles network activity that the user specifically asks to proxy, so the VPN interface no longer "hijacks" all network traffic on the host.

Basic usage

Commonly used options include:

  -D port                   Set up a SOCKS5 server on PORT
  -L lport:rhost:rport      Connections to localhost:LPORT will be redirected
                            over the VPN to RHOST:RPORT
  -g                        Allow non-local clients.
  -k interval               Send TCP keepalive every INTERVAL seconds, to
                            prevent connection timeouts

ocproxy should not be run directly. Instead, it should be started by openconnect using the --script-tun option:

openconnect --script-tun --script \
    "./ocproxy -L 2222:unix-host:22 -L 3389:win-host:3389 -D 11080" \
    vpn.example.com

Once ocproxy is running, connections can be established over the VPN link by connecting directly to a forwarded port or by utilizing the builtin SOCKS server:

ssh -p2222 localhost
rdesktop localhost
socksify ssh unix-host
tsocks ssh 172.16.1.2
...

OpenConnect can (and should) be run as a non-root user when using ocproxy.

Using the SOCKS5 proxy

tsocks, Dante, or similar wrappers can be used with non-SOCKS-aware applications.

Sample tsocks.conf (no DNS):

server = 127.0.0.1
server_type = 5
server_port = 11080

Sample socks.conf for Dante (DNS lookups via SOCKS5 "DOMAIN" addresses):

resolveprotocol: fake
route {
        from: 0.0.0.0/0 to: 0.0.0.0/0 via: 127.0.0.1 port = 11080
        command: connect
        proxyprotocol: socks_v5
}

FoxyProxy can be used to tunnel Firefox or Chrome browsing through the SOCKS5 server. This will send DNS queries through the VPN connection, and unqualified internal hostnames (e.g. http://intranet/) should work. FoxyProxy also allows the user to route requests based on URL patterns, so that (for instance) certain domains always use the proxy server but all other traffic connects directly.

It is possible to start several different instances of Firefox, each with its own separate profile (and hence, proxy settings):

# initial setup
firefox -no-remote -ProfileManager

# run with previous configured profile "vpn"
firefox -no-remote -P vpn

Building ocproxy

Dependencies:

  • libevent >= 2.0: *.so library and headers
  • autoconf
  • automake
  • gcc, binutils, make, etc.

Building from git:

./autogen.sh
./configure
make

Other possible uses for ocproxy

  • Routing traffic from different applications/browsers through different VPNs (or no VPN)
  • Connecting to multiple VPNs or sites concurrently, even if their IP ranges overlap or their DNS settings are incompatible
  • Situations in which root access is unavailable or undesirable; multiuser systems

It is possible to write a proxy autoconfig (PAC) script that decides whether each request should use ocproxy or a direct connection, based on the domain or other criteria.

ocproxy also works with OpenVPN; the necessary patches are posted here.

Network configuration

ocproxy normally reads its network configuration from the following environment variables set by OpenConnect:

  • INTERNAL_IP4_ADDRESS: IPv4 address
  • INTERNAL_IP4_MTU: interface MTU
  • INTERNAL_IP4_DNS: DNS server list (optional but recommended)
  • CISCO_DEF_DOMAIN: default domain name (optional)

The VPNFD environment variable tells ocproxy which file descriptor is used to pass the tunneled traffic.

vpnns (experimental)

Another approach to solving this problem is to create a separate network namespace (netns). This is supported by Linux kernels >= v3.8.

This starts up an application in a fresh user/net/uts/mount namespace:

vpnns -- google-chrome --user-data-dir=/tmp/vpntest

vpnns -- firefox -no-remote -P vpn

vpnns -- transmission-gtk

Initially it will not have any network access as the only interface present in the netns is the loopback device. The application should still be able to talk to Xorg through UNIX sockets in /tmp.

The next step is to connect to a VPN and invoke vpnns --attach to pass the VPN traffic back and forth:

openconnect --script "vpnns --attach" --script-tun vpn.example.com

openvpn --script-security 2 --config example.ovpn \
        --dev "|HOME=$HOME vpnns --attach"

These commands connect to an ocserv or openvpn gateway, then tell vpnns to set up a tunnel device, default route, and resolv.conf inside the namespace created above. On success, the web browser will have connectivity. When the VPN disconnects, the browser will lose all connectivity, preventing leaks.

vpnns can be rerun multiple times if the connection fails or if the VPN client crashes. If run without arguments, it will open a shell inside the namespace.

Some differences between vpnns and ocproxy:

  • No proxies are involved, so apps should not require any special configuration.
  • vpnns is better-suited for hard-to-proxy protocols such as VOIP or BitTorrent.
  • vpnns will only ever run on Linux.
  • vpnns may interfere with dbus connections.

Unlike previous approaches to the problem (e.g. anything that involves running ip netns), vpnns does not require root privileges or changing the host network configuration.

The --name option allows additional (and separate) namespaces to be created.

If your X server is a version that uses abstract sockets only (and UNIX sockets in /tmp are disabled), you can re-enable UNIX sockets by adding -listen unix to /etc/X11/xinit/xserverrc.

The OpenVPN example requires out-of-tree patches. Updated openvpn and ocproxy packages are available for Ubuntu 14.04 LTS and 16.04 LTS:

sudo -s
apt-get install software-properties-common
add-apt-repository --yes ppa:cernekee
apt-get update
apt-get install ocproxy openvpn

Credits

Original author: David Edmondson <[email protected]>

Current maintainer: Kevin Cernekee <[email protected]>

Project home page: https://github.com/cernekee/ocproxy

ocproxy's People

Contributors

cernekee avatar codido avatar dme avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ocproxy's Issues

udp associate support

It appears that UDP connections over ocproxy aren't supported, looking at the code, it appears to be intentional. Curious how straightforward this would be to add. If it's expected to be straightforward, but not something anyone else needs, I could have a go at trying to add support and submitting a PR for it.

Thanks!

Fedora and EPEL

Hi,
thanks for this nice util.
FYI I've built a package in the official Fedora and EPEL (*) repositories.
Regards.

(*) EPEL is an addon repository for RHEL (Red Hat Enterprise Linux).

Corrupt git repo?

% git clone https://github.com/cernekee/ocproxy.git
Cloning into 'ocproxy'...
remote: Counting objects: 1689, done.
remote: Total 1689 (delta 0), reused 0 (delta 0), pack-reused 1689
Receiving objects: 100% (1689/1689), 1.83 MiB | 224.00 KiB/s, done.
Resolving deltas: 100% (641/641), done.
Checking connectivity... done.
warning: remote HEAD refers to nonexistent ref, unable to checkout.

mirror openvpn patches

Hi,

I'm interested in implementing a package for nixos, but cannot find your patchset for openvpn.

Can you mirror the patchset here please?

Thanks,
s1341

warning: lwip_data_cb: could not allocate pbuf

Hi all.

When I run ocproxy on openconnect, after a while connections stop routing and this log appears in stdout:

warning: lwip_data_cb: could not allocate pbuf

what this means and how can I increase buffers to solve this problem?

Thank in advance.

Using vpnns for ssh?

I'm on Fedora 32 (kernel 5.6.19-300.fc32.x86_64). When I try running ssh through vpnns, I get the following message:

$ vpnns --name vpnname -- ssh user@hostname
Bad owner or permissions on /etc/ssh/ssh_config.d/50-redhat.conf

The process then exits immediately with status code 0.


I would ideally like to use vpnns, but even using ocproxy I'm having problems. In fact I can't get ocproxy to work at all for anything, whereas vpnns seems to work for everything but ssh.

With ocproxy, I'm running it like openconnect --script-tun --script "ocproxy -L 2222:hostname:22" vpngateway --protocol=gp.
When I connect via ssh -p2222 user@localhost, it just hangs. Running ssh in verbose mode ends in the following:

[...]
debug1: Connecting to localhost [127.0.0.1] port 2222.
debug1: Connection established.
debug1: identity file /home/ben/.ssh/id_rsa type -1
debug1: identity file /home/ben/.ssh/id_rsa-cert type -1
debug1: identity file /home/ben/.ssh/id_dsa type -1
debug1: identity file /home/ben/.ssh/id_dsa-cert type -1
debug1: identity file /home/ben/.ssh/id_ecdsa type -1
debug1: identity file /home/ben/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/ben/.ssh/id_ecdsa_sk type -1
debug1: identity file /home/ben/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /home/ben/.ssh/id_ed25519 type -1
debug1: identity file /home/ben/.ssh/id_ed25519-cert type -1
debug1: identity file /home/ben/.ssh/id_ed25519_sk type -1
debug1: identity file /home/ben/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /home/ben/.ssh/id_xmss type -1
debug1: identity file /home/ben/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.3
[hangs indefinitely until I stop openconnect]

Adding the -v flag to ocproxy doesn't seem to give any more info.

Similar hanging behavior occurs when I try forwarding the address of an http server (-L 8888:hostname:80) and trying to open localhost:8888 it in firefox. In this case, I am actually able to get it to work with vpnns though when I start a new instance of firefox under vpnns.


Any suggestions you can give as to how to use ssh with ocproxy/vpnns would be greatly appreciated.

Failed to write incoming packet: No buffer space available

Hello,

I am using ocproxy to redirect via -L several ports from my internal network. Unfortunately, if I stress connection, I keep getting these errors:

Failed to write incoming packet: No buffer space available

Is there any workaround for them?

Follow XDG specification for ~/.vpnns-NAME

This is a very simple request, and should be pretty easy to implement, but could vpnns use the XDG Base Directory Specification for where it puts its state files? I think it would be as simple as replacing getenv("HOME") in

if (asprintf(&statedir, "%s/.vpnns-%s", getenv("HOME"), name) < 0)

with

	char* state_home = getenv("XDG_STATE_HOME");
	if (!state_home || strlen(state_home) == 0) {
		state_home = getenv("HOME");
		strncat(state_home, "/.local/state",
			sizeof(state_home) - strlen(state_home) - 1);
	}
	if (asprintf(&statedir, "%s/.vpnns-%s", getenv("HOME"), name) < 0)

Note that this might be improved as I haven't really done any serious projects in C before, but this takes into account the cases where the variable is set to the empty string as well.

Port forwarding to M:localhost:N does not work

A typical port forwarding pattern with ssh is something like ssh -L 8080:localhost:80 to access a service running on the remote machine itself.

This does not work with ocproxy -L 2222:localhost:22, where the openconnect server provides ssh access. However, specifying the server's localnet IP address does work, e.g. ocproxy -L 2222:192.168.1.1:22.

At a minimum it would be helpful to document this exception to commonly expected behavior.

At a stretch, maybe automatically replace localhost with INTERNAL_IP4_ADDRESS?

add possibility of bind address for dynamic forward option

ssh have optional bind address for dynamic forward:
" -D [bind_address:]port" (from ssh manual)
in ocproxy we can only specify the port:
"-D, --dynfw port" (from oc proxy manual)
I tried using openssh syntax with "-D 127.123.123.123:1080" but got the following error:
invalid integer: '127.123.123.123:1080'

since ocproxy tries to mimic openssh syntax and features, this one would be a nice to have for people who are simultaneously connected to several vpns, tunnels etc.

download incomplete file

When I use ocproxy with this config openconnect --script-tun --script "ocproxy -v -g -D 51501" URL, webpages load incomplete and files like PDF don't download completely. For example I will receive 40KB of 2MB files!

Use of '-g' option

Hi there,

I've started using ocproxy to connect to a server (B) through another one (A) on which I need to run a vpn, it works like a charm, thanks so much!

I've been wondering how to use the option for non-local clients:

  -g                        Allow non-local clients.

I'm wondering if that means I could directly connect to B by selecting the port correctly when ssh-ing into A, instead of first connecting to A, then ssh-ing into the local forwarding port? So far I haven't been able to do it.

In my example, I do it like so:

openconnect --script-tun --script \
    "ocproxy -L 2222:$IP_B:22 -D 11080 -v -g"  vpn.example.com

And then I can do, while inside A:

ssh user@localhost -p2222

However, if I try this from the outside:

ssh user@A -p2222

I get a connection refused. Is there a way to ssh straight into this specific port from my machine?

Thanks!

Support for tunnel IPv6 addresses

My tunnel provider ($DAYJOB) has started to supply IPv6 addresses for the tunnel. ocproxy should be able to configure the lwip IPv6 stack accordingly.

vpsn browser

hello

is there all in one extension for openconnect server using browser base vpn can connect with all os browser support ? or any guidance for all browser os i will integraiton rest api login and then connect

Support for multiple DNS server IP addresses

At the moment ocproxy just takes the first IP address it is given and ignores any others.

We had an issue recently where the first DNS server was not working, and anyone using ocproxy couldn’t use the VPN until it was fixed, whereas people using open connect ‘natively’ failed over to the second server.

I know DNS servers can be specified manually, but it would be good if ocproxy could fallback to the other servers provided.

network throughput significantly reduced

I compared the download of a file with AnyConnect, OpenConnect and OpenConnect w/ocproxy.

AnyConnect and OpenConnect were comparable, but ocproxy was taking 10x as long. Is this a known issue with OpenConnect or specific to ocproxy? I've been digging around trying to implement a comparable script to ocproxy to debug this, but haven't had any luck making the initial handshake.

Thanks

Windows

Do you know if I can use it on Windows?

script is run up , but socks5 proxy is not ok

echo xxxxxxx | openconnect --user=xxxxxxxxxx --script-tun --script "ocproxy  -D 11080" host

After start openconnect, ocproxy is runing, sock5 proxy could telnet, but could not connect to internet.

The /tmp/tcpdump is like below:

10.3.180.233.49153 > 8.8.8.8.53: U  52
10.3.180.233.49153 > 8.8.8.8.53: U  44
10.3.180.233.49153 > 8.8.8.8.53: U  46
10.3.180.233.49153 > 8.8.8.8.53: U  35
10.3.180.233.49153 > 8.8.8.8.53: U  44
10.3.180.233.49153 > 8.8.8.8.53: U  46
10.3.180.233.49153 > 8.8.8.8.53: U  39
10.3.180.233.49153 > 8.8.8.8.53: U  52
10.3.180.233.49153 > 8.8.8.8.53: U  46
10.3.180.233.49153 > 8.8.8.8.53: U  46
10.3.180.233.49153 > 8.8.8.8.53: U  46
10.3.180.233.49153 > 8.8.8.8.53: U  44
10.3.180.233.49153 > 8.8.8.8.53: U  46
10.3.180.233.49153 > 8.8.8.8.53: U  46
10.3.180.233.49153 > 8.8.8.8.53: U  46
10.3.180.233.49153 > 8.8.8.8.53: U  46
10.3.180.233.49153 > 8.8.8.8.53: U  46
10.3.180.233.49153 > 8.8.8.8.53: U  46

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.