Compare commits

..

98 Commits

Author SHA1 Message Date
wangyu
fb5546f83b Merge branch 'master' of https://github.com/wangyu-/udp2raw-tunnel 2017-08-15 15:48:42 +08:00
wangyu
bb67509179 added lower-level option in help page 2017-08-15 15:48:19 +08:00
wangyu-
4bc4d618db Update README.zh-cn.md 2017-08-14 23:04:51 -07:00
wangyu
9f4c452cf6 Merge branch 'master' of https://github.com/wangyu-/udp2raw-tunnel 2017-08-15 13:04:55 +08:00
wangyu
455dcc1e84 trival 2017-08-15 13:04:21 +08:00
wangyu
cee22ec3dc zero out every sockaddr 2017-08-15 13:03:22 +08:00
wangyu-
0612b73e7e Update README.md 2017-08-14 05:32:54 -07:00
wangyu-
84697a35c9 Update README.md 2017-08-14 05:29:52 -07:00
wangyu-
78bf036e04 Update README.zh-cn.md 2017-08-14 05:24:00 -07:00
wangyu-
3ee73b048e Update README.md 2017-08-14 04:03:57 -07:00
wangyu-
8220cf30fb Update README.zh-cn.md 2017-08-14 03:50:34 -07:00
wangyu-
a061af0b89 Update README.zh-cn.md 2017-08-14 03:44:56 -07:00
wangyu-
746cda08d2 Update README.md 2017-08-14 03:28:31 -07:00
wangyu-
06f5541b2a Update README.zh-cn.md 2017-08-14 03:11:25 -07:00
wangyu-
97b73b06c9 Update README.zh-cn.md 2017-08-14 03:09:36 -07:00
wangyu-
f7319680d9 Update README.zh-cn.md 2017-08-14 03:07:43 -07:00
wangyu-
6dd52326b4 Update README.zh-cn.md 2017-08-14 03:04:16 -07:00
wangyu-
1ebef723bf Update README.zh-cn.md 2017-08-14 02:29:09 -07:00
wangyu-
744bf2dece Update README.zh-cn.md 2017-08-14 00:56:20 -07:00
wangyu-
7538204bd1 Update README.zh-cn.md 2017-08-14 00:54:44 -07:00
wangyu-
ae6dd0b196 Update README.md 2017-08-13 20:32:11 -07:00
wangyu-
fc515c770f Update README.md 2017-08-13 20:31:24 -07:00
wangyu-
491c322148 Update README.md 2017-08-13 07:31:25 -07:00
wangyu
80f1070546 Merge branch 'master' of https://github.com/wangyu-/udp2raw-tunnel 2017-08-13 21:28:05 +08:00
wangyu
5a4e3302e2 added comment about security of zero iv + nonce first data block 2017-08-13 21:27:53 +08:00
wangyu-
e76ad81a04 Update README.zh-cn.md 2017-08-13 05:57:20 -07:00
wangyu
7ac0d3561d improve makefile 2017-08-13 10:30:14 +08:00
wangyu
32166d65ae bug fix 2017-08-13 08:18:23 +08:00
wangyu
2af94823e3 better makefile 2017-08-13 02:14:50 +08:00
root
00a3955de0 Merge branch 'master' of https://github.com/wangyu-/udp2raw-tunnel 2017-08-12 19:21:31 +08:00
root
0266163b12 fixed a makefile problem 2017-08-12 19:21:24 +08:00
wangyu-
df55271c08 Update README.zh-cn.md 2017-08-12 03:56:39 -07:00
wangyu-
facf7e4049 Update README.md 2017-08-12 03:54:20 -07:00
wangyu-
81209ba25e Update README.md 2017-08-12 03:07:22 -07:00
wangyu-
8c833776da Update README.md 2017-08-11 23:36:48 -07:00
wangyu-
aede2a8680 Update README.md 2017-08-11 23:15:54 -07:00
wangyu-
b0636445e3 Update README.md 2017-08-11 22:55:41 -07:00
wangyu-
f8715a1d1d Update README.md 2017-08-11 22:48:04 -07:00
wangyu-
6205aa6b8f Update README.zh-cn.md 2017-08-11 21:46:38 -07:00
wangyu-
ae0509d7d2 Update README.md 2017-08-11 21:44:52 -07:00
wangyu
2fa2666479 make cross2 cross3 2017-08-12 11:36:14 +08:00
wangyu-
fdbf1e082f Update README.md 2017-08-11 17:24:51 -07:00
wangyu
d502de0c7c Merge branch 'master' of https://github.com/wangyu-/udp2raw-tunnel 2017-08-12 07:13:30 +08:00
wangyu
8487d7c624 updated image 2017-08-12 07:12:54 +08:00
wangyu-
83b00e79ad Add files via upload 2017-08-11 08:40:23 -07:00
wangyu-
36ed28064a Create 111 2017-08-11 08:39:43 -07:00
wangyu-
746aefa70a Update README.md 2017-08-11 06:54:39 -07:00
wangyu-
a69cbf23da Merge pull request #4 from t123yh/patch-1
Update README.md
2017-08-11 21:50:00 +08:00
Tian Yunhao
fc4d178657 Update README.md 2017-08-11 20:36:37 +08:00
wangyu-
ccab523ddf Update README.zh-cn.md 2017-08-11 02:46:33 -07:00
wangyu-
4eb72f6139 Update README.md 2017-08-11 02:45:29 -07:00
wangyu-
6296322e22 Update README.zh-cn.md 2017-08-11 02:41:07 -07:00
wangyu-
3a0c512e43 Update README.md 2017-08-11 02:39:46 -07:00
wangyu-
e01d7059ad Update README.zh-cn.md 2017-08-11 02:26:25 -07:00
wangyu-
5e6d977247 Update README.md 2017-08-11 02:25:14 -07:00
wangyu-
c08bd12ea0 Update README.md 2017-08-11 01:55:26 -07:00
wangyu-
ebdb08873a Update README.md 2017-08-11 01:54:39 -07:00
wangyu-
46b0a00b3e Update README.md 2017-08-11 01:53:03 -07:00
wangyu-
d1934dda4c Update README.md 2017-08-11 01:52:29 -07:00
wangyu-
81e599e84c Update README.zh-cn.md 2017-08-11 01:50:25 -07:00
wangyu-
fadf5a25c2 Update README.zh-cn.md 2017-08-11 01:49:56 -07:00
wangyu-
9f25a61dad Update README.md 2017-08-11 01:47:20 -07:00
wangyu-
165dc193f0 Update README.md 2017-08-11 01:45:53 -07:00
wangyu-
e732ce2a8a Update README.md 2017-08-11 01:33:20 -07:00
wangyu-
d7cae0be18 Update README.md 2017-08-11 01:32:55 -07:00
wangyu
c1b8eb23a2 english build_guide 2017-08-11 16:30:22 +08:00
wangyu
1bbe19cdee Merge branch 'master' of https://github.com/wangyu-/udp2raw-tunnel 2017-08-11 16:17:43 +08:00
wangyu
b16b37c879 fixed cmake 2017-08-11 16:17:26 +08:00
wangyu-
9479c95510 Update README.md 2017-08-10 23:49:55 -07:00
wangyu-
90b1897d4a Update README.md 2017-08-10 23:49:24 -07:00
wangyu-
3fa1a99046 Update README.zh-cn.md 2017-08-10 23:47:36 -07:00
wangyu-
eb59012b7b Update README.md 2017-08-10 23:31:42 -07:00
wangyu-
1a2cd767c0 Update README.zh-cn.md 2017-08-10 23:06:34 -07:00
wangyu-
8f04c82788 Update README.md 2017-08-10 22:53:01 -07:00
wangyu-
1b9f2a1e0e Update README.md 2017-08-10 22:51:50 -07:00
wangyu-
7592729abc Update README.md 2017-08-10 22:42:00 -07:00
wangyu
e890a6344c reverted extern c syntax,fixed a makefile problem 2017-08-11 12:25:04 +08:00
wangyu-
bc6358aa0a Merge pull request #3 from BroncoTc/master
merged pull request "add cmake support and fix compile errors“
2017-08-11 11:39:05 +08:00
broncotc
ed6416a30d add cmake support and fix compile errors 2017-08-11 10:45:40 +08:00
wangyu-
9378cee8d1 Update kcptun_step_by_step.md 2017-08-10 08:46:05 -07:00
wangyu-
0b3fb41f6f Update kcptun_step_by_step.md 2017-08-10 08:45:45 -07:00
wangyu-
41489af1d1 Update build_guide.zh-cn.md 2017-08-10 07:15:10 -07:00
wangyu
3a1bacc11e Merge branch 'master' of https://github.com/wangyu-/udp2raw-tunnel 2017-08-10 22:08:18 +08:00
wangyu-
06d7638c5f Update README.zh-cn.md 2017-08-10 07:08:21 -07:00
wangyu
380971fe2b modified makefile 2017-08-10 22:08:09 +08:00
wangyu-
709258b260 Update build_guide.zh-cn.md 2017-08-10 07:04:45 -07:00
wangyu-
c3a8305e49 Update build_guide.zh-cn.md 2017-08-10 07:03:57 -07:00
wangyu-
5c08d65d91 Update build_guide.zh-cn.md 2017-08-10 07:03:38 -07:00
wangyu-
6f9ab92c1d Create build_guide.zh-cn.md 2017-08-10 06:20:51 -07:00
wangyu-
2f57fa6670 Update openvpn_guide.md 2017-08-10 05:39:06 -07:00
wangyu-
d104074328 Update README.zh-cn.md 2017-08-10 03:21:34 -07:00
wangyu-
7c280ab335 Update README.md 2017-08-10 03:20:35 -07:00
wangyu-
eb8567b693 Update README.zh-cn.md 2017-08-10 00:05:47 -07:00
wangyu-
fec382ebab Update README.zh-cn.md 2017-08-09 23:46:03 -07:00
wangyu-
4d319f54ff Update README.zh-cn.md 2017-08-09 23:44:41 -07:00
wangyu-
a58618c73c Update README.zh-cn.md 2017-08-09 23:39:53 -07:00
wangyu-
456da000f4 Update README.zh-cn.md 2017-08-09 23:37:30 -07:00
wangyu-
91e229616c Update README.md 2017-08-09 20:49:44 -07:00
19 changed files with 393 additions and 137 deletions

19
CMakeLists.txt Normal file
View File

@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.7)
project(udp2raw_tunnel)
set(CMAKE_CXX_STANDARD 11)
set_source_files_properties(lib/aes.c lib/md5.c PROPERTIES LANGUAGE CXX )
set(SOURCE_FILES
lib/aes.c
lib/md5.c
common.cpp
encrypt.cpp
log.cpp
main.cpp
network.cpp
)
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -static")
#set(CMAKE_LINK_LIBRARY_FLAG "-lrt")
add_executable(udp2raw_tunnel ${SOURCE_FILES})
target_link_libraries(udp2raw_tunnel rt)

141
README.md
View File

@@ -1,45 +1,70 @@
# Udp2raw-tunnel
![image0](images/image0.PNG)
An Encrpyted,Anti-Replay,Multiplexed Udp Tunnel,tunnels udp traffic through raw socket
A UDP Tunnel which tunnels UDP via FakeTCP/UDP/ICMP Traffic by using Raw Socket,helps you Bypass UDP FireWalls(or Unstable UDP Environment).Its Encrpyted,Anti-Replay and Multiplexed.It aslo acts as a Connection Stablizer.
[简体中文](/doc/README.zh-cn.md)
### Send/Recv Udp Packet as Raw Packet with TCP header,ICMP header
Which can help you bypass udp blocking or udp QOS or just poorly supported udp NAT behavior by some ISP. Raw packet with UDP header is also supported,in this way you can just make use of the encrpyting and anti-replay feature.
### Encrpytion and Anti-Replay
encrypt your traffic with aes128cbc,protects data integrity by md5 or crc32,protect replay attack with an anti-replay window smiliar to ipsec/openvpn.
### Simulated TCP Handshake
simulated 3-way handshake,simluated seq ack_seq. Simluated tcp options:MSS,sackOk,TS,TS_ack,wscale. Provides real-time delivery ,no tcp over tcp problem when using openvpn.
### Connnection Failure Dectection & Recover
Conection failure detection by hearbeat. After hearbeat timeouts,client will auto change port and re-connect.if re-connection is successful,the previous connection will be recovered,and all existed udp conversations will stay vaild.
# Features
### Send / Receive UDP Packet with fake-tcp/icmp headers
Fake-tcp/icmp headers help you bypass UDP blocking, UDP QOS or improper UDP NAT behavior on some ISPs. Raw packets with UDP headers are also supported.In UDP header mode,it behaves just like a normal UDP tunnel,and you can just make use of the other features.
### 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.
### Encrpytion, Anti-Replay, No 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 MITM attacks.
### Failure Dectection & Stablization (Connection Recovery)
Conection failures are detected by heartbeats. If timed-out,client will automatically change 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**.
### Other Features
Multiplexing ,one client supports multi udp connections,all of those traffic will share one raw connection
* **Multiplexing** One client can handle multiple UDP connections, all of which share the same raw connection.
Multiple Clients Support,one server supports multiple clients.
* **Multiple Clients** One server can have multiple clients.
NAT Supported,all 3 modes work in NAT environment
* **NAT Support** All of the 3 modes work in NAT environments.
OpenVZ Supported,tested on bandwagonhost
* **OpenVZ Support** Tested on BandwagonHost.
* **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
Openwrt Supported,no dependence package,easy to compile,ar71xx binary included in release.
### Key Words
bypass udp qos,bypass udp blocking,openvpn tcp over tcp problem,openvpn over icmp,udp to icmp tunnel,udp to tcp tunnel,udp via icmp,udp via tcp
# Getting Started
### Prerequisites
linux host,root access. if you want to use it on window,you can use VMware in bridged mode.
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 <del>NAT mode</del> are supported).
### Installing
download binary release from https://github.com/wangyu-/udp2raw-tunnel/releases
Download binary release from https://github.com/wangyu-/udp2raw-tunnel/releases
### Running
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.
```
run at client side:
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
./udp2raw_amd64 -c -l0.0.0.0:3333 -r44.55.66.77:4096 -a -k "passwd" --raw-mode faketcp
run at server side:
# Run at server side:
./udp2raw_amd64 -s -l0.0.0.0:4096 -r 127.0.0.1:7777 -a -k "passwd" --raw-mode faketcp
```
Now,your client and server established a tunnel thorough tcp port 4096. Connecting to udp port 3333 at client side is equivalent with connecting to port 7777 at server side. No udp traffic will be exposed to outside.
Now,an encrypted raw tunnel has been established between client and server 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.
# Advanced Topic
### Usage
```
@@ -77,38 +102,43 @@ other options:
2:increase randomly, about every 3 packets (default)
-h,--help print this help message
```
### iptables rule
this programs sends packet via raw socket.In faketcp mode,Linux Kernel TCP packet processing has to be blocked by a iptables rule on both sides,otherwise Kernel will automatically send RST for unrecongized TCP packet and you will sustain from stability/peformance problem.You can use -a option to let the program automatically add/del 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
Its suggested to use aes128cbc + md5 to obtain maxmized security.If you want to run the program on a router,you can try xor+simple,it can fool Packet Inspection by firewalls most time, but it cant protect you from serious attackers. Mode none is only for debug,its not suggest to set cipher-mode or auth-mode to none.
### 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 `aes128cbc` + `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.
### seq-mode
the faketcp mode doest not behave 100% like a real tcp connection.ISP may be able to distinguish the simulated tcp traffic from real tcp traffic(though its costly). seq-mode can help you changed the seq increase behavior a bit. If you experienced problems,try to change the value.
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 connection problems, try to change the value.
# Peformance Test
#### test method:
iperf3 tcp via openvpn + udp2raw
(iperf3 udp mode is not used bc of bug mentioned in this issue: https://github.com/esnet/iperf/issues/296 ,instead,we turn iperf3 's tcp traffic into udp by using openvpn,to test udp2raw 's peformance. Read [Application](https://github.com/wangyu-/udp2raw-tunnel#application) for detail )
#### 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.
#### iperf3 command:
```
iperf3 -c 10.222.2.1 -P40
iperf3 -c 10.222.2.1 -P40 -R
```
#### client host
vultr $2.5/monthly plan(single core 2.4ghz cpu,512m ram,location:Tokyo,Japan),
#### server host
bandwagonhost $3.99/annually(single core 2.0ghz cpu,128m ram,location:Los Angeles,USA)
#### 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)
### Test1
raw_mode: faketcp cipher_mode: xor  auth_mode: simple
![image4](images/image4.PNG)
(reverse speed is simliar and not uploaded)
(reverse speed was simliar and not uploaded)
### Test2
raw_mode: faketcp cipher_mode: aes128cbc  auth_mode: md5
![image5](images/image5.PNG)
(reverse speed is simliar and not uploaded)
(reverse speed was simliar and not uploaded)
# Application
### tunneling any traffic via raw traffic by using udp2raw +openvpn
@@ -120,28 +150,47 @@ raw_mode: faketcp cipher_mode: aes128cbc  auth_mode: md5
3. openvpn over icmp also becomes a choice
more details at [openvpn+udp2raw_guide](/doc/openvpn_guide.md)
### tunneling kcptun
make kcptun support tcp mode.
### speed-up tcp connection via raw traffic by using udp2raw+kcptun
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.
(kcptun, https://github.com/xtaci/kcptun)
### tunneling finalspeed
finalspeed 's tcp mode doesnt work on openvz VPS.you can use finalspeed 's udp mode,and tunnel udp through tcp with this tunnel.
### 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.
# How to build
read [build_guide](/doc/build_guide.md)
# Other
### Easier installation on ArchLinux
```
yaourt -S udp2raw-tunnel # or
pacaur -S udp2raw-tunnel
```
# Related work
### kcptun-raw
this project was inspired by kcptun-raw,which modified kcptun to support tcp mode.
udp2raw was inspired by kcptun-raw,which modified kcptun to support tcp mode.
https://github.com/Chion82/kcptun-raw
### relayRawSocket
kcptun-raw was inspired by relayRawSocket. A simple udp to raw tunnel,wrote in python
https://github.com/linhua55/some_kcptun_tools/tree/master/relayRawSocket
### 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
### Tcp Minion
Tcp Minion is a project which modifid the code of tcp stack in kernel,and implemented real-time out-order udp packet delivery through this modified tcp stack.I failed to find the implementation,but there are some papers avaliable:
https://arxiv.org/abs/1103.0463
http://korz.cs.yale.edu/2009/tng/papers/pfldnet10.pdf
https://pdfs.semanticscholar.org/9e6f/e2306f4385b4eb5416d1fcab16e9361d6ba3.pdf

View File

@@ -59,7 +59,7 @@ typedef int i32_t;
const int max_data_len=1600;
const int buf_len=max_data_len+200;
const int buf_len=max_data_len+400;
const u32_t max_handshake_conn_num=10000;
const u32_t max_ready_conn_num=1000;
const u32_t anti_replay_window_size=1000;
@@ -71,7 +71,7 @@ const u32_t client_retry_interval=1000;
const u32_t server_handshake_timeout=10000;// this should be much longer than clients. client retry initially ,server retry passtively
const int conv_clear_ratio=10; //conv grabage collecter check 1/10 of all conv one time
const int conn_clear_ratio=10;
const int conn_clear_ratio=30;
const int conv_clear_min=5;
const int conn_clear_min=1;

View File

@@ -1,6 +1,8 @@
Udp2raw-tunnel
![image2](/images/image2.PNG)
加密、防重放攻击的、信道复用的udp tunnel利用raw socket中转udp流量
udp2raw tunnel通过raw socket给UDP包加上TCP或ICMP header进而绕过UDP屏蔽或QoS或在UDP不稳定的环境下提升稳定性。支持心跳保活、自动重连重连后会恢复上次连接在底层掉线的情况下可以保持上层不掉线。同时有加密、防重放攻击、信道复用的功能。
**欢迎任何形式的转载**
[English](/README.md)
@@ -11,25 +13,24 @@ Udp2raw-tunnel
如果你需要加速跨国网游、网页浏览解决方案在另一个repo
https://github.com/wangyu-/UDPspeeder
# 功能特性
### 把udp流量伪装成tcp /icmp
用raw socket给udp包加上tcp/icmp包头可以突破udp流量限制或Udp QOS。或者在udp nat有问题的环境下提升稳定性。  另外也支持用raw 发udp包这样流量不会被伪装只会被加密。
### 加密 防重放攻击
用aes128cbc加密md5/crc32做数据完整校验。用类似ipsec/openvpn的 replay windows机制来防止重放攻击。
设计目标是即使攻击者可以监听到tunnel的所有包可以选择性丢弃tunnel的任意包可以重放任意包攻击者也没办法获得tunnel承载的任何数据也没办法向tunnel的数据流中通过包构造/包重放插入任何数据。
### 模拟TCP3次握手
模拟TCP3次握手模拟seq ack过程。另外还模拟了一些tcp optionMSS,sackOk,TS,TS_ack,wscale用来使流量看起来更像是由普通的linux tcp协议栈发送的。
### 连接保持,连接快速恢复,单向链路失效检测
心跳机制检查连接是否中断一旦心跳超时。client会立即换raw socket的端口重连重连成功后会恢复之前中断的连接。虽然raw端的端口变了但是udp端的所有连接都会继续有效。udp这边感觉不到raw端的重连只会感觉到短暂断流,这跟普通的短暂丢包是类似的,不会导致上层应用重连。
### 心跳保活、自动重连,连接快速恢复,单向链路失效检测
心跳保活、自动重连udp2raw重连可以恢复上次的连接重连后上层连接继续有效底层掉线上层不掉线。有效解决上层连接断开的问题。 (功能借鉴自[kcptun-raw](https://github.com/Chion82/kcptun-raw)**就算你拔掉网线重插或者重新拨号获得新ip上层应用也不会断线**
Client能用单倍的超时时间检测到单向链路的失效不管是上行还是下行只要有一失效就能被client检测到。重连只需要client发起就可以立即被server处理不需要等到server端的连接超时后。
Client能用单倍的超时时间检测到单向链路的失效不管是上行还是下行只要有一个方向失效就能被client检测到。重连只需要client发起就可以立即被server处理不需要等到server端的连接超时后。
对于有大量client的情况对于不同client,server发送的心跳是错开时间发送的不会因为短时间发送大量的心跳而造成拥塞和延迟抖动。
### 加密 防重放攻击 防中间人攻击
用aes128cbc加密md5/crc32做数据完整校验。用类似ipsec/openvpn的 replay window机制来防止重放攻击。
设计目标是即使攻击者可以监听到tunnel的所有包可以选择性丢弃tunnel的任意包可以重放任意包攻击者也没办法获得tunnel承载的任何数据也没办法向tunnel的数据流中通过包构造/包重放插入任何数据。client和server互相认证对方无法被中间人攻击。
### 其他特性
信道复用client的udp端支持多个连接。
@@ -40,9 +41,9 @@ NAT 穿透 tcp icmp udp模式都支持nat穿透。
支持Openvz配合finalspeed使用可以在openvz上用tcp模式的finalspeed
支持Openwrt,没有编译依赖容易编译到任何平台上。release中提供了ar71xx版本的binary
支持Openwrt没有编译依赖容易编译到任何平台上。release中提供了ar71xx版本的binary
epoll纯异步高并发除了回收过期连接外所有操作的时间复杂度都跟连接数无关。回收过期连接的操做也是一点一点进行的不会因为消耗太多cpu时间造成延迟抖动。
epoll纯异步高并发除了回收过期连接外所有操作的时间复杂度都跟连接数无关。回收过期连接的操做也是柔和进行的不会因为消耗太多cpu时间造成延迟抖动。
### 关键词
突破udp qos,突破udp屏蔽openvpn tcp over tcp problem,openvpn over icmp,udp to icmp tunnel,udp to tcp tunnel,udp via icmp,udp via tcp
@@ -50,7 +51,7 @@ epoll纯异步高并发除了回收过期连接外所有操作的时间
# 简明操作说明
### 环境要求
Linux主机有root权限。主机上最好安装了iptables命令(apt/yum很容易安装)。在windows和mac上可以开虚拟机桥接模式测试可用
Linux主机有root权限。主机上最好安装了iptables命令(apt/yum很容易安装)。在windows和mac上可以开虚拟机udp2raw跑在linux里其他应用照常跑在windows上桥接模式测试可用)。
### 安装
下载编译好的二进制文件,解压到任意目录。
@@ -110,7 +111,7 @@ other options:
-h,--help print this help message
```
### iptables 规则
用raw收发tcp包本质上绕过了linux内核的tcp协议栈。linux碰到raw socket发来的包会不认识如果一直收到不认识的包会回复大量RST造成不稳定或性能问题。所以强烈建议添加iptables规则屏蔽Linux内核的对指定端口的处理。用-a选项udp2raw会在启动的时候自动帮你加上Iptables规则退出的时候再自动删掉。如果你不信任-a选项的可靠性,可以用-g选项来生成相应的Ip规则再自己手动添加。
用raw收发tcp包本质上绕过了linux内核的tcp协议栈。linux碰到raw socket发来的包会不认识如果一直收到不认识的包会回复大量RST造成不稳定或性能问题。所以强烈建议添加iptables规则屏蔽Linux内核的对指定端口的处理。用-a选项udp2raw会在启动的时候自动帮你加上Iptables规则退出的时候再自动删掉。如果长期使用,可以用-g选项来生成相应的Iptables规则再自己手动添加这样规则不会在udp2raw退出时被删掉可以避免停掉udp2raw后内核向对端回复RST
用raw收发udp包也类似只是内核回复的是icmp unreachable。而用raw 收发icmp内核会自动回复icmp echo。都需要相应的iptables规则。
### cipher-mode 和 auth-mode
@@ -154,19 +155,21 @@ raw_mode: faketcp cipher_mode: aes128cbc  auth_mode: md5
[udp2raw+kcptun step_by_step教程](kcptun_step_by_step.md)
### 中转 finalspeed
[udp2raw+finalspeed step_by_step教程](finalspeed_step_by_step.md)
# 如何自己编译
[编译教程](build_guide.zh-cn.md)
# 相关repo
### kcptun-raw
this project was inspired by kcptun-raw,which modified kcptun to support tcp mode.
udp2raw was inspired by kcptun-raw,which modified kcptun to support tcp mode.
https://github.com/Chion82/kcptun-raw
### relayRawSocket
kcptun-raw was inspired by relayRawSocket. A simple udp to raw tunnel,wrote in python
https://github.com/linhua55/some_kcptun_tools/tree/master/relayRawSocket
### 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.

74
doc/build_guide.md Normal file
View File

@@ -0,0 +1,74 @@
# udp2raw build guide
the guide on how to build udp2raw to you own platform
## linux platform which supports local compile
such as PC,raspberry pi
##### install git
run on debian/ubuntun
```
sudo apt-get install git
```
run on redhat/centos:
```
sudo yum install git
```
##### clone git code
run in any dir
```
git clone https://github.com/wangyu-/udp2raw-tunnel.git
cd udp2raw-tunnel
```
##### install compile tool
run on debian/ubuntun
```
sudo apt-get install build-essential
```
run on redhat/centos:
```
sudo yum groupinstall 'Development Tools'
```
run 'make'compilation done. the udp2raw file is the just compiled binary
## platform which needs cross-compile
such as openwrt router,run following instructions on your PC
##### install git
run on debian/ubuntun
```
sudo apt-get install git
```
run on redhat/centos:
```
sudo yum install git
```
##### download cross compile tool chain
find it on downloads.openwrt.org according to your openwrt version and cpu model.
for example, my tplink wdr4310 runs chaos_calmer 15.05,its with ar71xx cpudownload the following package.
```
http://downloads.openwrt.org/chaos_calmer/15.05/ar71xx/generic/OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2
```
unzip it to any dir,such as /home/wangyu/OpenWrt-SDK-ar71xx-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2
cd into staging_dir toolchain-xxxxx bin .find the soft link with g++ suffix. in my case ,its mips-openwrt-linux-g++ ,check for its full path:
```
/home/wangyu/Desktop/OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-g++
```
##### compile
modify first line of makefile to:
```
cc_cross=/home/wangyu/Desktop/OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-g++
```
run 'make cross'the just generated udp2raw_cross is the binary,compile done. copy it to your router to run.

72
doc/build_guide.zh-cn.md Normal file
View File

@@ -0,0 +1,72 @@
# udp2raw编译方法
本文演示怎么把udp2raw编译到自己所需的平台。
## 可以本地编译的linux平台
比如电脑、树莓派
##### 首先安装git
debian/ubuntun执行
```
sudo apt-get install git
```
redhat/centos执行:
```
sudo yum install git
```
##### 用git把源码clone至本地
在任意目录执行:
```
git clone https://github.com/wangyu-/udp2raw-tunnel.git
cd udp2raw-tunnel
```
##### 安装g++ make 等工具
debian/ubuntun执行
```
sudo apt-get install build-essential
```
redhat/centos执行:
```
sudo yum groupinstall 'Development Tools'
```
然后运行make编译完成。 生成的udp2raw就是编译好的bianry。
## 需要交叉编译的平台
比如各种openwrt路由器
##### 首先安装git
debian/ubuntun执行
```
sudo apt-get install git
```
redhat/centos执行:
```
sudo yum install git
```
##### 下载安装交叉编译工具包
去downloads.openwrt.org上找到自己的openwrt版本和cpu型号对应的SDK。通常openwrt版本号不一样也问题不大最主要是cpu型号。
比如我的tplink wdr4310运行的是chaos_calmer 15.05,ar71xx cpu应该下载这个包
```
http://downloads.openwrt.org/chaos_calmer/15.05/ar71xx/generic/OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2
```
解压到本地任意目录,比如:/home/wangyu/OpenWrt-SDK-ar71xx-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2
让后依次进入staging_dir toolchain-xxxxx bin 目录找到后缀是g++的软链,比如我的是mips-openwrt-linux-g++ ,记下这个文件的完整路径:
```
/home/wangyu/Desktop/OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-g++
```
##### 编译
把makefile的第一行 cross_cc=后面的内容改成你刚才记下的完整路径:
```
cc_cross=/home/wangyu/Desktop/OpenWrt-SDK-15.05-ar71xx-generic_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-g++
```
执行make cross目录下生成udp2raw_cross文件。编译完成。

View File

@@ -1,7 +1,7 @@
# udp2raw+kcptun 加速tcp流量 Step by Step 教程
![image](kcptun_step_by_step/Capture00.PNG)
本教程会一步一步演示用udp2raw+kcptun加速SSH流量的过程。加速任何其他tcp流量也一样。
本教程会一步一步演示用udp2raw+kcptun加速SSH流量的过程。加速任何其他tcp流量也一样包括ss本文避免涉及科学上网所以演示ssh
### 环境要求
两边的主机都是linux有root权限。 可以是openwrt路由器或树莓派windows上桥接模式的虚拟机也可用

View File

@@ -18,6 +18,9 @@ assume server ip is 45.66.77.88
#### client side config
```
client
dev tun100
proto udp
remote 127.0.0.1 3333
resolv-retry infinite

View File

@@ -1,18 +1,21 @@
#include <lib/aes.h>
#include <lib/md5.h>
#include "lib/aes.h"
#include "lib/md5.h"
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <encrypt.h>
#include <common.h>
#include "encrypt.h"
#include "common.h"
#include "log.h"
//static uint64_t seq=1;
static int8_t zero_iv[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0};//this prog use zero iv,you should make sure first block of data contains a random/nonce data
/****
* important!
* why zero iv + nonce first data block is secure?
* https://crypto.stackexchange.com/questions/5421/using-cbc-with-a-fixed-iv-and-a-random-first-plaintext-block
****/
unordered_map<int, const char *> auth_mode_tostring = {{auth_none, "none"}, {auth_md5, "md5"}, {auth_crc32, "crc32"},{auth_simple,"simple"}};
unordered_map<int, const char *> cipher_mode_tostring={{cipher_none,"none"},{cipher_aes128cbc,"aes128cbc"},{cipher_xor,"xor"}};

View File

@@ -29,10 +29,6 @@ enum cipher_mode_t {cipher_none=0,cipher_aes128cbc,cipher_xor,cipher_end};
extern auth_mode_t auth_mode;
extern cipher_mode_t cipher_mode;
struct a
{
char * buf[buf_len];
};
extern unordered_map<int, const char *> auth_mode_tostring;
extern unordered_map<int, const char *> cipher_mode_tostring;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 37 KiB

1
images/speedtest/111 Normal file
View File

@@ -0,0 +1 @@

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

View File

@@ -1,4 +1,4 @@
#include <log.h>
#include "log.h"
int log_level=log_info;

2
log.h
View File

@@ -44,7 +44,7 @@
#include <sys/timerfd.h>
#include <set>
#include <encrypt.h>
#include "encrypt.h"
#include <inttypes.h>
#include <sys/ioctl.h>

View File

@@ -860,8 +860,8 @@ int try_to_list_and_bind(int port)
close(old_bind_fd);
}
struct sockaddr_in temp_bind_addr;
bzero(&temp_bind_addr, sizeof(temp_bind_addr));
struct sockaddr_in temp_bind_addr={0};
//bzero(&temp_bind_addr, sizeof(temp_bind_addr));
temp_bind_addr.sin_family = AF_INET;
temp_bind_addr.sin_port = htons(port);
@@ -1155,7 +1155,7 @@ int client_on_timer(conn_info_t &conn_info) //for client
{
conn_info.state.client_current_state=client_idle;
conn_info.my_id=get_true_random_number_nz();
mylog(log_info,"state back to client_idle from client_ready bc of recv-direction timeout\n");
mylog(log_info,"state back to client_idle from client_ready bc of server-->client direction timeout\n");
return 0;
}
@@ -1168,7 +1168,7 @@ int client_on_timer(conn_info_t &conn_info) //for client
{
conn_info.state.client_current_state=client_idle;
conn_info.my_id=get_true_random_number_nz();
mylog(log_info,"state back to client_idle from client_ready bc of send-direction timeout\n");
mylog(log_info,"state back to client_idle from client_ready bc of client-->server direction timeout\n");
}
mylog(log_debug,"heartbeat sent <%x,%x>\n",conn_info.oppsite_id,conn_info.my_id);
@@ -1375,7 +1375,7 @@ int client_on_raw_recv(conn_info_t &conn_info)
u64_t u64=conn_info.blob->conv_manager.find_u64_by_conv(tmp_conv_id);
sockaddr_in tmp_sockaddr;
sockaddr_in tmp_sockaddr={0};
tmp_sockaddr.sin_family = AF_INET;
tmp_sockaddr.sin_addr.s_addr=(u64>>32u);
@@ -1417,10 +1417,13 @@ int server_on_raw_recv_multi()
{
recv(raw_recv_fd, 0,0, 0 );//
//struct sockaddr saddr;
//socklen_t saddr_size;
//socklen_t saddr_size=sizeof(saddr);
///recvfrom(raw_recv_fd, 0,0, 0 ,&saddr , &saddr_size);//
mylog(log_trace,"peek_raw failed\n");
return -1;
}else
{
mylog(log_trace,"peek_raw success\n");
}
u32_t ip=peek_info.src_ip;uint16_t port=peek_info.src_port;
@@ -1544,9 +1547,11 @@ int server_on_raw_recv_multi()
if(conn_info.state.server_current_state==server_ready)
{
char type;
//mylog(log_info,"before recv_safer\n");
if (recv_safer(conn_info,type, data, data_len) != 0) {
return -1;
}
//mylog(log_info,"after recv_safer\n");
return server_on_raw_recv_ready(conn_info,ip_port,type,data,data_len);
}
return 0;
@@ -1663,10 +1668,10 @@ int server_on_raw_recv_ready(conn_info_t &conn_info,char * ip_port,char type,cha
tmp_conv_id);
return 0;
}
struct sockaddr_in remote_addr_in;
struct sockaddr_in remote_addr_in={0};
socklen_t slen = sizeof(sockaddr_in);
memset(&remote_addr_in, 0, sizeof(remote_addr_in));
//memset(&remote_addr_in, 0, sizeof(remote_addr_in));
remote_addr_in.sin_family = AF_INET;
remote_addr_in.sin_port = htons(remote_port);
remote_addr_in.sin_addr.s_addr = remote_address_uint32;
@@ -1857,10 +1862,10 @@ int server_on_raw_recv_pre_ready(conn_info_t &conn_info,char * ip_port,u32_t tmp
int get_src_adress(u32_t &ip)
{
struct sockaddr_in remote_addr_in;
struct sockaddr_in remote_addr_in={0};
socklen_t slen = sizeof(sockaddr_in);
memset(&remote_addr_in, 0, sizeof(remote_addr_in));
//memset(&remote_addr_in, 0, sizeof(remote_addr_in));
remote_addr_in.sin_family = AF_INET;
remote_addr_in.sin_port = htons(remote_port);
remote_addr_in.sin_addr.s_addr = remote_address_uint32;
@@ -1883,7 +1888,7 @@ int get_src_adress(u32_t &ip)
return -1;
}
struct sockaddr_in my_addr;
struct sockaddr_in my_addr={0};
unsigned int len=sizeof(my_addr);
if(getsockname(new_udp_fd, (struct sockaddr *) &my_addr, &len)!=0) return -1;
@@ -1945,10 +1950,10 @@ int client_event_loop()
int yes = 1;
//setsockopt(udp_fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes));
struct sockaddr_in local_me;
struct sockaddr_in local_me={0};
socklen_t slen = sizeof(sockaddr_in);
memset(&local_me, 0, sizeof(local_me));
//memset(&local_me, 0, sizeof(local_me));
local_me.sin_family = AF_INET;
local_me.sin_port = htons(local_port);
local_me.sin_addr.s_addr = local_address_uint32;
@@ -2033,9 +2038,10 @@ int client_event_loop()
{
int recv_len;
struct sockaddr_in udp_new_addr_in;
if ((recv_len = recvfrom(udp_fd, buf, buf_len, 0,
(struct sockaddr *) &udp_new_addr_in, &slen)) == -1) {
struct sockaddr_in udp_new_addr_in={0};
socklen_t udp_new_addr_len = sizeof(sockaddr_in);
if ((recv_len = recvfrom(udp_fd, buf, max_data_len, 0,
(struct sockaddr *) &udp_new_addr_in, &udp_new_addr_len)) == -1) {
mylog(log_error,"recv_from error,this shouldnt happen at client\n");
myexit(1);
};
@@ -2131,8 +2137,8 @@ int server_event_loop()
bind_fd=socket(AF_INET,SOCK_DGRAM,0);
}
struct sockaddr_in temp_bind_addr;
bzero(&temp_bind_addr, sizeof(temp_bind_addr));
struct sockaddr_in temp_bind_addr={0};
// bzero(&temp_bind_addr, sizeof(temp_bind_addr));
temp_bind_addr.sin_family = AF_INET;
temp_bind_addr.sin_port = htons(local_port);
@@ -2307,13 +2313,14 @@ int server_event_loop()
u32_t conv_id=conn_info.blob->conv_manager.find_conv_by_u64(fd);
int recv_len=recv(fd,buf,buf_len,0);
int recv_len=recv(fd,buf,max_data_len,0);
mylog(log_trace,"received a packet from udp_fd,len:%d\n",recv_len);
if(recv_len<0)
{
mylog(log_debug,"udp fd,recv_len<0 continue\n");
mylog(log_debug,"udp fd,recv_len<0 continue,%s\n",strerror(errno));
continue;
}
@@ -2388,6 +2395,8 @@ void print_help()
printf(" 1:increase every packet\n");
printf(" 2:increase randomly, about every 3 packets (default)\n");
// printf("\n");
printf(" --lower-level <string> send packet at OSI level 2, format:'if_name#gateway_mac_adress'\n");
printf(" ie:'eth0#00:23:45:67:89:b9'.Beta.\n");
printf(" -h,--help print this help message\n");
//printf("common options,these options must be same on both side\n");

View File

@@ -1,23 +1,41 @@
ccmips=mips-openwrt-linux-g++
FLAGS=-Wall -Wextra -Wno-unused-variable -Wno-unused-parameter
FLAGS2= -O3
cc_cross=/home/wangyu/OpenWrt-SDK-ar71xx-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-g++
cc_local=g++
cc_ar71xx=/home/wangyu/OpenWrt-SDK-ar71xx-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2/staging_dir/toolchain-mips_34kc_gcc-4.8-linaro_uClibc-0.9.33.2/bin/mips-openwrt-linux-g++
cc_bcm2708=/home/wangyu/raspberry/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-g++
FLAGS= -std=c++11 -Wall -Wextra -Wno-unused-variable -Wno-unused-parameter -Wno-missing-field-initializers
SOURCES=main.cpp lib/aes.c lib/md5.c encrypt.cpp log.cpp network.cpp common.cpp
NAME=udp2raw
TAR=${NAME}_binaries.tar.gz ${NAME}_amd64 ${NAME}_x86 ${NAME}_ar71xx ${NAME}_bcm2708
all:
sudo killall udp2raw||true
sleep 0.2
g++ main.cpp -o udp2raw -static -ggdb -I. lib/aes.c lib/md5.c encrypt.cpp log.cpp network.cpp common.cpp -lrt -std=c++11 ${FLAGS} ${FLAGS2}
# ${ccmips} main.cpp -o udp2raw_ar71xx -lrt -I. lib/aes.c lib/md5.c encrypt.cpp log.cpp network.cpp common.cpp -std=c++11 ${FLAGS} ${FLAGS2}
rm -f ${NAME}
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -static -O3
fast:
sudo killall udp2raw||true
sleep 0.2
g++ main.cpp -o udp2raw -ggdb -I. lib/aes.c lib/md5.c encrypt.cpp log.cpp network.cpp common.cpp -lrt -std=c++11 ${FLAGS}
rm -f ${NAME}
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt
debug:
g++ main.cpp -o udp2raw -static -ggdb -I. -Ilib lib/aes.c lib/md5.c encrypt.cpp log.cpp network.cpp common.cpp -lrt -std=c++11 ${FLAGS} -Wformat-nonliteral -D MY_DEBUG
rm -f ${NAME}
${cc_local} -o ${NAME} -I. ${SOURCES} ${FLAGS} -lrt -Wformat-nonliteral -D MY_DEBUG
release:
g++ main.cpp -o udp2raw_amd64 -static -ggdb -I. lib/aes.c lib/md5.c encrypt.cpp log.cpp network.cpp common.cpp -lrt -std=c++11 ${FLAGS} ${FLAGS2}
g++ main.cpp -o udp2raw_x86 -static -ggdb -I. lib/aes.c lib/md5.c encrypt.cpp log.cpp network.cpp common.cpp -lrt -std=c++11 ${FLAGS} ${FLAGS2} -m32
${ccmips} main.cpp -o udp2raw_ar71xx -lrt -I. lib/aes.c lib/md5.c encrypt.cpp log.cpp network.cpp common.cpp -std=c++11 ${FLAGS} ${FLAGS2}
tar -zcvf udp2raw_binaries.tar.gz udp2raw_amd64 udp2raw_x86 udp2raw_ar71xx
ar71xx:
${cc_ar71xx} -o ${NAME}_ar71xx -I. ${SOURCES} ${FLAGS} -lrt -lgcc_eh -static -O3
bcm2708:
${cc_bcm2708} -o ${NAME}_bcm2708 -I. ${SOURCES} ${FLAGS} -lrt -static -O3
amd64:
${cc_local} -o ${NAME}_amd64 -I. ${SOURCES} ${FLAGS} -lrt -static -O3
x86:
${cc_local} -o ${NAME}_x86 -I. ${SOURCES} ${FLAGS} -lrt -m32 -static -O3
cross:
${cc_cross} -o ${NAME}_cross -I. ${SOURCES} ${FLAGS} -lrt -O3
cross2:
${cc_cross} -o ${NAME}_cross -I. ${SOURCES} ${FLAGS} -lrt -static -lgcc_eh -O3
release: amd64 x86 ar71xx bcm2708
tar -zcvf ${TAR}
clean:
rm -f ${TAR}

View File

@@ -24,6 +24,8 @@ int lower_level=0;
int ifindex=-1;
char if_name[100]="";
unsigned short g_ip_id_counter=0;
unsigned char oppsite_hw_addr[6]=
{0xff,0xff,0xff,0xff,0xff,0xff};
//{0x00,0x23,0x45,0x67,0x89,0xb9};
@@ -162,6 +164,7 @@ packet_info_t::packet_info_t()
int init_raw_socket()
{
g_ip_id_counter=get_true_random_number()%65535;
if(lower_level==0)
{
raw_send_fd = socket(AF_INET , SOCK_RAW , IPPROTO_TCP);
@@ -306,7 +309,6 @@ int init_ifindex(char * if_name)
return 0;
}
int send_raw_ip(raw_info_t &raw_info,const char * payload,int payloadlen)
{
const packet_info_t &send_info=raw_info.send_info;
@@ -316,19 +318,18 @@ int send_raw_ip(raw_info_t &raw_info,const char * payload,int payloadlen)
struct iphdr *iph = (struct iphdr *) send_raw_ip_buf;
memset(iph,0,sizeof(iphdr));
static unsigned short ip_id=1;
iph->ihl = sizeof(iphdr)/4; //we dont use ip options,so the length is just sizeof(iphdr)
iph->version = 4;
iph->tos = 0;
if(lower_level)
{
iph->id=0;
//iph->id = htons (ip_id++); //Id of this packet
//iph->id=0;
iph->id = htons (g_ip_id_counter++); //Id of this packet
}
else
iph->id = 0; //Id of this packet ,kernel will auto fill this if id is zero ,or really?????// todo //seems like there is a problem
iph->id = htons (g_ip_id_counter++); //Id of this packet
//iph->id = 0; //Id of this packet ,kernel will auto fill this if id is zero ,or really?????// todo //seems like there is a problem
iph->frag_off = htons(0x4000); //DF set,others are zero
// iph->frag_off = htons(0x0000); //DF set,others are zero
@@ -353,7 +354,7 @@ int send_raw_ip(raw_info_t &raw_info,const char * payload,int payloadlen)
int ret;
if(lower_level==0)
{
struct sockaddr_in sin;
struct sockaddr_in sin={0};
sin.sin_family = AF_INET;
//sin.sin_port = htons(info.dst_port); //dont need this
sin.sin_addr.s_addr = send_info.dst_ip;
@@ -363,8 +364,8 @@ int send_raw_ip(raw_info_t &raw_info,const char * payload,int payloadlen)
else
{
struct sockaddr_ll addr;
memset(&addr,0,sizeof(addr));
struct sockaddr_ll addr={0};
//memset(&addr,0,sizeof(addr));
addr.sll_family=AF_PACKET;
addr.sll_ifindex=ifindex;
@@ -389,13 +390,15 @@ int send_raw_ip(raw_info_t &raw_info,const char * payload,int payloadlen)
int peek_raw(packet_info_t &peek_info)
{ static char peek_raw_buf[buf_len];
char *ip_begin=peek_raw_buf+link_level_header_len;
struct sockaddr saddr;
socklen_t saddr_size;
int recv_len = recvfrom(raw_recv_fd, peek_raw_buf,buf_len, MSG_PEEK ,&saddr , &saddr_size);//change buf_len to something smaller,we only need header here
struct sockaddr saddr={0};
socklen_t saddr_size=sizeof(saddr);
int recv_len = recvfrom(raw_recv_fd, peek_raw_buf,max_data_len, MSG_PEEK ,&saddr , &saddr_size);//change max_data_len to something smaller,we only need header here
iphdr * iph = (struct iphdr *) (ip_begin);
//mylog(log_info,"recv_len %d\n",recv_len);
if(recv_len<int(sizeof(iphdr)))
{
mylog(log_trace,"failed here %d %d\n",recv_len,int(sizeof(iphdr)));
mylog(log_trace,"%s\n ",strerror(errno));
return -1;
}
peek_info.src_ip=iph->saddr;
@@ -407,10 +410,17 @@ int peek_raw(packet_info_t &peek_info)
{
case mode_faketcp:
{
if(iph->protocol!=IPPROTO_TCP) return -1;
if(iph->protocol!=IPPROTO_TCP)
{
mylog(log_trace,"failed here");
return -1;
}
struct tcphdr *tcph=(tcphdr *)payload;
if(recv_len<int( iphdrlen+sizeof(tcphdr) ))
{
mylog(log_trace,"failed here");
return -1;
}
peek_info.src_port=ntohs(tcph->source);
peek_info.syn=tcph->syn;
break;
@@ -445,12 +455,10 @@ int recv_raw_ip(raw_info_t &raw_info,char * &payload,int &payloadlen)
static char recv_raw_ip_buf[buf_len];
iphdr * iph;
struct sockaddr saddr;
socklen_t saddr_size;
saddr_size = sizeof(saddr);
struct sockaddr saddr={0};
socklen_t saddr_size = sizeof(saddr);
int flag=0;
int recv_len = recvfrom(raw_recv_fd, recv_raw_ip_buf, buf_len, flag ,&saddr , &saddr_size);
int recv_len = recvfrom(raw_recv_fd, recv_raw_ip_buf, max_data_len, flag ,&saddr , &saddr_size);
if(recv_len<0)
{
@@ -481,6 +489,7 @@ int recv_raw_ip(raw_info_t &raw_info,char * &payload,int &payloadlen)
if(bind_address_uint32!=0 &&recv_info.dst_ip!=bind_address_uint32)
{
mylog(log_trace,"bind adress doenst match, dropped\n");
//printf(" bind adress doenst match, dropped\n");
return -1;
}
@@ -987,7 +996,7 @@ int recv_raw_udp(raw_info_t &raw_info, char *&payload, int &payloadlen)
}
udphdr *udph=(struct udphdr*)ip_payload;
if(ntohs(udph->len)!=ip_payloadlen)
if(int(ntohs(udph->len))!=ip_payloadlen)
{
mylog(log_debug,"udp length error %d %d \n",ntohs(udph->len),ip_payloadlen);
@@ -1183,7 +1192,7 @@ int recv_raw_tcp_deprecated(packet_info_t &info,char * &payload,int &payloadlen)
mylog(log_trace,"raw!\n");
size = recvfrom(raw_recv_fd, buf, buf_len, 0 ,&saddr , &saddr_size);
size = recvfrom(raw_recv_fd, buf, max_data_len, 0 ,&saddr , &saddr_size);
if(buf[12]!=8||buf[13]!=0)
{