udp2raw/README.md

180 lines
8.8 KiB
Markdown
Raw Normal View History

2017-08-05 13:48:55 +00:00
# Udp2raw-tunnel
2017-08-08 01:54:55 +00:00
![image0](images/image0.PNG)
2017-07-14 14:01:34 +00:00
2017-08-11 12:36:37 +00:00
An encrpyted, anti-replay, multiplexing UDP tunnel which tunnels UDP traffic with fake TCP or ICMP header using raw socket. Also acts as a connection stablizer.
[简体中文](/doc/README.zh-cn.md)
2017-08-11 09:25:14 +00:00
# Features
2017-08-11 12:36:37 +00:00
### Send / Receive UDP Packet with fake headers
Fake headers help you bypass UDP blocking, UDP QOS or improper UDP NAT behavior on some ISPs. Raw packets with UDP headers are also supported, where you can just use the encrpyting and anti-replay feature.
2017-08-11 09:39:46 +00:00
2017-08-11 12:36:37 +00:00
### Simulate TCP Handshake
Simulates the 3-way handshake, along with seq and ack_seq. TCP options MSS, sackOk, TS, TS_ack, wscale are also simulated. Real-time delivery guaranteed, no TCP over TCP problem when using OpenVPN.
2017-08-11 09:39:46 +00:00
2017-08-11 12:36:37 +00:00
### Encrpytion, Anti-Replay, Anti-MITM
* Encrypt your traffic with AES-128-CBC.
* Protect data integrity by MD5 or CRC32.
* Defense replay attack with an anti-replay window, smiliar to IPSec and OpenVPN.
* Authenticate mutually, no more MITM attacks.
### Failure Dectection & Stablization (Connection Recovery)
Conection failures are detected by heartbeats. If timed-out, the client will automatically change the port number and reconnect. If reconnection is successful, the previous connection will be recovered, and all existing UDP conversations will stay vaild.
For example, if you use UDP2RAW + OpenVPN, OpenVPN won't lose connection after any reconnect, **even if the network cable is re-plugged or the WiFi access point is changed**.
2017-08-11 08:52:29 +00:00
2017-08-05 14:06:39 +00:00
### Other Features
2017-08-11 12:36:37 +00:00
* **Multiplexing** One client can handle multiple UDP connections, all of which share the same raw connection.
* **Multiple Clients** One server can have multiple clients.
2017-07-14 14:01:34 +00:00
2017-08-11 12:36:37 +00:00
* **NAT Support** All of the 3 modes work in NAT-ed environments.
2017-08-05 13:48:55 +00:00
2017-08-11 12:36:37 +00:00
* **OpenVZ Support** Tested on BandwagonHost.
2017-08-05 13:48:55 +00:00
2017-08-11 12:36:37 +00:00
* **OpenWRT Support** No dependencies, easy to build. Binary for ar71xx are included in release.
### Keywords
* UDP QoS Bypass
* UDP Blocking Bypass
* OpenVPN TCP over TCP problem
* OpenVPN over ICMP
* UDP to ICMP tunnel
* UDP to TCP tunnel
* UDP over ICMP
* UDP over TCP
2017-08-05 13:48:55 +00:00
2017-08-05 14:06:39 +00:00
# Getting Started
2017-08-05 13:48:55 +00:00
### Prerequisites
2017-08-11 12:36:37 +00:00
A Linux host (including desktop Linux, OpenWRT router, or Raspberry PI) with root access.
If you want to use it on MICRO$OFT Windows, you can use VMware or Hyper-V (both bridged mode and NAT mode are supported).
2017-08-05 13:48:55 +00:00
### Installing
2017-08-11 12:36:37 +00:00
Download binary release from https://github.com/wangyu-/udp2raw-tunnel/releases
2017-08-05 13:48:55 +00:00
### Running
2017-08-11 12:36:37 +00:00
Assume your UDP is blocked or being QOS-ed or just poorly supported. Assume your server ip is 44.55.66.77, you have a service listening on udp port 7777.
```bash
# Run at client side
2017-08-05 14:06:39 +00:00
./udp2raw_amd64 -c -l0.0.0.0:3333 -r44.55.66.77:4096 -a -k "passwd" --raw-mode faketcp
2017-08-11 12:36:37 +00:00
# Run at server side:
2017-08-05 14:06:39 +00:00
./udp2raw_amd64 -s -l0.0.0.0:4096 -r 127.0.0.1:7777 -a -k "passwd" --raw-mode faketcp
```
2017-08-11 12:36:37 +00:00
Now, the client and the server have established a tunnel through TCP port 4096. Connecting to UDP port 3333 at the client side is equivalent to connecting to port 7777 at the server side. No UDP traffic will be exposed.
2017-08-05 14:06:39 +00:00
# Advanced Topic
### Usage
2017-08-05 13:48:55 +00:00
```
2017-08-05 14:06:39 +00:00
udp2raw-tunnel
version: Aug 5 2017 21:03:54
repository: https://github.com/wangyu-/udp2raw-tunnel
2017-07-14 14:01:53 +00:00
2017-08-05 14:06:39 +00:00
usage:
run as client : ./this_program -c -l local_listen_ip:local_port -r server_ip:server_port [options]
run as server : ./this_program -s -l server_listen_ip:server_port -r remote_ip:remote_port [options]
2017-07-14 14:01:34 +00:00
2017-08-05 14:06:39 +00:00
common options,these options must be same on both side:
--raw-mode <string> avaliable values:faketcp(default),udp,icmp
-k,--key <string> password to gen symetric key,default:"secret key"
--auth-mode <string> avaliable values:aes128cbc(default),xor,none
--cipher-mode <string> avaliable values:md5(default),crc32,simple,none
-a,--auto-rule auto add (and delete) iptables rule
-g,--gen-rule generate iptables rule then exit
--disable-anti-replay disable anti-replay,not suggested
client options:
--source-ip <ip> force source-ip for raw socket
--source-port <port> force source-port for raw socket,tcp/udp only
this option disables port changing while re-connecting
other options:
--log-level <number> 0:never 1:fatal 2:error 3:warn
4:info (default) 5:debug 6:trace
--log-position enable file name,function name,line number in log
--disable-color disable log color
--disable-bpf disable the kernel space filter,most time its not necessary
unless you suspect there is a bug
--sock-buf <number> buf size for socket,>=10 and <=10240,unit:kbyte,default:1024
--seqmode <number> seq increase mode for faketcp:
0:dont increase
1:increase every packet
2:increase randomly, about every 3 packets (default)
-h,--help print this help message
2017-08-05 13:48:55 +00:00
```
2017-08-11 12:36:37 +00:00
### IPTABLES rule
This program sends packets via raw socket. In FakeTCP mode, Linux kernel TCP packet processing has to be blocked by a iptables rule on both sides, otherwise the kernel will automatically send RST for an unrecongized TCP packet and you will sustain from stability / peformance problems. You can use `-a` option to let the program automatically add / delete iptables rule on start / exit. You can also use the -g option to generate iptables rule and add it manually.
### `cipher-mode` and `auth-mode`
It is suggested to use AES-128-CBC + MD5 to obtain maximum security. If you want to run the program on a router, you can try XOR + simple, which can fool packet inspection by firewalls the most of time, but it cannot protect you from serious attacks. Mode none is only for debugging purpose. It is not recommended to set the cipher-mode or auth-mode to none.
2017-08-05 14:06:39 +00:00
### seq-mode
2017-08-11 12:36:37 +00:00
The FakeTCP mode does not behave 100% like a real tcp connection. ISPs may be able to distinguish the simulated tcp traffic from the real TCP traffic (though it's costly). seq-mode can help you change the seq increase behavior slightly. If you experience any problems, try to change the value.
2017-08-05 14:06:39 +00:00
# Peformance Test
2017-08-11 12:36:37 +00:00
#### Test method:
iperf3 TCP via OpenVPN + udp2raw
(iperf3 UDP mode is not used because of a bug mentioned in this issue: https://github.com/esnet/iperf/issues/296 . Instead, we package the TCP traffic into UDP by OpenVPN to test the performance. Read [Application](https://github.com/wangyu-/udp2raw-tunnel#application) for details.
2017-08-05 14:06:39 +00:00
#### iperf3 command:
```
iperf3 -c 10.222.2.1 -P40
iperf3 -c 10.222.2.1 -P40 -R
```
2017-08-11 12:36:37 +00:00
#### Environments
* **Client** Vultr $2.5/monthly plan (single core 2.4GHz cpu, 512MB RAM, Tokyo, Japan)
* **Server** BandwagonHost $3.99/annually plan (single core 2.0GHz cpu, 128MB RAM, Los Angeles, USA)
2017-08-05 14:06:39 +00:00
### Test1
2017-08-06 06:11:36 +00:00
raw_mode: faketcp cipher_mode: xor  auth_mode: simple
2017-08-05 14:06:39 +00:00
![image4](images/image4.PNG)
(reverse speed is simliar and not uploaded)
### Test2
2017-08-06 06:11:36 +00:00
raw_mode: faketcp cipher_mode: aes128cbc  auth_mode: md5
2017-08-05 14:06:39 +00:00
![image5](images/image5.PNG)
(reverse speed is simliar and not uploaded)
# Application
### tunneling any traffic via raw traffic by using udp2raw +openvpn
![image_vpn](images/openvpn.PNG)
1. bypasses UDP block/UDP QOS
2017-08-07 02:33:25 +00:00
2. no TCP ovr tcp problem (tcp over tcp problem http://sites.inka.de/bigred/devel/tcp-tcp.html ,https://community.openvpn.net/openvpn/ticket/2 )
2017-08-05 14:06:39 +00:00
3. openvpn over icmp also becomes a choice
2017-08-07 05:58:42 +00:00
more details at [openvpn+udp2raw_guide](/doc/openvpn_guide.md)
2017-08-11 06:31:42 +00:00
### speed-up tcp connection via raw traffic by using udp2raw+kcptun
2017-08-11 05:53:01 +00:00
kcptun is a tcp connection speed-up program,it speeds-up tcp connection by using kcp protocol on-top of udp.by using udp2raw,you can use kcptun while udp is QoSed or blocked.
2017-08-05 14:06:39 +00:00
(kcptun, https://github.com/xtaci/kcptun)
2017-08-11 06:31:42 +00:00
### speed-up tcp connection via raw traffic by using udp2raw+finalspeed
finalspeed is a tcp connection speed-up program similiar to kcptun,it speeds-up tcp connection by using kcp protocol on-top of udp or tcp.but its tcp mode doesnt support openvz,you can bypass this problem if you use udp2raw+finalspeed together,and icmp mode also becomes avaliable.
2017-08-05 14:06:39 +00:00
2017-08-11 08:33:20 +00:00
# How to build
2017-08-11 08:32:55 +00:00
read [build_guide](/doc/build_guide.md)
2017-08-05 14:06:39 +00:00
# Related work
### kcptun-raw
this project was inspired by kcptun-raw,which modified kcptun to support tcp mode.
https://github.com/Chion82/kcptun-raw
### kcpraw
another project of kcptun with tcp mode
https://github.com/ccsexyz/kcpraw
### relayRawSocket
a simple udp to raw tunnel without simluated 3-way handshake ,wrote in python
https://github.com/linhua55/some_kcptun_tools/tree/master/relayRawSocket
### icmptunnel
Transparently tunnel your IP traffic through ICMP echo and reply packets.
https://github.com/DhavalKapil/icmptunnel