Projects STRLCPY SeaMoon Commits f91855dd
🤬
  • ■ ■ ■ ■ ■
    Dockerfile
    skipped 11 lines
    12 12  LABEL maintainer="[email protected]"
    13 13  WORKDIR /app
    14 14  COPY --from=build /tmp/seamoon /app/seamoon
     15 +COPY ./entrypoint.sh /app/entrypoint.sh
     16 +RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories && \
     17 + apk add tor && \
     18 + echo -e "RunAsDaemon 1\n\nAssumeReachable 1\n\nLog notice file /var/log/tor/tor.log" > /etc/tor/torrc &&\
     19 + chmod +x /app/entrypoint.sh && chmod +x /app/seamoon
    15 20  EXPOSE 1080 8080 7777 9000
    16  -ENTRYPOINT ["/app/seamoon"]
     21 +ENTRYPOINT ["/app/entrypoint.sh"]
  • ■ ■ ■ ■ ■ ■
    README.md
    skipped 14 lines
    15 15   月海(Sea Moon) 是一款 FaaS/BaaS 实现的 Serverless 网络工具集,期望利用云原生的优势,实现更简单、更便宜的网络功能。
    16 16  </p>
    17 17  <p align="center">
    18  - 月海之名取自于苏轼的《西江月·顷在黄州》,寓意月海取自于传统工具,用之于云,最终达到隐匿于海的效果。
     18 + 月海之名取自于苏轼的《西江月·顷在黄州》,寓意月海取自于传统工具,用之于云,最终达到隐匿于海的效果。
    19 19  </p>
    20 20   
    21 21  ## ☁️ 什么是月海
    22 22   
    23 23  > 🌕 月出于云却隐于海
     24 + 
     25 +> 🔥 新增 seamoon 支持 tor 网络访问 onion 域名
    24 26   
    25 27  月海(Sea Moon) 是一款 FaaS/BaaS 实现的 Serverless 网络工具集,期望利用云原生的优势,实现更简单、更便宜的网络功能。
    26 28   
    27 29  月海之名取自于苏轼的《西江月·顷在黄州》,寓意月海取自于传统工具,用之于云,最终达到隐匿于海的效果。
    28 30   
    29  -月海基于 Serverless 的动态特性、分别从网络层、应用层实现对应的能力,并利用serverless-devs工具来实现快捷的部署/跨厂商操作。
     31 +月海基于 Serverless 的动态特性、分别从网络层、应用层实现对应的能力,并利用serverless-devs工具来实现快捷的部署/跨厂商操作。
    30 32   
    31 33  想要了解更多,请移步 [官方手册](https://seamoon.dvkunion.cn)
    32 34   
    33 35  觉得项目不错的话,[还请给一个star ✨](https://github.com/DVKunion/SeaMoon), 你的支持是更新的最大动力~
     36 + 
     37 +## 🔨 功能简要
     38 + 
     39 + 
     40 +**网络隧道**
     41 + 
     42 +| 隧道类型 | 技术文档 | 支持情况 |
     43 +|-----------|------|:------:|
     44 +| websockst | []() | ✅ |
     45 +| grpc | []() | ✅ |
     46 + 
     47 + 
     48 +**网络代理**
     49 + 
     50 +| 代理类型 | 技术文档 | Seamoon 客户端支持 | 其他客户端支持 |
     51 +|-------------|-----------------------------------------------------------|:-------------:|:-------:|
     52 +| HTTP(S) | [HTTP.md](https://seamoon.dvkunion.cn/tech/net/http/) | ✅ | ✅ |
     53 +| Socks5 | [Socks5.md](https://seamoon.dvkunion.cn/tech/net/socks5/) | ✅ | ✅ |
     54 +| Socks4 | []() | ❌ | ✅ |
     55 +| shadowsocks | []() | ❌ | ✅ |
     56 + 
     57 +**其他**
     58 + 
     59 ++ 🧅 Tor 网络 .onion 支持. [如何开启 Tor 代理](https://seamoon.dvkunion.cn/guide/client/tor/)
     60 ++ ......
    34 61   
    35 62  ## 🔥 使用展示
    36 63   
    skipped 29 lines
  • ■ ■ ■ ■ ■ ■
    cmd/client/config.go
    skipped 30 lines
    31 31  type controlConfig struct {
    32 32   ConfigAddr string `toml:"addr"`
    33 33   LogPath string `toml:"logPath"`
     34 + TorEnable bool `toml:"tor_enable"`
    34 35  }
    35 36   
    36 37  type proxyConfig struct {
    skipped 21 lines
    58 59   // is dangerous to open Control page for everyone, do not set value like: ":7777" / "0.0.0.0:7777"
    59 60   ConfigAddr: ":7777",
    60 61   LogPath: "web.log",
     62 + TorEnable: false,
    61 63   },
    62 64   Http: proxyConfig{
    63 65   false, ":9000", "inactive",
    skipped 46 lines
  • ■ ■ ■ ■
    cmd/client/control.go
    skipped 77 lines
    78 78   slog.Error(consts.ACCEPT_ERROR, "err", err)
    79 79   }
    80 80   if srv, ok := service.Factory.Load(pt); ok {
    81  - destConn, err := srv.(service.Service).Conn(ctx, t, service.WithAddr(pa))
     81 + destConn, err := srv.(service.Service).Conn(ctx, t, service.WithAddr(pa), service.WithTorFlag(Config().Control.TorEnable))
    82 82   if err != nil {
    83 83   slog.Error(consts.CONNECT_RMOET_ERROR, "err", err)
    84 84   continue
    skipped 10 lines
  • ■ ■ ■ ■ ■
    cmd/client/static/public/js/index.js
    skipped 37 lines
    38 38   Control: {
    39 39   ConfigAddr: $("#controlAddr").val(),
    40 40   LogPath: $("#controlLog").val(),
     41 + TorEnable: $(".tor.ui.toggle.checkbox").hasClass("checked"),
    41 42   },
    42 43   Http: {
    43 44   Enabled: $(".http.ui.toggle.checkbox").hasClass("checked"),
    skipped 26 lines
    70 71   console.log(config.Control.ConfigAddr)
    71 72   $('#controlAddr').attr("value", config.Control.ConfigAddr)
    72 73   $('#controlLog').attr("value", config.Control.LogPath)
     74 + if (config.Control.TorEnable) {
     75 + $('.tor.ui.toggle.checkbox').addClass("checked")
     76 + $("#torEnable").attr("checked", "checked")
     77 + }
    73 78   if (config.Http.Enabled) {
    74 79   $('.http.ui.toggle.checkbox').addClass("checked")
    75 80   $(".http.two.fields").attr("style", "display: block;")
    skipped 26 lines
  • ■ ■ ■ ■ ■ ■
    cmd/client/static/templates/index.html
    skipped 31 lines
    32 32   <div class="content center">
    33 33   <p>SeaMoon - 月海</p>
    34 34   <p align="center">
    35  - <img src="https://goreportcard.com/badge/github.com/DVKunion/SeaMoon" />
    36  - <img src="https://img.shields.io/github/stars/DVKunion/SeaMoon.svg" alt="stars"/>
    37  - <img src="https://img.shields.io/github/downloads/dvkunion/seamoon/total?color=orange" alt="downloads" />
    38  - <img src="https://img.shields.io/github/languages/top/DVKunion/SeaMoon.svg?&color=blueviolet" alt="languages">
    39  - <img src="https://img.shields.io/badge/LICENSE-MIT-777777.svg" alt="license"/>
     35 + <img src="https://goreportcard.com/badge/github.com/DVKunion/SeaMoon"/>
     36 + <img src="https://img.shields.io/github/stars/DVKunion/SeaMoon.svg" alt="stars"/>
     37 + <img src="https://img.shields.io/github/downloads/dvkunion/seamoon/total?color=orange"
     38 + alt="downloads"/>
     39 + <img src="https://img.shields.io/github/languages/top/DVKunion/SeaMoon.svg?&color=blueviolet"
     40 + alt="languages">
     41 + <img src="https://img.shields.io/badge/LICENSE-MIT-777777.svg" alt="license"/>
    40 42   <a href='https://github.com/DVKunion/SeaMoon'><img
    41  - src="https://img.shields.io/github/watchers/dvkunion/seamoon?style=social"/></a>
     43 + src="https://img.shields.io/github/watchers/dvkunion/seamoon?style=social"/></a>
    42 44   </p>
    43 45   <div class="sub header">
    44 46   🌕 月出于云却隐于海
    skipped 39 lines
    84 86   <input id="controlLog" placeholder="日志路径" type="text">
    85 87   </div>
    86 88   </div>
     89 + <br />
     90 + <div class="field">
     91 + <div class="tor ui toggle checkbox">
     92 + <input id="torEnable" type="checkbox" tabindex="0" class="hidden">
     93 + <label>开启 tor 网络(仅支持 socks5 代理 + websocket 隧道)</label>
     94 + </div>
     95 + </div>
    87 96   <h4 class="ui inverted dividing header"><i class="cloud icon"></i>云端配置</h4>
    88 97   <div class="fifteen wide field">
    89 98   <label>代理地址: </label>
    skipped 28 lines
    118 127   <input id="socksAddr" placeholder="socks代理地址" type="text">
    119 128   </div>
    120 129   </div>
    121  - <h4 class="ui dividing inverted header"><i class="ellipsis horizontal icon"></i>高级功能</h4>
    122  -{{/* <div class="inline field">*/}}
    123  -{{/* <div class="ui checkbox">*/}}
    124  -{{/* <input type="checkbox" tabindex="0" class="hidden">*/}}
    125  -{{/* <label>开启webshell动态代理功能(待实现)</label>*/}}
    126  -{{/* </div>*/}}
    127  -{{/* </div>*/}}
    128  - <!-- <div class="inline field">-->
    129  - <!-- <div class="ui checkbox">-->
    130  - <!-- <input type="checkbox" tabindex="0" class="hidden">-->
    131  - <!-- <label>其他一些乱七八糟的功能,占个位置</label>-->
    132  - <!-- </div>-->
    133  - <!-- </div>-->
     130 +{{/* <h4 class="ui dividing inverted header"><i class="ellipsis horizontal icon"></i>高级功能</h4>*/}}
     131 + 
    134 132   </form>
    135 133   </div>
    136 134   <div class="actions">
    skipped 22 lines
    159 157  <script src="/static/public/js/index.js"></script>
    160 158  <script>
    161 159   const config = {{ . }}
    162  - setValue(config);
     160 + setValue(config);
    163 161  </script>
    164 162  </html>
  • ■ ■ ■ ■ ■ ■
    docs/README.md
    skipped 8 lines
    9 9  postList: none
    10 10  features:
    11 11  - title: 🫥 隐匿
    12  - details: 基于 FaaS/BaaS 实现动态IP代理,云上无痕。
     12 + details: 基于 FaaS/BaaS 实现动态IP代理,Tor云上无痕。
    13 13  - title: 🗃️ 集成
    14  - details: 适配大量云服务商知名客户端,拒绝服务绑架。
     14 + details: 适配大量云服务商知名客户端,拒绝服务绑架。
    15 15  - title: 🚀 便携
    16  - details: 以 Serverless Devs为基础,实现跨平台快速部署。
     16 + details: 以 Serverless Devs 为基础,实现跨平台快速部署。
    17 17  ---
  • ■ ■ ■ ■ ■ ■
    docs/guide/00.概述/00.introduce.md
    skipped 21 lines
    22 22   
    23 23  月海之名取自于苏轼的《西江月·顷在黄州》,寓意月海取自于传统工具,用之于云,最终达到隐匿于海的效果。
    24 24   
    25  -月海基于 Serverless 的动态特性、分别从网络层、应用层实现对应的能力,并利用serverless-devs工具来实现快捷的部署/跨厂商操作。
     25 +月海基于 Serverless 的动态特性、分别从网络层、应用层实现对应的能力,并利用serverless-devs工具来实现快捷的部署/跨厂商操作。
    26 26   
    27 27  觉得项目不错的话,[还请给一个star ✨](https://github.com/DVKunion/SeaMoon), 你的支持是更新的最大动力~
    28 28   
    skipped 4 lines
    33 33  网络层支持是月海的基础功能,也是云函数最基本的优势和特性。
    34 34   
    35 35  利用云函数的动态实例不同的出口IP,从而获取到了干净(非威胁情报黑名单)、随机的外网IP代理来进行测试。
     36 + 
     37 +同时月海集成了 Tor 网桥,实现了服务端 Tor 网络的访问。
    36 38   
    37 39  目前网络层功能支持如下:
    38 40   
    skipped 14 lines
    53 55  | Socks4 | []() | ❌ | ✅ |
    54 56  | shadowsocks | []() | ❌ | ✅ |
    55 57   
    56  -****
     58 +****
    57 59   
    58  -**NAT穿透**
     60 ++ 🧅 Tor 网络 .onion 支持. [如何开启 Tor 代理](https://seamoon.dvkunion.cn/guide/client/tor/)
     61 ++ ......
    59 62   
    60 63  更多特性相关请移步: [技术文档](https://seamoon.dvkunion.cn/tech/feature/)
    61 64   
    skipped 33 lines
  • ■ ■ ■ ■ ■ ■
    docs/guide/03.客户端部署/03.gost.md
    skipped 63 lines
    64 64  # 通过 gost 启动一个其他协议代理,这里以 socks4 代理为例,利用 websocket 转发,并指定转发的流量 以 socks5 形式。
    65 65  gost -L socks4://:1080 -F socks5+wss://<seamoon-server>:<seamoon-port>?path=/socks5
    66 66  ```
    67  - 
    68 67  </code-block>
    69 68   
    70 69  <code-block title="gost-shadowsocks + seamoon-websocket(socks5)">
    71 70   
    72 71  ```shell
    73 72  # 通过 gost 启动一个其他协议代理,这里以 shadowsocks 代理为例,利用 websocket 转发,并指定转发的流量 以 socks5 形式。
    74  -gost -L ss://:1080 -F socks5+wss://<seamoon-server>:<seamoon-port>?path=/socks5
     73 +gost -L ss://<cipher>:<pass>@:1080 -F socks5+wss://<seamoon-server>:<seamoon-port>?path=/socks5
     74 +# 如:ss://AEAD_AES_128_GCM:password@:1080
    75 75  ```
    76 76   
    77 77  </code-block>
    skipped 8 lines
  • ■ ■ ■ ■ ■ ■
    docs/guide/03.客户端部署/04.tor.md
     1 +---
     2 +title: Tor
     3 +date: 2022-09-29 23:45:03
     4 +permalink: /guide/client/tor
     5 +article: false
     6 +---
     7 + 
     8 +## 🧅 Tor 网络开启
     9 + 
     10 +::: warning 注意
     11 +tor 服务比较吃内存,经测试 内存至少需要配置在 100MB 以上才能发挥稳定的效果。
     12 +:::
     13 + 
     14 +为了防止普通流量过 Tor 导致的速率下降,在客户端做了个开关。
     15 + 
     16 +客户端会根据这个这个开关来选择是否给服务端发送 Tor 代理标识。
     17 + 
     18 +服务端接收到 Tor 代理标识后,会将流量直接转发给本地服务。
     19 + 
     20 +![tor](https://seamoon.oss-cn-hangzhou.aliyuncs.com/ec26347f298a4f9d81f7068eb3c0e4dc.png)
     21 + 
     22 +注意,tor 网络目前仅支持: 本地 socks5 代理 + websocket 隧道 的模式。
     23 + 
     24 +然后本地的 socks5 代理即可访问一些 .onion 结尾的域名了。如:
     25 + 
     26 +`https://duckduckgogg42xjoc72x3sjasowoarfbgcmvfimaftt6twagswzczad.onion/`
     27 + 
     28 + 
     29 +![onion](https://seamoon.oss-cn-hangzhou.aliyuncs.com/09626bede56b4c18b6cd4d41d3e11c00.png)
     30 + 
     31 + 
     32 +::: tips
     33 +在当前版本内,seamoon 实现了最简单的 tor 接入方式 -- 通过 tor cli 自带的 s5 协议做了一层转发,因为 v2ray 也是这样玩的。
     34 + 
     35 +实际上,这种方案,有很多不足,出去开头的资源占用较高 warning,通过 binary 的集成力度也不是非常合适,但是在这个阶段暂时用该方案来减少代码开发的工作量。
     36 + 
     37 +因此,此方案仅用于证明 seamoon 的扩展性,距离真正 "便宜" 可能还需要一段的距离。
     38 +:::
  • ■ ■ ■ ■ ■ ■
    docs/guide/03.客户端部署/README.md
    skipped 11 lines
    12 12  + [docker](https://seamoon.dvkunion.cn/guide/client/docker/)
    13 13  + [binary](https://seamoon.dvkunion.cn/guide/deploy/binary/)
    14 14   
     15 +Seamoon 客户端还支持了 Tor 网桥的接入
     16 + 
     17 ++ [tor](https://seamoon.dvkunion.cn/guide/client/tor/)
     18 + 
    15 19  除此之外,你还可以选择其他客户端,seamoon做了部分的协议适配支持,这样可以选择仅部署服务端,然后使用已有的成品客户端。
    16 20   
    17 21  成品客户端通常会支持更多协议类型,比如 gost,基本上所有可以监听的类型都可以通过 seamoon 隧道协议转发出来。
    18 22   
    19 23  + [gost:优雅简便的go代理](https://seamoon.dvkunion.cn/guide/client/gost/)
     24 + 
     25 +[//]: # (+ [v2ray: 时代战神]&#40;https://seamoon.dvkunion.cn/guide/client/v2ray/&#41;)
  • ■ ■ ■ ■ ■ ■
    docs/tech/01.网络/03.TOR.md
     1 +---
     2 +title: TOR
     3 +date: 2024-01-29 11:05:23
     4 +permalink: /tech/net/tor/
     5 +article: false
     6 +---
     7 +# TOR
     8 + 
     9 + 
  • ■ ■ ■ ■ ■ ■
    entrypoint.sh
     1 +#!/bin/sh
     2 + 
     3 +if [ "$TOR" = "true" ]; then
     4 + tor
     5 +fi
     6 + 
     7 +/app/seamoon "$@"
  • ■ ■ ■ ■ ■ ■
    pkg/service/options.go
    skipped 7 lines
    8 8  type Options struct {
    9 9   addr string
    10 10   
     11 + tor bool
    11 12   tlsConf *tls.Config
    12 13   keepalive *KeepAliveOpt
    13 14   buffers *BufferOpt
    skipped 20 lines
    34 35  func WithAddr(addr string) Option {
    35 36   return func(o *Options) {
    36 37   o.addr = addr
     38 + }
     39 +}
     40 + 
     41 +func WithTorFlag(tor bool) Option {
     42 + return func(o *Options) {
     43 + o.tor = tor
    37 44   }
    38 45  }
    39 46   
    skipped 18 lines
  • ■ ■ ■ ■ ■
    pkg/service/websocket.go
    skipped 49 lines
    50 50   wsDialer.EnableCompression = srvOpts.buffers.EnableCompression
    51 51   }
    52 52   
    53  - wsConn, _, err := wsDialer.Dial(t.Path(srvOpts.addr), nil)
     53 + var requestHeader = http.Header{}
     54 + 
     55 + if srvOpts.tor {
     56 + requestHeader.Add("SM-ONION", "enable")
     57 + }
     58 + 
     59 + wsConn, _, err := wsDialer.Dial(t.Path(srvOpts.addr), requestHeader)
    54 60   
    55 61   if err != nil {
    56 62   return nil, err
    skipped 58 lines
    115 121  }
    116 122   
    117 123  func (s *WSService) socks5(w http.ResponseWriter, r *http.Request) {
     124 + onion := r.Header.Get("SM-ONION")
    118 125   // means use socks5 to connector
    119 126   conn, err := s.upGrader.Upgrade(w, r, nil)
    120 127   if err != nil {
    skipped 1 lines
    122 129   }
    123 130   t := tunnel.WsWrapConn(conn)
    124 131   go func() {
    125  - if err := transfer.Socks5Transport(t); err != nil {
    126  - slog.Error("connection error", "msg", err)
     132 + // 检测是否存在 onion 标识,代表着是否要开启 tor 转发
     133 + if onion != "" {
     134 + if err := transfer.TorTransport(t); err != nil {
     135 + slog.Error("connection error", "msg", err)
     136 + }
     137 + } else {
     138 + if err := transfer.Socks5Transport(t); err != nil {
     139 + slog.Error("connection error", "msg", err)
     140 + }
    127 141   }
    128 142   }()
    129 143  }
    skipped 11 lines
  • ■ ■ ■ ■ ■ ■
    pkg/transfer/tor.go
     1 +package transfer
     2 + 
     3 +import (
     4 + "log/slog"
     5 + "net"
     6 + "time"
     7 + 
     8 + "github.com/DVKunion/SeaMoon/pkg/consts"
     9 + "github.com/DVKunion/SeaMoon/pkg/network"
     10 +)
     11 + 
     12 +const defaultTorAddr = "127.0.0.1:9050"
     13 + 
     14 +func TorTransport(conn net.Conn) error {
     15 + // tor 转发非常简单,但是要求入口流量必须是一个 s5,然后直接把 s5 的口子转发给 tor 服务即可。
     16 + dialer := net.Dialer{Timeout: 10 * time.Second}
     17 + destConn, err := dialer.Dial("tcp", defaultTorAddr)
     18 + 
     19 + if err != nil {
     20 + return err
     21 + }
     22 + 
     23 + defer destConn.Close()
     24 + 
     25 + slog.Info(consts.SOCKS5_CONNECT_ESTAB, "src", conn.RemoteAddr(), "dest", defaultTorAddr)
     26 + 
     27 + if err := network.Transport(conn, destConn); err != nil {
     28 + slog.Error(consts.CONNECT_TRANS_ERROR, "err", err)
     29 + }
     30 + 
     31 + slog.Info(consts.SOCKS5_CONNECT_DIS, "src", conn.RemoteAddr(), "dest", defaultTorAddr)
     32 + 
     33 + return nil
     34 +}
     35 + 
Please wait...
Page is in error, reload to recover