V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
AllenHua
V2EX  ›  程序员

PVE 的管理页面是自签证书 https 的,如何借助 frp 外网访问?

  •  
  •   AllenHua · 2022-06-15 21:03:01 +08:00 · 3902 次点击
    这是一个创建于 652 天前的主题,其中的信息可能已经有所发展或是发生改变。

    家里一台机器安装了 pve(proxmox virtual environment)。在内网通过 https://10.10.10.3:8006 访问

    20220615205133

    点击 Proceed 即可正常访问(忽略这个警告即可)

    VPS 上 frps 已部署好,内网 frpc 也已经配置好(内网配置如下)

    [pve-dashboard]
    type = http
    custom_domains = pve.example.com
    local_ip = 10.10.10.3
    local_port = 8006
    remote_port = 81
    use_compression = true
    use_encryption = true
    

    frpc 这边日志显示 proxy 建立成功

    [control.go:181] [0e57994403b3976e] [admin.pve-dashboard] start proxy success
    

    但是访问 https://pve.example.com 是 frp 的默认 404 页面(如下图)。

    我在 frp http 传输外层包了一层 nginx ,最外层套了 SSL 实现的 https 访问

    20220615205516

    有人知道这种情况下应该怎么做吗?

    内网中,curl -v http://10.10.10.3:8006 结果如下,

    * Empty reply from server
    * Connection #0 to host 10.10.10.3 left intact
    

    scheme 必须指定是 https 才行,curl -v https://10.10.10.3:8006

    *   Trying 10.10.10.3:8006...
    * Connected to 10.10.10.3 (10.10.10.3) port 8006 (#0)
    * ALPN, offering h2
    * ALPN, offering http/1.1
    * successfully set certificate verify locations:
    *  CAfile: /etc/ssl/certs/ca-certificates.crt
    *  CApath: /etc/ssl/certs
    * TLSv1.3 (OUT), TLS handshake, Client hello (1):
    * TLSv1.3 (IN), TLS handshake, Server hello (2):
    * TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
    * TLSv1.3 (IN), TLS handshake, Certificate (11):
    * TLSv1.3 (OUT), TLS alert, unknown CA (560):
    * SSL certificate problem: unable to get local issuer certificate
    * Closing connection 0
    curl: (60) SSL certificate problem: unable to get local issuer certificate
    More details here: https://curl.se/docs/sslcerts.html
    
    curl failed to verify the legitimacy of the server and therefore could not
    establish a secure connection to it. To learn more about this situation and
    how to fix it, please visit the web page mentioned above.
    

    这种自签证书的 web 服务可以通过 frp 暴露在公网吗,还请指教。

    19 条回复    2023-03-22 22:17:00 +08:00
    des
        1
    des  
       2022-06-15 21:08:12 +08:00 via iPhone
    为什么不行?最简单的方式 type 用 tcp 就行
    lcy630409
        2
    lcy630409  
       2022-06-15 21:11:12 +08:00
    自签证书和购买的证书的区别 也就是购买的证书的根证书内置到系统里去了,在证书方面来说 暴漏在公网没啥问题
    AllenHua
        3
    AllenHua  
    OP
       2022-06-15 21:17:14 +08:00
    @des 我也用了 type tcp ,但是没弄清楚两端应该分别怎么配置才能通过 https://pve.example.com 访问
    Kaiyuan
        4
    Kaiyuan  
       2022-06-15 21:19:16 +08:00   ❤️ 1
    AMCE 签一个

    ```
    acme.sh --installcert --issue --dns dns_cf -d *.ABC.COM -d ABC.COM --certpath /etc/pve/local/pveproxy-ssl.pem --keypath /etc/pve/local/pveproxy-ssl.key --capath /etc/pve/local/pveproxy-ssl.pem --reloadcmd "systemctl restart pveproxy"
    ```
    des
        5
    des  
       2022-06-15 21:22:21 +08:00 via iPhone
    @AllenHua
    type tcp 比 http 配置还要少啊?!根本不需要额外配置。
    服务端和客户端配置好了,直接用 https://ip:port 访问就行
    AllenHua
        6
    AllenHua  
    OP
       2022-06-15 21:36:57 +08:00 via iPhone
    @Kaiyuan #4 貌似不错,回头试试 谢谢
    AllenHua
        7
    AllenHua  
    OP
       2022-06-15 21:39:24 +08:00 via iPhone
    @des #5 tcp 配置项是更少,custom domain 都不需要,你说这种方式我再试试吧,如果可以实现 frps 那侧 nginx 也要配合写一条配置 (目前写的是 针对 http 服务的,proxy pass 到 81 端口,得改)
    documentzhangx66
        8
    documentzhangx66  
       2022-06-15 21:40:37 +08:00   ❤️ 2
    重要业务,包括这种后台、数据库端口等,是万万不能直接暴露给公网的。

    正确的做法是:

    1.建立一套 VPN ,想偷懒,就用 ZeroTier ,然后买个公有云装 moon 节点来避免高延迟与不稳定。

    2.VPN 用强密码。

    3.VPN 默认端口号改掉。

    4.VPN 端口被连接后,不主动发信息。OpenSSH 就有这个毛病,被连接后,会主动告知对面,自己是 OpenSSH ,仿佛在邀请别人来攻击。

    5. VPN 用强密码,至少 16 位随机数字 + 字符 + 字母大小写。

    6.对外用蜜罐伪装对外开放 RDP 、常用 VPN 、SSH 、Mysql 、MSSQL 等端口,哪个 IP 连接就封它娘的。

    7.留意 VPN 的 0day 漏洞,经常升级。
    documentzhangx66
        9
    documentzhangx66  
       2022-06-15 21:41:44 +08:00
    有了 VPN 后,所有访问都是内网访问了。

    所以最好提前规划号内网 IP 。

    另外 ZeroTier 免费版本只有 50 个免费 IP 节点。如果有超过 50 个设备,并且只打算白嫖,一定要规划好子网。
    AllenHua
        10
    AllenHua  
    OP
       2022-06-15 21:58:11 +08:00
    @documentzhangx66 #8
    @documentzhangx66 #9

    谢谢指导意见,非常不错。我是打算建立 VPN 了,OpenWrt 里好几个 VPN 程序,我可以尝试一下。
    LeeLou
        11
    LeeLou  
       2022-06-15 22:05:38 +08:00
    @documentzhangx66 #8 原来蜜罐还有这么个用法
    totoro625
        12
    totoro625  
       2022-06-15 22:22:07 +08:00   ❤️ 1
    用 http2https 插件把 https 转换成 http ,再用 nginx 套 ssl 即可

    当然,用 VPN 更好
    [pve-dashboard]
    type = http
    custom_domains = pve.example.com
    plugin = http2https
    plugin_local_addr = 10.10.10.3:8006
    plugin_host_header_rewrite = 10.10.10.3
    plugin_header_X-From-Where = frp
    AllenHua
        13
    AllenHua  
    OP
       2022-06-15 22:30:47 +08:00 via iPhone
    @totoro625 #12 从 frp 0.20.0 版本开始用,那时候好像还没插件,本帖最原始的诉求解决办法应该就是你这个,怪我一直没用过 frp 中的插件系统 🤣
    AllenHua
        14
    AllenHua  
    OP
       2022-06-15 22:37:28 +08:00
    @totoro625 #12 已经成功访问了,目前 frp 版本是 0.39.0 ,真不错。不过还是要学习一下 VPN ,再次感谢介绍这个插件。

    ```
    [pve-dashboard]
    type = http
    custom_domains = pve.example.com
    plugin = http2https
    plugin_local_addr = 10.10.10.3:8006
    plugin_host_header_rewrite = 10.10.10.3
    plugin_header_X-From-Where = frp
    use_compression = true
    use_encryption = true
    ```
    documentzhangx66
        15
    documentzhangx66  
       2022-06-15 23:11:06 +08:00
    @LeeLou 正经人,谁会去尝试连接别人的 ssh 、rdp 、mysql 等端口,这些基本上是黑客入侵的第一步,用软件对 IP 段进行扫描,对常用端口进行扫描,然后字典 + 弱密码 + 0day 攻击。所以用蜜罐就最合适了,谁连就封谁。
    360dust
        16
    360dust  
       2022-06-16 09:04:25 +08:00 via iPhone
    @des 怎么给 IP 套 https
    des
        17
    des  
       2022-06-16 10:05:52 +08:00 via iPhone
    @360dust 如果是 type tcp ,原有的服务是 https ,那转发出去的自然是 https
    不过还是像楼上建议一样用 vpn 访问

    另外你问的“怎么给 IP 套 https”这个问题有错误。
    不知道你是想问“怎么申请&设置 IP 证书”,还是“怎么配置通过 https 访问我的转发出来的服务”
    itnoob
        18
    itnoob  
       2022-12-30 01:06:12 +08:00
    然后应该就只剩逃了 nginx+ssl 以后的 web shell 需要再关注一下就好了。
    friendsa
        19
    friendsa  
       2023-03-22 22:17:00 +08:00
    @AllenHua 您好,nginx 那端应该如何配置方便给个示例嘛?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2678 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 15:45 · PVG 23:45 · LAX 08:45 · JFK 11:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.