Chion82 / kcptun-raw

Kcptun with raw socket and fake TCP headers.
GNU General Public License v3.0
416 stars 101 forks source link

kcptun-raw

为缓解部分ISP对UDP断流的问题,通过伪造TCP报文,实现了简化版的 kcptun
kcp的下层通信方式是带伪TCP报头的packet,通过raw socket实现,需要通过iptables绕过内核协议栈。

Inspired by linhua55/some_kcptun_tools/relayRawSocket .

Features

Updates

Compilation

编译依赖:libev-devel, openssl-devel, automake, autoconf

$ ./autogen.sh
$ ./configure
$ make
$ sudo make install

Openwrt编译指南:

依赖准备:

$ cd OpenWRT-SDK-XXX
$ scripts/feeds update
$ scripts/feeds install libev
$ make menuconfig #勾选Libraries->libev
$ make V=99

交叉编译: 请参考 Cross Compile
以ar71xx 15.05.1 SDK为例:

$ export PATH=$PATH:(your toolchain/bin directory here)
$ export STAGING_DIR=(your staging_dir directory here)
$ cd kcptun-raw
$ ./autogen.sh
$ ./configure --build=architecture-unknown-linux-gnu \
--host=mips-openwrt-linux-uclibc \
CFLAGS="-I${STAGING_DIR}/target-mips_34kc_uClibc-0.9.33.2/usr/include" \
LDFLAGS="-L${STAGING_DIR}/target-mips_34kc_uClibc-0.9.33.2/usr/lib"
$ make

编译产出binary: src/kcpraw_client , src/kcpraw_server

Usage

服务端:

# iptables -A INPUT -p tcp --dport SERVER_PORT -j DROP
# kcpraw_server TARGET_IP TARGET_PORT SERVER_IP SERVER_PORT [--key 16_BYTES_KEY] [--mode MODE] [--noseq]

客户端:

# iptables -A INPUT -p tcp -s SERVER_IP --sport LISTEN_PORT -j DROP
# kcpraw_client SERVER_IP SERVER_PORT LISTEN_IP LISTEN_PORT [--key 16_BYTES_KEY] [--mode MODE] [--noseq]

示例:

108.0.0.1替换为服务器IP 服务端:

# iptables -A INPUT -p tcp --dport 888 -j DROP
# kcpraw_server 127.0.0.1 8388 0.0.0.0 888 --mode fast2

客户端:

# iptables -A INPUT -p tcp -s 108.0.0.1 --sport 888 -j DROP
# kcpraw_client 108.0.0.1 888 0.0.0.0 8388 --mode fast2
$ sslocal -s 127.0.0.1 -p 8388 -k YOUR_SS_KEY

如果客户端log中有大量Re-init fake TCP connection并且频繁断流,请尝试在客户端和服务端的命令都添加--noseq参数。

可选参数说明:

分层示意图