QQ群:397745473
295_利用cloudflare免服务器打洞
场景描述 利用cloudflare安装一个服务到服务器上, 就能达到穿透内网任意服务的目的,确实十分方便。比FRP感觉更舒服。
小缺点: 需要绑卡才能用, 开始测试的时候总是连不上, 以为是配置不当,折腾很久发现原来是没有绑卡开通这个Zero Trust
服务
现在来记录一下使用Zero Trust
连接服务器中的一个Docker环境的ssh
准备工作
一个 cloudflare 账号 免费的, 没有就到下面网站注册一个
1 https://dash.cloudflare.com/
装上docker
1 curl -sSL https://get.daocloud.io/docker | sh;curl -L https://get.daocloud.io/docker/compose/releases/download/v2.3.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose;chmod +x /usr/local/bin/docker-compose
安装桌面系统 只需要把22端口映射到本地再用bitvise https://www.bitvise.com/ssh-client-download
穿透后连接rdp或者VNC
只需要连上了ssh就可以利用ssh转发任意端口到本地连接了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 docker run -itd 127.0.0.1:9922:22 --shm-size=2000m --restart always --name=vnc -e VNC_PASSWORD=yb67Yq6K5kBG387TDaz6 --device /dev/snd -e ALSADEV=hw:2,0 -v /dev/shm:/dev/shm dorowu/ubuntu-desktop-lxde-vnc docker exec -it vnc bash passwd root apt-get update;apt-get upgrade -y; apt-get install openssh-server xrdp -y; systemctl enable ssh.service;/etc/init.d/ssh restart; systemctl enable xrdp.service;/etc/init.d/xrdp restart sed -i 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config sed -i 's/#PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config sed -i 's/#PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config
火狐浏览器 这个直接用vnc连接就会跳出一个浏览器来的docker镜像
ssh 连接纯折腾, 可以忽略
1 2 3 4 5 6 7 8 9 10 - 火狐浏览器 https://hub.docker.com/r/jlesage/firefox mkdir -p /docker/appdata/firefox docker run -d --name=firefox --shm-size=2000m --restart always -p 127.0.0.1:9969:5800 -e VNC_PASSWORD=yb67Yq6K5kBG387TDaz6 -v /docker/appdata/firefox:/config:rw jlesage/firefox docker run -d --name=firefox --shm-size=2000m --restart always --device /dev/snd -p 127.0.0.1:9969:5800 -e VNC_PASSWORD=yb67Yq6K5kBG387TDaz6 -v /docker/appdata/firefox:/config:rw jlesage/firefox
折腾ssh连接
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 - 火狐浏览器 https://hub.docker.com/r/jlesage/firefox docker run -d --name=firefox --shm-size=2000m --restart always -p 127.0.0.1:8822:22 -e VNC_PASSWORD=yb67Yq6K5kBG387TDaz6 -v /docker/appdata/firefox:/config:rw jlesage/firefox docker exec -it firefox sh apk --no-cache update;apk --no-cache upgrade apk add --no-cache openssh openrc adduser -D -H -s /sbin/nologin sshd useradd admin && echo 'admin:newpassword' | chpasswd vi /etc/ssh/sshd_config sed -i 's/#PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config Port 22 PermitRootLogin yes PasswordAuthentication yes UsePAM yes UsePrivilegeSeparation yes mkdir -p /run/openrc/;touch /run/openrc/softlevel ssh-keygen -A rc-status rc-service sshd restart rc-update add sshd default
kasmweb 桌面系统 用户名: kasm_user
密码: admin
Docker Kali
1 docker run -d --name=desktop --restart always --shm-size=512m -p 127.0.0.1:8822:22 --user root -e VNC_PW=admin kasmweb/core-kali-rolling:1.12.0
Ubuntu 测试成功
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 docker run -d --name containerName -p 3389:3389 catyku/ubuntu-xrdp:22.04 createUser password rootYesNo docker run -d --name containerName -p 3389:3389 catyku/rockylinuxrdp createUser password rootYesNo docker run -d --name=desktop --restart always --shm-size=512m -p 127.0.0.1:8822:22 --user root catyku/ubuntu-xrdp:22.04 ubuntu ubuntu123 yes docker run -d --name=desktop --restart always --shm-size=512m -p 127.0.0.1:8822:22 --user root catyku/rockylinuxrdp createUser password rootYesNo docker exec -it desktop bash echo 'root:newpassword' | chpasswdapt-get update;apt-get upgrade -y; apt-get install openssh-server -y sed -i 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config sed -i 's/#PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config sed -i 's/#PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config /etc/init.d/ssh restart
Ubuntu Jammy
用户名: kasm_user
密码: password
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 docker run -d --name=desktop --restart always --shm-size=512m -p 127.0.0.1:8822:22 --user root -e VNC_PW=password kasmweb/ubuntu-jammy-desktop:1.12.0 docker exec -it desktop bash passwd root apt-get update;apt-get upgrade -y; apt-get install openssh-server xrdp -y; systemctl enable ssh.service;/etc/init.d/ssh restart; systemctl enable xrdp.service;/etc/init.d/xrdp restart sed -i 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config sed -i 's/#PermitRootLogin.*/PermitRootLogin yes/g' /etc/ssh/sshd_config sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config sed -i 's/#PasswordAuthentication.*/PasswordAuthentication yes/g' /etc/ssh/sshd_config /etc/init.d/ssh restart 6901 novnc端口
1 2 docker run -d --name=desktop --restart always --shm-size=512m -p 127.0.0.1:8822:22 --user root -e VNC_PW=password kasmweb/core-ubuntu-jammy:1.12.0-rolling
微桌面 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 docker run -d --name=desktop --restart always --shm-size=512m -p 127.0.0.1:9922:22 -p 127.0.0.1:9969:6901 -p 127.0.0.1:9933:3389 --user root -e VNC_PW=password soff/tiny-remote-desktop docker run -d --name=desktop --restart always --shm-size=512m --device /dev/snd -p 127.0.0.1:9922:22 -p 127.0.0.1:9969:6901 -p 127.0.0.1:9933:3389 -e RESOLUTION=1600x1200 -e VNC_PW=password soff/tiny-remote-desktop apt update && apt install alsa-base pulseaudio / logging configuration: LogFile: /var/log /xrdp.log LogLevel: 4 EnableSyslog: 1 SyslogLevel: 4 It looks like xrdp is already running. If not, delete /var/run/xrdp.pid and try again.
Centos
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 docker run -d --name=desktop --restart always --shm-size=512m -p 127.0.0.1:8822:22 --user root -e VNC_PW=password kasmweb/centos-7-desktop:1.12.0 docker exec -it desktop bash [root@b5926410fe60 /] [root@b5926410fe60 /] [root@b5926410fe60 /] [root@b5926410fe60 /] [root@b5926410fe60 /] [root@b5926410fe60 /] [root@b5926410fe60 /] [root@b5926410fe60 /] yum update -y;yum upgrade -y; yum install openssh-server -y; yum install xrdp -y; systemctl enable ssh.service;/etc/init.d/ssh restart; systemctl enable xrdp.service;/etc/init.d/xrdp restart
其他桌面 1 2 3 4 5 6 7 8 9 https://morioh.com/p/9240212eef7e Docker Ubuntu: Ubuntu with XRDP and MATE https://github.com/RattyDAVE/docker-ubuntu-xrdp-mate-custom https://www.modb.pro/db/410039
另一个完整案例 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 参考: https://twitter.com/wesbos/status/1634310926219333642 Nice free ngrok alternative. 1. brew install cloudflared 2. cloudflared tunnel --url http://localhost:6969 1. cloudflared tunnel login 2. cloudflared tunnel create local 3. cloudflared tunnel route dns local http://local.yourdomain.com 4. cloudflared tunnel run --url http://localhost:9999 local https://tunnelto.dev https://localtunnel.me --> https://theboroer.github.io/localtunnel-www/ https://github.com/antoniomika/sish docker run -p 888:80 -d leejoneshane/ezgo-vdi docker run -p 3389:3389 -d leejoneshane/ezgo-vdi curl -Lo /usr/bin/cloudflared https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 && chmod +x /usr/bin/cloudflared 下面这条命令参考: https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/tunnel-guide/local /local-management/ingress/ cloudflared tunnel --url tcp://localhost:3389 cloudflared tunnel --url rdp://127.0.0.1:3389 exe 下载地址: https://github.com/cloudflare/cloudflared/releases .\cloudflared-windows-amd64.exe access rdp --hostname https://chapel-kidney-finishing-integration.trycloudflare.com --url rdp://localhost:13389 --loglevel debug
安装Tunnels 1 2 3 4 5 6 7 8 curl -Lo /usr/bin/cloudflared https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 && chmod +x /usr/bin/cloudflared cloudflared login ** 登陆成功后就可以在网页上随意控制映身端口了 登陆:https://one.dash.cloudflare.com/ 选择: Access/Tunnels --> Create a tunnel 新建一个隧道后会有命令提示直接复制后执行就行了
Windows客户端本地执行 1 2 3 4 5 6 7 8 参考官方文档: https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/use_cases/ 下载: https://github.com/cloudflare/cloudflared/releases 参考: .\cloudflared-windows-amd64.exe access rdp --hostname rdp.2bkf.com --url rdp://localhost:13389 --loglevel debug .\cloudflared-windows-amd64.exe access ssh --hostname ssh.2bkf.com --url tcp://localhost:9922 --loglevel debug
参考资料 1 2 【超简易Cloudflare Tunnel搭配Docker使用指南】 https://www.bilibili.com/video/BV1XY411T7sT/?share_source=copy_web&vd_source=cce1b28f8472adea56ea0325aa0ea453
分享 免费能建docker的平台 1 2 https://gitpod.io/workspaces https://shell.cloud.google.com/
QQ群:397745473