ssh后门反向代理实现内网穿透

如图所示,内网主机ginger 无公网IP地址,防火墙只允许ginger连接blackbox.example.com主机

假如你是ginger的管理员root,你想要用tech主机连接ginger主机时,你想用其他机器连接ginger怎么办?在防火墙上砸个洞!

SSH使用 -R 标记通过 SSH 从 ginger 连接到 blackbox.example.com。使用 -R 标记将 blackbox 上端口 6699 的说明转发到 ginger 的端口 22(ssh端口) 上。这就设置了 SSH 通道。注意,只有 SSH 通信可以进入 ginger:您不会将 ginger 放在无保护的 Internet 上。

操作如下:

环境说明:

133.236.66.66   阿里云服务器  图中(blackbox.example.com主机)
192.168.233.10  内网机器     图中(ginger主机)
192.168.5.153   其他机器     图中(tech主机)

配置阿里云服务器

[root@Check2 ~]# vim /etc/ssh/sshd_config


GatewayPorts yes


[root@Check2 ~]# /etc/init.d/sshd restart
停止 sshd: [确定]
正在启动 sshd: [确定]

内网机器连接到阿里云开启反向代理端口,输入阿里云密码(阿里云的ssh端口为:42066默认为22。开启的反向监听端口为6699)

[root@wcy ~]# ssh -CqTfnN -R 6699:192.168.233.10:22 root@133.236.66.66 -p 42066
root@60.195.250.166's password: 
[root@wcy ~]#

阿里云上面看监听的端口

[root@Check2 ~]# netstat -anpt | grep 6699
tcp 0 0 0.0.0.0:6699 0.0.0.0:* LISTEN 422/sshd 
tcp 0 0 :::6699 :::* LISTEN 422/sshd 
[root@Check2 ~]#

通过其他机器(tech主机)连接阿里云的6699端口

[root@s153 ~]# ssh -p 6699 root@133.236.66.66
The authenticity of host '[133.236.66.66]:6699 ([133.236.66.66]:6699)' can't be established.
RSA key fingerprint is SHA256:5YOqHn741zWnU73B1R4zoQ1iTDWE7UnqYbUorSaKvV0.
RSA key fingerprint is MD5:9f:96:4a:dc:02:6d:fa:b0:02:fd:66:35:6c:fd:f7:63.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[133.236.66.66]:6699' (RSA) to the list of known hosts.
root@133.236.66.66's password: 
Last login: Tue Jul 31 23:03:52 2018 from 192.168.233.1
[root@wcy ~]# ip a | grep 192
inet 192.168.233.10/24 brd 192.168.233.255 scope global eth0
[root@wcy ~]#

验证查看,通过阿里云的6699端口成功连接到ginger主机

原文地址:https://www.cnblogs.com/chuyiwang/p/9396594.html