All Projects → longshengwang → tcpthrough-server

longshengwang / tcpthrough-server

Licence: other
该项目主要用来做 tcp 穿透内网

Programming Languages

java
68154 projects - #9 most used programming language
Dockerfile
14818 projects

Labels

Projects that are alternatives of or similar to tcpthrough-server

steady-tun
Secure TLS tunnel with pool of prepared upstream connections
Stars: ✭ 37 (-42.19%)
Mutual labels:  tcp-proxy
Goproxy
🔥 Proxy is a high performance HTTP(S) proxies, SOCKS5 proxies,WEBSOCKET, TCP, UDP proxy server implemented by golang. Now, it supports chain-style proxies,nat forwarding in different lan,TCP/UDP port forwarding, SSH forwarding.Proxy是golang实现的高性能http,https,websocket,tcp,socks5代理服务器,支持内网穿透,链式代理,通讯加密,智能HTTP,SOCKS5代理,黑白名单,限速,限流量,限连接数,跨平台,KCP支持,认证API。
Stars: ✭ 11,334 (+17609.38%)
Mutual labels:  tcp-proxy
Gobetween
☁️ Modern & minimalistic load balancer for the Сloud era
Stars: ✭ 1,631 (+2448.44%)
Mutual labels:  tcp-proxy
Toxiproxy
⏰ 🔥 A TCP proxy to simulate network and system conditions for chaos and resiliency testing
Stars: ✭ 7,529 (+11664.06%)
Mutual labels:  tcp-proxy
http-tunnel
HTTP(S) Tunnel and TCP Proxy
Stars: ✭ 70 (+9.38%)
Mutual labels:  tcp-proxy
FastTunnel
expose a local server to the internet. 高性能跨平台的内网穿透解决方案 远程内网计算机 域名访问内网站点 反向代理内网服务 端口转发 http代理
Stars: ✭ 815 (+1173.44%)
Mutual labels:  tcp-proxy
PortForwarder
A small program to forward TCP traffic with QoS options
Stars: ✭ 30 (-53.12%)
Mutual labels:  tcp-proxy
ptw
Pooling TLS Wrapper
Stars: ✭ 20 (-68.75%)
Mutual labels:  tcp-proxy

Tcp Through Server

1. 说明

该项目只是server端,还有client端,对应的地址是 https://github.com/longshengwang/tcpthrough-client

这两个项目的主要功能是可以从一个公网IP地址来访问很多内网下服务(NAT后面的网络),比如 sshscphttpvnc等 ( 只要是tcp协议就可以 )

2. 编译

2.1. gradle和java版本

$ gradle -v

------------------------------------------------------------
Gradle 4.6
------------------------------------------------------------

Build time:   2018-02-28 13:36:36 UTC
Revision:     8fa6ce7945b640e6168488e4417f9bb96e4ab46c

Groovy:       2.4.12
Ant:          Apache Ant(TM) version 1.9.9 compiled on February 2 2017
JVM:          1.8.0_121 (Oracle Corporation 25.121-b13)
OS:           Mac OS X 10.15 x86_64
 
$ java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)

2.2. 编译命令

gradle build

2.3. 运行

说明:采用了gradleapplication plugin,所以可以生成用命令方式运行的zip和tar(目录是在 build/distribution 下)。 选择其中一种压缩包,解压直接直接运行 bin目录下的可执行文件(其实是脚本,windows是bat文件,unix是另一个shell文件)

在解压后的目录下运行如下命令

bin/server
  • data server默认端口是 9009
  • manage server默认端口是 9000
  • http server默认端口是 8080

也可以指定端口,具体信息可以运行 bin/server -h

3. HTTP接口

注意:HTTP服务目前运行在127.0.0.1上,所以如果该服务部署在公网上,用公网IP地址是无法访问的。如果想用公网访问,可以用nginx、haproxy等反向代理,不过目前http没有做用户验证,需要注意。

3.1. 获取所有client的信息

  1. 访问接口GET http://localhost:8080/tcpth/list
  2. 返回信息
[
  {
    "proxy_port": "2242",         # 对外的代理端口
    "is_remote_manage": "true",   # client是否允许server端控制(下面的两个接口)
    "read_speed": "0KB/s",        # 读速度
    "name": "wls_home",           # client name(不可以重复)
    "out_connection_count": "0",  # 连接到 2242端口的连接数
    "local": "localhost:22",      # client的host,这个host也可以是client网络环境中的其他主机
    "write_speed": "0KB/s"        # 写速度
  }
]

3.2. 增加代理信息

  1. 访问接口
POST  http://localhost:8080/tcpth/register/add
{
	"name":"wls_home",
	"proxy_port" : "22112",
	"local_host": "localhost", # 这个host也可以是client网络环境中的其他主机
	"local_port": 223
}
  1. 返回信息 true -> 成功 false -> 失败

3.3. 删除代理信息

  1. 访问接口
POST  http://localhost:8080/tcpth/register/delete
{
	"name":"wls_home",
	"proxy_port":"22112"
}
  1. 返回信息 true -> 成功 false -> 失败

3.4. 安全模式下增加信任IP

  1. 访问接口
GET  http://localhost:8080/tcpth/auth/addtrustip/{client_name}/{ip_address}
  1. 返回信息 true -> 成功 false -> 失败

3.5. 安全模式下删除信任IP

  1. 访问接口
GET  http://localhost:8080/tcpth/auth/rmtrustip/{client_name}/{ip_address}
  1. 返回信息 true -> 成功 false -> 失败

4. 测试结果

在 2015款 macbook pro i7 16g 上用iperf3测试

 上行: 13Gb/s
 下行: 13Gb/s

后来加了流量统计以后的速度有所下降,基本也能保证在 10Gb/s 上下。

注:这里是小b哦。

5. 命令行操作HTTP Api

5.1. 安装

pip install tcpth.cmd

5.2. 使用

➜  tcp-console git:(master) ✗ tcpth_cmd
Welcome to use the tcp through.
  ______              ________                           __
 /_  __/________     /_  __/ /_  _________  __  ______ _/ /_
  / / / ___/ __ \     / / / __ \/ ___/ __ \/ / / / __ `/ __ \
 / / / /__/ /_/ /    / / / / / / /  / /_/ / /_/ / /_/ / / / /
/_/  \___/ .___/    /_/ /_/ /_/_/   \____/\__,_/\__, /_/ /_/
        /_/                                    /____/


tcpthrough> help
    list                                 -- get all registration
    get <name>                           -- get special name information
    register add <name> <localhost:port> <proxy port>    -- add registration
    register delete <name> <proxy port>                  -- delete registration
    trust add <name> [<proxy port>] <trusted ip>        -- add trust ip
    trust delete <name> [<proxy port>]  <trusted ip>     -- delete trust ip
    trust get <name> [<proxy port>]     -- get trust ip
tcpthrough>

6. 亮点功能

  1. 支持 http api 动态添加和删除代理信息(支持一个client可以代理多个内网端口)
  2. 支持安全模式。只有在信任列表的IP地址才可以访问client (防止攻击的最好方式)
  3. 支持速度限制,功能已经测试可用。只是目前在代码中没有限速,可自己修改代码,具体代码在server库中的OuterServer中,注释中有说明。
  4. client可设定不允许server控制 (client端的isRemoteManage参数)
  5. 支持查看实时速率(不需要用总量来计算)
  6. 管理通道进行了SSL加密,防止注册信息被抓包
  7. 数据平面和控制平面分离,提高性能。
  8. 管理平面和控制平面都进行了安全性校验,不正确的连接会被kill掉,拒绝攻击。
  9. Server可以增加密码校验,不允许其他的client注册。Server启动时候加上 -s 参数
  10. 后续可开发总量控制,traffic shaping counter中可以获取总量,所以想要进行总量控制,也是很easy的。

7. 可再完善的功能

7.1. 自己开发网页调用 http api 来显示代理信息

目前Server端的http server没有增加cookie和密码之类的校验,所以只允许运行在 localhost。 可以开发html 然后通过nginx反向代理来访问localhost http api。 安全性校验可以用base-auth。当然要记得开启 https(http的basic auth可是明文)

7.2. server增加用户登录管理,以及每个用户的登录页面。

这样就可以用管理员来设定每个用户的限额,每个用户也可以自己操作自己的client,比如增加代理和查看详情

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].