项目作者: AdrianVollmer

项目描述 :
htun tunnels IP traffic transparently over HTTP or TCP
高级语言: Python
项目地址: git://github.com/AdrianVollmer/htun.git
创建时间: 2018-09-09T12:29:59Z
项目社区:https://github.com/AdrianVollmer/htun

开源协议:MIT License

下载


htun

htun is a transparent tunnel for transporting IP traffic over HTTP or TCP.

It was developed with situations in mind where traffic to the internet is
restricted. For instance, some networks don’t allow traffic to the internet
at all and require you to go through an HTTP proxy. htun enables you to get
full internet access in those situations (all ports, all protocols). It also
supports using a SOCKS proxy.

Obviously, performance takes a huge hit. So it is meant for some light
browsing or downloading small files sporadically. Expect transfer rates to
be cut by a factor of up to 100.

Also, it is not encrypted by default. It is recommended to put another
tunnel on top, such as Wireguard.

Since python-pytun is required, which is a non-portable module, this will
only run on Linux.

Requirements

To run htun, you need Python3 and the following modules:

  • urllib3==1.24
  • python_pytun==2.2.1
  • pytun==1.0.1
  • SocksiPy_branch==1.01

Recommended:

  • hexdump==3.3

Usage

The script needs to be run with root privileges both on the server and the
client. On the server, run:

  1. ./htun.py --server

On the client, run:

  1. ./htun.py --uri <SERVER URI>

By default, it uses HTTP on port 80 and the IP addresses 10.13.37.1 and
10.13.37.2 for the client and the server, respectively.

For all options, run ./htun.py --help:

  1. usage: htun.py [-h] [--debug] [--client-addr CADDR] [--server-addr SADDR]
  2. [--tun-netmask TMASK] [--tun-mtu TMTU] [--tun-timeout TIMEOUT]
  3. [--route-subnet RSUBNET] [--proxy PROXY] [--username USERNAME]
  4. [--password PASSWORD] [--listen-port LPORT] [--bind-ip BINDIP]
  5. (--server [{http,tcp}] | --uri URI)
  6. htun tunnels IP traffic transparently over HTTP or TCP (author: Adrian
  7. Vollmer)
  8. optional arguments:
  9. -h, --help show this help message and exit
  10. --debug, -d debug flag to true (default: False)
  11. --client-addr CADDR, -c CADDR
  12. tunnel local address (default: 10.13.37.1)
  13. --server-addr SADDR, -s SADDR
  14. tunnel destination address (default: 10.13.37.2)
  15. --tun-netmask TMASK, -m TMASK
  16. tunnel netmask (default: 255.255.255.0)
  17. --tun-mtu TMTU tunnel MTU (default: 1500)
  18. --tun-timeout TIMEOUT
  19. r/w timeout in seconds (default: 1)
  20. --route-subnet RSUBNET, -n RSUBNET
  21. subnet to be routed via tunnel (default: None)
  22. --proxy PROXY, -P PROXY
  23. proxy URI (<proto>://<host>:<port>) (default: None)
  24. --username USERNAME, -u USERNAME
  25. username for HTTP proxy basic authentication (default:
  26. None)
  27. --password PASSWORD, -W PASSWORD
  28. password for HTTP proxy basic authentication (default:
  29. None)
  30. --listen-port LPORT, -p LPORT
  31. listen port of the server component (default: 80)
  32. --bind-ip BINDIP, -b BINDIP
  33. bind IP address of the server component (default:
  34. 0.0.0.0)
  35. --server [SERVER] local port and bind address (http, tcp)
  36. (default: http)
  37. --uri URI remote URI (<proto>://<host>[:<port>]) (default: None)

Examples

TCP Tunnel

To use a TCP tunnel on port 443, run

  1. ./htun.py --server tcp -p 443

on the server side and

  1. ./htun.py --uri tcp://<host>:443

on the client side. Now the client can reach the server via the IP address
10.13.37.2

SOCKS Proxy

To use HTTP over a SOCKS5 proxy on port 5000, run

  1. ./htun.py --server

on the server side and

  1. ./htun.py --uri http://<host> --proxy socks5://<proxy-host>:5000

on the client side.

Proxy Authentication

Proxies using basic authentication are supported (but yet untested).

A proxy requiring NTLM authentication is not supported because
python-urllib3 does not support NTLM. It is suggested to use cntlm as an
additional SOCKS proxy.

Performance

Performance over a TCP tunnel is much better than over an HTTP tunnel.
Expect several orders of magnitude in degradation of the connection when
using HTTP.

Example downloading 713k bytes without the tunnel:

  1. $ curl https://example.com/example.png > /dev/null
  2. % Total % Received % Xferd Average Speed Time Time Time Current
  3. Dload Upload Total Spent Left Speed
  4. 100 713k 100 713k 0 0 2680k 0 --:--:-- --:--:-- --:--:-- 2680k

Downloading the same file with an HTTP tunnel:

  1. $ curl https://example.com/example.png > /dev/null
  2. % Total % Received % Xferd Average Speed Time Time Time Current
  3. Dload Upload Total Spent Left Speed
  4. 100 713k 100 713k 0 0 12177 0 0:00:59 0:00:59 --:--:-- 16590

With a TCP tunnel it’s at least around 3% of the original speed:

  1. $ curl https://example.com/example.png > /dev/null
  2. % Total % Received % Xferd Average Speed Time Time Time Current
  3. Dload Upload Total Spent Left Speed
  4. 100 713k 100 713k 0 0 37640 0 0:00:19 0:00:19 --:--:-- 41086

To do

  • Make performance improvements when using HTTP
  • Experiment with threaded requests

Disclaimer

Keep in mind that the administrator of the network most likely did not want
you to bypass the restriction that were set up. The restriction is probably
there for a reason and you need to respect that. Using this tool may violate
terms and conditions or company rules and may possibly even get you in legal
trouble and/or fired from your job.

Use this only if you know that you have permission to use it by everyone
involved.

Author

Adrian Vollmer, 2018