Total Pageviews

Friday 12 May 2017

kcptun的修改版-kcpraw

运行在伪造的 TCP 协议之上的 kcptun, 主要目的是避免 ISP 对 UDP 协议可能的 QOS.
在三次握手后会进行 HTTP 握手, 将流量伪装成 HTTP 流量.
kcptun 的具体参数与使用方法参见 kcptun

基本用法

为了使用原始套接字,服务端与客户端都需要 root 权限
服务端
./kcpraw_server_linux_amd64 -t "TARGET_IP:TARGET_PORT" -l "KCP_SERVER_IP:KCP_SERVER_PORT"
客户端
./kcpraw_client_darwin_amd64 -r "KCP_SERVER_IP:KCP_SERVER_PORT" -l ":LOCAL_PORT"

注意事项

为了避免内核返回的 RST 报文影响连接的建立,需要添加相应的 iptables 规则
现在 linux 下的客户端和服务端会自动添加和清理 iptables 规则
windows 客户端参考 windows firewall port exceptions 链接中的方法为 LOCAL_PORT 设置防火墙规则
windows 下推荐直接下载编译好的客户端,依赖 winpcap
macos 下使用客户端可以参考 enable steath mode 打开静默模式即可
macos 下使用推荐通过设置 pf 规则来过滤 RST 报文
# 在 /etc/pf.conf 文件后添加一行 
block drop proto tcp from any to <your kcp-server ip address> flags R/R
# 例如 block drop proto tcp from any to 45.88.75.23 flags R/R  
# 然后在终端下执行 
sudo pfctl -f /etc/pf.conf 
sudo pfctl -e 
如果找不到方法过滤 RST 报文,现在可以使用选项 --ignrst 来在应用层忽略 RST 报文,但是并不推荐使用这个选项,因为并不能保证 RST 发出去以后连接还能继续保持,请谨慎使用
由于使用 windows 或者 macos 服务器运行 kcptun 服务的情况并不多见, 并没有进行相应的测试, 所以并不能保证服务端在非 linux 环境下能够正常使用
伪装的 Host 可以通过选项 --host 进行设置
如果不希望伪装为 HTTP 流量可以通过设置选项 --nohttp 关闭此功能, 注意客户端和服务端在这一选项上必须保持一致

构建

go get -u -v github.com/luckypoem/kcpraw/client  
go get -u -v github.com/luckypoem/kcpraw/server  
windows 下编译依赖 winpcap 和 gcc 请自行解决环境问题
对 windows10 使用者你可能需要参考这个链接 stackoverflow 

from https://github.com/ccsexyz/kcpraw
https://github.com/luckypoem/kcpraw/


相关帖子:http://briteming.blogspot.com/2016/05/kcptunsocks.html
https://briteming.blogspot.com/2017/10/xkcptunkcplibevent2ckcptun.html
https://briteming.blogspot.com/2017/10/kcpraw.html
----------------

我的补充说明

登陆linux vps.
mkdir kcpraw-linux-amd64
cd kcpraw-linux-amd64
wget https://github.com/ccsexyz/kcpraw/releases/download/v20171122/kcpraw-linux-amd64-20171121.tar.gz
tar zxvf  kcpraw-linux-amd64-20171121.tar.gz
(在当前目录下,会解压出来kcpraw_server_linux_amd64文件)
chmod 755  kcpraw_server_linux_amd64

root@ar:~/kcpraw-linux-amd64#  ./kcpraw_server_linux_amd64 -t "localhost:8118" -l "0.0.0.0:2255" &

在vps的8118端口上运行的是一个http代理服务器程序:
https://briteming.blogspot.com/2018/04/gohttpkiss-proxy.html .
不过此命令:./kcpraw_server_linux_amd64 -t "localhost:8118" -l "0.0.0.0:2255" &容易退出运行,
我们可利用systemd把此命令运行为service:
nano /etc/systemd/system/kcpraw.service
其内容为:
[Unit]
After=network.target

[Service]
ExecStart=/root/kcpraw-linux-amd64/kcpraw_server_linux_amd64 -t "localhost:8118" -l "0.0.0.0:2255"
Restart=always

[Install]
WantedBy=multi-user.target


然后运行:
systemctl start kcpraw
systemctl enable kcpraw

服务器端搭建完成。

在本地机器mac上。
mkdir kcpraw
cd  kcpraw
wget https://github.com/ccsexyz/kcpraw/releases/download/v20171122/kcpraw-darwin-amd64-20171121.tar.gz
tar zxvf kcpraw-darwin-amd64-20171121.tar.gz
(在当前目录下,会解压出来文件kcpraw_client_darwin_amd64)
chmod 755 kcpraw_client_darwin_amd64
sudo ./kcpraw_client_darwin_amd64 -r "vps-ip:2255" -l ":6677"

然后设置本地机器的浏览器的http代理服务器地址为127.0.0.1:6677 ,浏览器即可翻墙。
-------

A kcptun based on c++11/asio, compatible with kcptun(golang)

Name

kcptun-asio -- A Secure Tunnel Based On KCP with N:M Multiplexing
kcptun-asio is based on C++11 and Asio, fully compatible with kcptun(go)

Synopsis

$ ./kcptun_client -l :6666 -r xx:xx:xx:xx:yy --key password --crypt aes --mtu 1200 --ds 20 --ps 10 --nocomp
$ ./kcptun_server -l :7777 -t xx:xx:xx:xx:yy --key password --crypt aes --mtu 1200 --ds 20 --ps 10 --nocomp

Features

  • reliable data transfering based on kcp protocol
  • support aes*/xor/xtea/none/cast5/blowfish/twofish/3des/salsa20 encryption
  • multiplexing
  • snappy streaming compression and decompression,based on google/snappy.The data frame format is frame_format
  • forward error correction
  • lower resource consumption

Build

Prerequisites

  1. asio
  2. cryptopp
  3. snappy

Unix-like system

  1. Get the latest code
$ git clone https://github.com/ccsexyz/kcptun-asio.git  
  1. Run build.sh
$ ./build.sh 
from https://github.com/ccsexyz/kcptun-asio
-------

kcp-go-raw

为了解决 ISP 或某猴米路由器对 UDP 可能的QOS问题,利用原始套接字实现了运行在伪装的 TCP 协议之上的 kcp-go

注意事项

服务端在使用前需要设置 iptables 来避免内核返回的 RST 报文断开客户端的连接

iptables -A OUTPUT -p tcp --sport <port> --tcp-flags RST RST -j DROP
from  https://github.com/zhanglei/kcp-go-raw

No comments:

Post a Comment