V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
taolinxs
V2EX  ›  Linux

有没有懂 SSLH 的大佬,想实现 CentOS 下 http 和 ssh 共用 80 端口

  •  
  •   taolinxs · 2023-02-07 16:35:55 +08:00 · 4432 次点击
    这是一个创建于 415 天前的主题,其中的信息可能已经有所发展或是发生改变。

    试了网上好多 sslh 的文章无解,官方英文文档读不懂,有没有配置过的大佬?求指点指点

    18 条回复    2023-02-08 18:48:25 +08:00
    taolinxs
        1
    taolinxs  
    OP
       2023-02-07 16:37:58 +08:00
    因为出口防火墙只开了 80 端口,外网无法 ssh 连接。
    defunct9
        2
    defunct9  
       2023-02-07 16:38:59 +08:00   ❤️ 3
    开 ssh ,让我上去试试
    defunct9
        3
    defunct9  
       2023-02-07 16:40:32 +08:00
    sudo apt install sslh

    vi /etc/default/sslh

    找到
    Run=no
    改成
    Run=yes

    然后到下面,按需配置
    DAEMON_OPTS="--user sslh --listen 0.0.0.0:22 --ssh 127.0.0.1:2222 --ssl 127.0.0.1:80 --openvpn 127.0.0.1:1194 --pidfile /var/run/sslh/sslh.pid --timeout 5"
    taolinxs
        4
    taolinxs  
    OP
       2023-02-07 16:43:22 +08:00
    @defunct9 这一看就是网上复制过来的,现在的 sslh 配置文件不长这样了。
    Judoon
        5
    Judoon  
       2023-02-07 16:59:59 +08:00
    http 当然不行,https 和 ssh 才行啊
    sssssks
        6
    sssssks  
       2023-02-07 17:04:01 +08:00
    直接上 nginx 做基于 stream 的四层反代,通过不同域名去复用端口
    cheng6563
        7
    cheng6563  
       2023-02-07 17:54:12 +08:00
    SSLH 是 ssl 和 ssh 分流啊,你得用 https 才行。

    直接用 go 撸一个反代吧
    sujin190
        8
    sujin190  
       2023-02-07 18:42:26 +08:00   ❤️ 3
    geligaoli
        9
    geligaoli  
       2023-02-07 22:12:42 +08:00
    我以前做过的一个 nginx 配置,如下:

    stream {

    map $ssl_preread_server_name $upstream {
    www.somedomain.cn nginx;
    web.somedomain.cn nginx;
    ovn.somedomain.cn openvpn;
    sks.somedomain.cn socks5;
    default ssh;
    }

    server {
    listen 10.10.10.10:443;
    resolver 8.8.8.8;
    proxy_pass $upstream;
    ssl_preread on;
    }

    upstream ssh {
    server 127.0.0.1:22;
    }

    upstream openvpn {
    server 127.0.0.1:1194;
    }

    upstream nginx {
    server 127.0.0.1:443;
    }

    upstream socks5 {
    server 127.0.0.1:1081;
    }

    }

    根据 nginx 的 ssl_preread 读到的域名信息来区分不同的目的地。正常的访问转到 nginx ,对于 ssh 访问因为没有域名信息所以等几秒后会转到 ssh 上。

    对于 openvpn 和 sockets5 ,需要客户端启动一个 stunnel 软件,该软件采用 https 方式连接上来,打通一个隧道供 openvn 和 sockets 客户端使用。
    imdong
        10
    imdong  
       2023-02-07 22:18:58 +08:00 via iPhone
    综合楼上所说,你把 https 跑在 80 端口上,就可以继续配置了。
    LindsayZhou
        11
    LindsayZhou  
       2023-02-07 22:58:27 +08:00   ❤️ 2
    要是有人帮忙去看一眼 github 仓库马上就解决了,有点无力吐槽。


    配置: https://pb.koi.moe/9P

    基于 Arch Linux 提供的默认配置( https://pb.koi.moe/9Q )改的
    datocp
        12
    datocp  
       2023-02-08 00:37:42 +08:00 via Android
    这个东西已经被我放弃了,之前用于 tls 跑在 tcp80 。但是在某个版本以后,之前的参数就无法使用。导致一直停留在那版本。
    后来因为多了反向连接需要获得客户端 ip 的功能,用了更牛逼的 haproxy,同样能实现端口复用功能。
    snoopygao
        13
    snoopygao  
       2023-02-08 08:46:58 +08:00
    nginx 和 haproxy 都能实现
    snoopygao
        14
    snoopygao  
       2023-02-08 08:48:28 +08:00
    frontend main
    mode tcp
    bind *:12482
    # acl 规则
    tcp-request inspect-delay 3s
    acl is_ssh req.payload(0,3) -m bin 535348
    acl is_http req.proto_http
    acl is_ssl req.ssl_hello_type 1
    # 设置四层允许通过
    tcp-request content accept if is_ssh
    tcp-request content accept if is_http
    tcp-request content accept if is_ssl
    tcp-request content reject
    # 分发到对应的 backend
    use_backend ssh if is_ssh
    use_backend http if is_http
    use_backend https if is_ssl
    backend http
    mode tcp
    server http 127.0.0.1:80
    backend https
    mode tcp
    server https 127.0.0.1:443
    backend ssh
    mode tcp
    server ssh 127.0.0.1:22
    snoopygao
        15
    snoopygao  
       2023-02-08 08:50:56 +08:00   ❤️ 2
    再提一点,我是搞运维的,自己的机器可以这么玩儿,如果是公司的东西,还是让运维人员开 vpn 比较正规,这么复用明显是违反安全原则了
    julyclyde
        16
    julyclyde  
       2023-02-08 10:31:40 +08:00
    ssh 是主动服务
    http/https 是被服务
    不能共用的
    jiulang
        17
    jiulang  
       2023-02-08 11:43:01 +08:00
    两种情况:
    1 、假设流量都是加密传输的 tls ,可以上 nginx 用 sni 里面的域名来分开流量类型;
    2 、假设流量是 http 和 ssh ,那要自己写 tcp 转发器,根据连接的数据来分析连接是 http 还是 ssh
    wonderblank
        18
    wonderblank  
       2023-02-08 18:48:25 +08:00
    haproxy
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2957 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 00:32 · PVG 08:32 · LAX 17:32 · JFK 20:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.