2

一个 TCP/UDP 端口复用器,根据第一个包的内容用正则表达式来确定转发的目标

 11 months ago
source link: https://www.v2ex.com/t/943547
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

github: https://github.com/lidotcircle/portForwarder

应用协议复用器

应用协议复用器是一种工具,它允许您根据客户端发送的第一个数据包中的正则表达式模式匹配,将 TCP 或 UDP 流量转发到不同的地址。

可以从源代码构建此工具,或者从发布页面下载名为 portfd 的预编译二进制文件。

可以使用简单的命令行参数运行 portfd ,请使用以下语法:portfd <local-bind> <remote>。 在这种情况下,需要指定监听地址和远程地址。 对于更高级的用法,portfd 可以使用支持更复杂规则的配置文件启动。以下是一个使用 YAML 格式的配置文件示例:

forwarders:
  - local: 0.0.0.0:8808
    # 指定 'remoteMap' 或 'remote'
    remoteMap:
      - pattern: "[http:localhost]"
        remote: 192.168.44.43:5445
      - pattern: "[https:baidu.com]"
        remote: "39.156.66.10:443"
      - pattern: "[ssh]"
        remote: "192.168.44.43:22"
      - pattern: .*
        remote: 192.168.100.46:3389
    remote: <remote-address/127.0.0.1:2233>
    enable_tcp: true # 默认为 true
    enable_udp: true # 默认为 true
    conn_bufsize: 2MB
    max_connections: 10000 # 可选
    allow_nets: # 可选的白名单
      - 127.0.0.0/24

pattern字段支持四种格式,所有格式都将转换为正则表达式:

  • [http] 或 [http:domain_name]:仅将 HTTP 流量或与 domain_name 匹配的 HTTP 请求的主机名转发到指定的远程地址。
  • [https:domain_name]:匹配 HTTPS 流量中客户端 Hello 中的 SNI (服务器名称指示)。
  • [ssh]:仅将 SSH 流量转发。
  • 任意正则表达式:仅将与此正则表达式匹配的首个接收到的数据包的流量转发。

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK